Python configargparse.ArgumentParser() Examples
The following are 24
code examples of configargparse.ArgumentParser().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
configargparse
, or try the search function
.
Example #1
Source File: translator.py From ITDD with MIT License | 6 votes |
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
Example #2
Source File: translator2.py From ITDD with MIT License | 6 votes |
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
Example #3
Source File: preprocess.py From ITDD with MIT License | 6 votes |
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
Example #4
Source File: diagnostic_cli.py From autopush with Mozilla Public License 2.0 | 6 votes |
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)
Example #5
Source File: args.py From ctf-gameserver with ISC License | 6 votes |
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
Example #6
Source File: args.py From ctf-gameserver with ISC License | 6 votes |
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
Example #7
Source File: args.py From ctf-gameserver with ISC License | 6 votes |
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
Example #8
Source File: args.py From ctf-gameserver with ISC License | 6 votes |
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
Example #9
Source File: args.py From ctf-gameserver with ISC License | 6 votes |
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
Example #10
Source File: test_configargparse.py From ConfigArgParse with MIT License | 5 votes |
def test_FormatHelpProgLib(self): parser = argparse.ArgumentParser('format_help_prog') self.assertRegex(parser.format_help(), 'usage: format_help_prog .*')
Example #11
Source File: test_configargparse.py From ConfigArgParse with MIT License | 5 votes |
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)
Example #12
Source File: test_configargparse.py From ConfigArgParse with MIT License | 5 votes |
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()
Example #13
Source File: parse.py From OpenNMT-kpg-release with MIT License | 5 votes |
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)
Example #14
Source File: server.py From OpenNMT-kpg-release with MIT License | 5 votes |
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
Example #15
Source File: parse.py From OpenNMT-py with MIT License | 5 votes |
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)
Example #16
Source File: server.py From OpenNMT-py with MIT License | 5 votes |
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
Example #17
Source File: config.py From azure-python-devtools with MIT License | 5 votes |
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([])
Example #18
Source File: parse.py From encoder-agnostic-adaptation with MIT License | 5 votes |
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)
Example #19
Source File: argparse2rst.py From espnet with Apache License 2.0 | 5 votes |
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
Example #20
Source File: abs_task.py From espnet with Apache License 2.0 | 5 votes |
def add_task_arguments(cls, parser: argparse.ArgumentParser): pass
Example #21
Source File: main_argparse.py From autopush with Mozilla Public License 2.0 | 5 votes |
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)
Example #22
Source File: translation_server.py From ITDD with MIT License | 5 votes |
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
Example #23
Source File: tts_decode.py From adviser with GNU General Public License v3.0 | 4 votes |
def get_parser(): """Get parser of decoding arguments.""" parser = configargparse.ArgumentParser( description='Synthesize speech from text using a TTS model on one CPU', config_file_parser_class=configargparse.YAMLConfigFileParser, formatter_class=configargparse.ArgumentDefaultsHelpFormatter) # general configuration parser.add('--config', is_config_file=True, help='config file path') parser.add('--config2', is_config_file=True, help='second config file path that overwrites the settings in `--config`.') parser.add('--config3', is_config_file=True, help='third config file path that overwrites the settings in `--config` and `--config2`.') parser.add_argument('--ngpu', default=0, type=int, help='Number of GPUs') parser.add_argument('--backend', default='pytorch', type=str, choices=['chainer', 'pytorch'], help='Backend library') parser.add_argument('--debugmode', default=1, type=int, help='Debugmode') parser.add_argument('--seed', default=1, type=int, help='Random seed') parser.add_argument('--out', type=str, required=True, help='Output filename') parser.add_argument('--verbose', '-V', default=0, type=int, help='Verbose option') parser.add_argument('--preprocess-conf', type=str, default=None, help='The configuration file for the pre-processing') # task related parser.add_argument('--json', type=str, required=True, help='Filename of train label data (json)') parser.add_argument('--model', type=str, required=True, help='Model file parameters to read') parser.add_argument('--model-conf', type=str, default=None, help='Model config file') # decoding related parser.add_argument('--maxlenratio', type=float, default=5, help='Maximum length ratio in decoding') parser.add_argument('--minlenratio', type=float, default=0, help='Minimum length ratio in decoding') parser.add_argument('--threshold', type=float, default=0.5, help='Threshold value in decoding') parser.add_argument('--use-att-constraint', type=strtobool, default=False, help='Whether to use the attention constraint') parser.add_argument('--backward-window', type=int, default=1, help='Backward window size in the attention constraint') parser.add_argument('--forward-window', type=int, default=3, help='Forward window size in the attention constraint') # save related parser.add_argument('--save-durations', default=False, type=strtobool, help='Whether to save durations converted from attentions') parser.add_argument('--save-focus-rates', default=False, type=strtobool, help='Whether to save focus rates of attentions') return parser
Example #24
Source File: main_argparse.py From autopush with Mozilla Public License 2.0 | 4 votes |
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)