当前位置: 首页>>代码示例>>Python>>正文


Python configargparse.ArgumentParser方法代码示例

本文整理汇总了Python中configargparse.ArgumentParser方法的典型用法代码示例。如果您正苦于以下问题:Python configargparse.ArgumentParser方法的具体用法?Python configargparse.ArgumentParser怎么用?Python configargparse.ArgumentParser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在configargparse的用法示例。


在下文中一共展示了configargparse.ArgumentParser方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: build_translator

# 需要导入模块: import configargparse [as 别名]
# 或者: from configargparse import ArgumentParser [as 别名]
def build_translator(opt, report_score=True, logger=None, out_file=None):
    if out_file is None:
        out_file = codecs.open(opt.output, 'w+', 'utf-8')

    dummy_parser = configargparse.ArgumentParser(description='train.py')
    opts.model_opts(dummy_parser)
    dummy_opt = dummy_parser.parse_known_args([])[0]

    load_test_model = onmt.decoders.ensemble.load_test_model \
        if len(opt.models) > 1 else onmt.model_builder.load_test_model
    fields, model, model_opt = load_test_model(opt, dummy_opt.__dict__)

    scorer = onmt.translate.GNMTGlobalScorer(opt)

    translator = Translator(
        model,
        fields,
        opt,
        model_opt,
        global_scorer=scorer,
        out_file=out_file,
        report_score=report_score,
        logger=logger
    )
    return translator 
开发者ID:lizekang,项目名称:ITDD,代码行数:27,代码来源:translator.py

示例2: parse_args

# 需要导入模块: import configargparse [as 别名]
# 或者: from configargparse import ArgumentParser [as 别名]
def parse_args():
    parser = configargparse.ArgumentParser(
        description='preprocess.py',
        config_file_parser_class=configargparse.YAMLConfigFileParser,
        formatter_class=configargparse.ArgumentDefaultsHelpFormatter)

    opts.config_opts(parser)
    opts.add_md_help_argument(parser)
    opts.preprocess_opts(parser)

    opt = parser.parse_args()
    torch.manual_seed(opt.seed)

    check_existing_pt_files(opt)

    return opt 
开发者ID:lizekang,项目名称:ITDD,代码行数:18,代码来源:preprocess.py

示例3: _load_args

# 需要导入模块: import configargparse [as 别名]
# 或者: from configargparse import ArgumentParser [as 别名]
def _load_args(self, sysargs, use_files):
        shared_config_files = AutopushMultiService.shared_config_files
        if use_files:
            config_files = shared_config_files + (  # pragma: nocover
                '/etc/autopush_endpoint.ini',
                '~/.autopush_endpoint.ini',
                '.autopush_endpoint.ini'
            )
        else:
            config_files = []  # pragma: nocover

        parser = configargparse.ArgumentParser(
            description='Runs endpoint diagnostics.',
            default_config_files=config_files)
        parser.add_argument('endpoint', help="Endpoint to parse")

        add_shared_args(parser)
        return parser.parse_args(sysargs) 
开发者ID:mozilla-services,项目名称:autopush,代码行数:20,代码来源:diagnostic_cli.py

示例4: get_arg_parser_with_db

# 需要导入模块: import configargparse [as 别名]
# 或者: from configargparse import ArgumentParser [as 别名]
def get_arg_parser_with_db(description):
    """
    Returns an ArgumentParser pre-initalized with common arguments for configuring logging and the main
    database connection. It also supports reading arguments from environment variables.
    """

    parser = configargparse.ArgumentParser(description=description, auto_env_var_prefix='ctf_')

    parser.add_argument('--loglevel', default='WARNING', type=str,
                        choices=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'], help='Log level')

    db_group = parser.add_argument_group('database', 'Gameserver database')
    db_group.add_argument('--dbhost', type=str, help='Hostname of the database. If unspecified, the '
                          'default Unix socket will be used.')
    db_group.add_argument('--dbname', type=str, required=True, help='Name of the used database')
    db_group.add_argument('--dbuser', type=str, required=True, help='User name for database access')
    db_group.add_argument('--dbpassword', type=str, help='Password for database access if needed')

    return parser 
开发者ID:fausecteam,项目名称:ctf-gameserver,代码行数:21,代码来源:args.py

示例5: parse_opt

# 需要导入模块: import configargparse [as 别名]
# 或者: from configargparse import ArgumentParser [as 别名]
def parse_opt(self, opt):
        """Parse the option set passed by the user using `onmt.opts`
           Args:
               opt: (dict) options passed by the user

           Returns:
               opt: (Namespace) full set of options for the Translator
        """
        prec_argv = sys.argv
        sys.argv = sys.argv[:1]
        parser = configargparse.ArgumentParser()
        onmt.opts.translate_opts(parser)

        models = opt['models']
        if not isinstance(models, (list, tuple)):
            models = [models]
        opt['models'] = [os.path.join(self.model_root, model)
                         for model in models]
        opt['src'] = "dummy_src"

        for (k, v) in opt.items():
            if k == 'models':
                sys.argv += ['-model']
                sys.argv += [str(model) for model in v]
            elif type(v) == bool:
                sys.argv += ['-%s' % k]
            else:
                sys.argv += ['-%s' % k, str(v)]

        opt = parser.parse_args()
        opt.cuda = opt.gpu > -1

        sys.argv = prec_argv
        return opt 
开发者ID:lizekang,项目名称:ITDD,代码行数:36,代码来源:translation_server.py

示例6: parse_endpoint

# 需要导入模块: import configargparse [as 别名]
# 或者: from configargparse import ArgumentParser [as 别名]
def parse_endpoint(config_files, args):
    """Parses out endpoint arguments for an autoendpoint node"""
    parser = configargparse.ArgumentParser(
        description='Runs an Endpoint Node.',
        default_config_files=config_files,
        )
    parser.add_argument('--config-endpoint',
                        help="Endpoint node configuration file path",
                        dest='config_file', is_config_file=True)
    parser.add_argument('-p', '--port', help='Public HTTP Endpoint Port',
                        type=int, default=8082, env_var="PORT")
    parser.add_argument('--no_cors', help='Disallow CORS PUTs for update.',
                        action="store_true",
                        default=False, env_var='ALLOW_CORS')
    parser.add_argument('--auth_key', help='Bearer Token source key',
                        type=str, default=[], env_var='AUTH_KEY',
                        action="append")
    parser.add_argument('--client_certs',
                        help="Allowed TLS client certificates",
                        type=str, env_var='CLIENT_CERTS', default="{}")
    parser.add_argument('--proxy_protocol_port',
                        help="Enable a secondary Endpoint Port with HAProxy "
                        "Proxy Protocol handling",
                        type=int, default=None,
                        env_var='PROXY_PROTOCOL_PORT')

    add_shared_args(parser)
    return parser.parse_args(args) 
开发者ID:mozilla-services,项目名称:autopush,代码行数:30,代码来源:main_argparse.py

示例7: add_task_arguments

# 需要导入模块: import configargparse [as 别名]
# 或者: from configargparse import ArgumentParser [as 别名]
def add_task_arguments(cls, parser: argparse.ArgumentParser):
        pass 
开发者ID:espnet,项目名称:espnet,代码行数:4,代码来源:abs_task.py

示例8: get_parser

# 需要导入模块: import configargparse [as 别名]
# 或者: from configargparse import ArgumentParser [as 别名]
def get_parser():
    parser = configargparse.ArgumentParser(
        description='generate RST from argparse options',
        config_file_parser_class=configargparse.YAMLConfigFileParser,
        formatter_class=configargparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('src', type=str, nargs='+',
                        help='source python files that contain get_parser() func')
    return parser


# parser 
开发者ID:espnet,项目名称:espnet,代码行数:13,代码来源:argparse2rst.py

示例9: __init__

# 需要导入模块: import configargparse [as 别名]
# 或者: from configargparse import ArgumentParser [as 别名]
def __init__(
            self,
            config_file_parser_class=cfargparse.YAMLConfigFileParser,
            formatter_class=cfargparse.ArgumentDefaultsHelpFormatter,
            **kwargs):
        super(ArgumentParser, self).__init__(
            config_file_parser_class=config_file_parser_class,
            formatter_class=formatter_class,
            **kwargs) 
开发者ID:harvardnlp,项目名称:encoder-agnostic-adaptation,代码行数:11,代码来源:parse.py

示例10: __init__

# 需要导入模块: import configargparse [as 别名]
# 或者: from configargparse import ArgumentParser [as 别名]
def __init__(self, parent_parsers=None, config_file=None):
        parent_parsers = parent_parsers or []
        self.parser = configargparse.ArgumentParser(parents=parent_parsers)
        self.parser.add_argument(
            '-c', '--config', is_config_file=True, default=config_file,
            help='Path to a configuration file in YAML format.'
        )
        self.parser.add_argument(
            '-l', '--live-mode', action='store_true', dest='live_mode',
            env_var=ENV_LIVE_TEST,
            help='Activate "live" recording mode for tests.'
        )
        self.args = self.parser.parse_args([]) 
开发者ID:Azure,项目名称:azure-python-devtools,代码行数:15,代码来源:config.py

示例11: _get_parser

# 需要导入模块: import configargparse [as 别名]
# 或者: from configargparse import ArgumentParser [as 别名]
def _get_parser():
    parser = configargparse.ArgumentParser(
        config_file_parser_class=configargparse.YAMLConfigFileParser,
        description="OpenNMT-py REST Server")
    parser.add_argument("--ip", type=str, default="0.0.0.0")
    parser.add_argument("--port", type=int, default="5000")
    parser.add_argument("--url_root", type=str, default="/translator")
    parser.add_argument("--debug", "-d", action="store_true")
    parser.add_argument("--config", "-c", type=str,
                        default="./available_models/conf.json")
    return parser 
开发者ID:OpenNMT,项目名称:OpenNMT-py,代码行数:13,代码来源:server.py

示例12: testSubParsers

# 需要导入模块: import configargparse [as 别名]
# 或者: from configargparse import ArgumentParser [as 别名]
def testSubParsers(self):
        config_file1 = tempfile.NamedTemporaryFile(mode="w", delete=True)
        config_file1.write("--i = B")
        config_file1.flush()

        config_file2 = tempfile.NamedTemporaryFile(mode="w", delete=True)
        config_file2.write("p = 10")
        config_file2.flush()

        parser = configargparse.ArgumentParser(prog="myProg")
        subparsers = parser.add_subparsers(title="actions")

        parent_parser = configargparse.ArgumentParser(add_help=False)
        parent_parser.add_argument("-p", "--p", type=int, required=True,
                                   help="set db parameter")

        create_p = subparsers.add_parser("create", parents=[parent_parser],
                                         help="create the orbix environment")
        create_p.add_argument("--i", env_var="INIT", choices=["A","B"],
                              default="A")
        create_p.add_argument("-config", is_config_file=True)


        update_p = subparsers.add_parser("update", parents=[parent_parser],
                                         help="update the orbix environment")
        update_p.add_argument("-config2", is_config_file=True, required=True)

        ns = parser.parse_args(args = "create -p 2 -config "+config_file1.name)
        self.assertEqual(ns.p, 2)
        self.assertEqual(ns.i, "B")

        ns = parser.parse_args(args = "update -config2 " + config_file2.name)
        self.assertEqual(ns.p, 10)
        config_file1.close()
        config_file2.close() 
开发者ID:bw2,项目名称:ConfigArgParse,代码行数:37,代码来源:test_configargparse.py

示例13: testKwrgsArePassedToArgParse

# 需要导入模块: import configargparse [as 别名]
# 或者: from configargparse import ArgumentParser [as 别名]
def testKwrgsArePassedToArgParse(self, argparse_init):
        kwargs_for_argparse = {"allow_abbrev": False, "whatever_other_arg": "something"}

        parser = configargparse.ArgumentParser(add_config_file_help=False, **kwargs_for_argparse)

        argparse_init.assert_called_with(parser, **kwargs_for_argparse) 
开发者ID:bw2,项目名称:ConfigArgParse,代码行数:8,代码来源:test_configargparse.py

示例14: test_FormatHelpProgLib

# 需要导入模块: import configargparse [as 别名]
# 或者: from configargparse import ArgumentParser [as 别名]
def test_FormatHelpProgLib(self):
        parser = argparse.ArgumentParser('format_help_prog')
        self.assertRegex(parser.format_help(), 'usage: format_help_prog .*') 
开发者ID:bw2,项目名称:ConfigArgParse,代码行数:5,代码来源:test_configargparse.py

示例15: parse_connection

# 需要导入模块: import configargparse [as 别名]
# 或者: from configargparse import ArgumentParser [as 别名]
def parse_connection(config_files, args):
    """Parse out connection node arguments for an autopush node"""
    parser = configargparse.ArgumentParser(
        description='Runs a Connection Node.',
        default_config_files=config_files,
        )
    parser.add_argument('--config-connection',
                        help="Connection node configuration file path",
                        dest='config_file', is_config_file=True)
    parser.add_argument('-p', '--port', help='Websocket Port', type=int,
                        default=8080, env_var="PORT")
    parser.add_argument('--router_hostname',
                        help="HTTP Router Hostname to use for internal "
                        "router connects", type=str, default=None,
                        env_var="ROUTER_HOSTNAME")
    parser.add_argument('-r', '--router_port',
                        help="HTTP Router Port for internal router connects",
                        type=int, default=8081, env_var="ROUTER_PORT")
    parser.add_argument('--router_ssl_key',
                        help="Routing listener SSL key path", type=str,
                        default="", env_var="ROUTER_SSL_KEY")
    parser.add_argument('--router_ssl_cert',
                        help="Routing listener SSL cert path", type=str,
                        default="", env_var="ROUTER_SSL_CERT")
    parser.add_argument('--auto_ping_interval',
                        help="Interval between Websocket pings", default=0,
                        type=float, env_var="AUTO_PING_INTERVAL")
    parser.add_argument('--auto_ping_timeout',
                        help="Timeout in seconds for Websocket ping replys",
                        default=4, type=float, env_var="AUTO_PING_TIMEOUT")
    parser.add_argument('--max_connections',
                        help="The maximum number of concurrent connections.",
                        default=0, type=int, env_var="MAX_CONNECTIONS")
    parser.add_argument('--close_handshake_timeout',
                        help="The WebSocket closing handshake timeout. Set to "
                        "0 to disable.", default=0, type=int,
                        env_var="CLOSE_HANDSHAKE_TIMEOUT")
    parser.add_argument('--hello_timeout',
                        help="The client handshake timeout. Set to 0 to"
                        "disable.", default=0, type=int,
                        env_var="HELLO_TIMEOUT")

    add_shared_args(parser)
    return parser.parse_args(args) 
开发者ID:mozilla-services,项目名称:autopush,代码行数:46,代码来源:main_argparse.py


注:本文中的configargparse.ArgumentParser方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。