Hello community, here is the log from the commit of package python-configargparse for openSUSE:Factory checked in at 2020-02-20 15:00:31 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python-configargparse (Old) and /work/SRC/openSUSE:Factory/.python-configargparse.new.26092 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-configargparse" Thu Feb 20 15:00:31 2020 rev:7 rq:777654 version:1.0 Changes: -------- --- /work/SRC/openSUSE:Factory/python-configargparse/python-configargparse.changes 2019-11-22 10:27:35.001235350 +0100 +++ /work/SRC/openSUSE:Factory/.python-configargparse.new.26092/python-configargparse.changes 2020-02-20 15:00:34.318899268 +0100 @@ -1,0 +2,6 @@ +Thu Feb 20 11:25:43 UTC 2020 - Steve Kowalik <steven.kowa...@suse.com> + +- Update to 1.0. + * Dash supported as first char of argument + +------------------------------------------------------------------- Old: ---- ConfigArgParse-0.15.1.tar.gz New: ---- ConfigArgParse-1.0.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-configargparse.spec ++++++ --- /var/tmp/diff_new_pack.BMbpJE/_old 2020-02-20 15:00:35.806902188 +0100 +++ /var/tmp/diff_new_pack.BMbpJE/_new 2020-02-20 15:00:35.810902196 +0100 @@ -1,7 +1,7 @@ # # spec file for package python-configargparse # -# Copyright (c) 2019 SUSE LLC +# Copyright (c) 2020 SUSE LLC # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -18,7 +18,7 @@ %{?!python_module:%define python_module() python-%{**} python3-%{**}} Name: python-configargparse -Version: 0.15.1 +Version: 1.0 Release: 0 Summary: A drop-in replacement for argparse License: MIT ++++++ ConfigArgParse-0.15.1.tar.gz -> ConfigArgParse-1.0.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ConfigArgParse-0.15.1/ConfigArgParse.egg-info/PKG-INFO new/ConfigArgParse-1.0/ConfigArgParse.egg-info/PKG-INFO --- old/ConfigArgParse-0.15.1/ConfigArgParse.egg-info/PKG-INFO 2019-10-08 16:50:55.000000000 +0200 +++ new/ConfigArgParse-1.0/ConfigArgParse.egg-info/PKG-INFO 2019-12-30 06:16:29.000000000 +0100 @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: ConfigArgParse -Version: 0.15.1 +Version: 1.0 Summary: A drop-in replacement for argparse that allows options to also be set via config files and/or environment variables. Home-page: https://github.com/bw2/ConfigArgParse License: MIT @@ -106,7 +106,7 @@ .. code:: bash - python my_script.py --genome hg19 --my-config config.txt f1.vcf f2.vcf + DBSNP_PATH=/data/dbsnp/variants_v2.vcf python config_test.py --my-config config.txt f1.vcf f2.vcf *output:* @@ -114,30 +114,36 @@ .. code:: bash - Namespace(dbsnp='/data/dbsnp/variants.vcf', genome='hg19', my_config='config.txt', vcf=['f1.vcf', 'f2.vcf'], verbose=False) + Namespace(dbsnp='/data/dbsnp/variants_v2.vcf', genome='HCMV', my_config='config.txt', v=False, vcf=['f1.vcf', 'f2.vcf']) ---------- - usage: my_script.py [-h] --genome GENOME [-v] -c MY_CONFIG [-d DBSNP] - vcf [vcf ...] + usage: config_test.py [-h] -c MY_CONFIG --genome GENOME [-v] [-d DBSNP] + vcf [vcf ...] + Args that start with '--' (eg. --genome) can also be set in a config file - (/etc/settings.ini or /home/jeff/.my_settings or provided via -c) by using - .ini or .yaml-style syntax (eg. genome=value). Command-line values override - environment variables which override config file values which override - defaults. - + (/etc/app/conf.d/*.conf or ~/.my_settings or specified via -c). Config file + syntax allows: key=value, flag=true, stuff=[a,b,c] (for details, see syntax at + https://goo.gl/R74nmi). If an arg is specified in more than one place, then + commandline values override environment variables which override config file + values which override defaults. + positional arguments: - vcf variant file + vcf variant file(s) + optional arguments: -h, --help show this help message and exit - --genome GENOME path to genome file - -v verbose -c MY_CONFIG, --my-config MY_CONFIG config file path + --genome GENOME path to genome file + -v verbose -d DBSNP, --dbsnp DBSNP known variants .vcf [env var: DBSNP_PATH] + ---------- - Command Line Args: --genome hg19 --my-config config.txt f1.vcf f2.vcf + Command Line Args: --my-config config.txt f1.vcf f2.vcf + Environment Variables: + DBSNP_PATH: /data/dbsnp/variants_v2.vcf Config File (config.txt): - dbsnp: /data/dbsnp/variants.vcf + genome: HCMV Special Values ~~~~~~~~~~~~~~ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ConfigArgParse-0.15.1/ConfigArgParse.egg-info/SOURCES.txt new/ConfigArgParse-1.0/ConfigArgParse.egg-info/SOURCES.txt --- old/ConfigArgParse-0.15.1/ConfigArgParse.egg-info/SOURCES.txt 2019-10-08 16:50:55.000000000 +0200 +++ new/ConfigArgParse-1.0/ConfigArgParse.egg-info/SOURCES.txt 2019-12-30 06:16:29.000000000 +0100 @@ -9,4 +9,6 @@ ConfigArgParse.egg-info/requires.txt ConfigArgParse.egg-info/top_level.txt tests/__init__.py -tests/test_configargparse.py \ No newline at end of file +tests/__init__.pyc +tests/test_configargparse.py +tests/test_configargparse.pyc \ No newline at end of file diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ConfigArgParse-0.15.1/PKG-INFO new/ConfigArgParse-1.0/PKG-INFO --- old/ConfigArgParse-0.15.1/PKG-INFO 2019-10-08 16:50:55.000000000 +0200 +++ new/ConfigArgParse-1.0/PKG-INFO 2019-12-30 06:16:29.000000000 +0100 @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: ConfigArgParse -Version: 0.15.1 +Version: 1.0 Summary: A drop-in replacement for argparse that allows options to also be set via config files and/or environment variables. Home-page: https://github.com/bw2/ConfigArgParse License: MIT @@ -106,7 +106,7 @@ .. code:: bash - python my_script.py --genome hg19 --my-config config.txt f1.vcf f2.vcf + DBSNP_PATH=/data/dbsnp/variants_v2.vcf python config_test.py --my-config config.txt f1.vcf f2.vcf *output:* @@ -114,30 +114,36 @@ .. code:: bash - Namespace(dbsnp='/data/dbsnp/variants.vcf', genome='hg19', my_config='config.txt', vcf=['f1.vcf', 'f2.vcf'], verbose=False) + Namespace(dbsnp='/data/dbsnp/variants_v2.vcf', genome='HCMV', my_config='config.txt', v=False, vcf=['f1.vcf', 'f2.vcf']) ---------- - usage: my_script.py [-h] --genome GENOME [-v] -c MY_CONFIG [-d DBSNP] - vcf [vcf ...] + usage: config_test.py [-h] -c MY_CONFIG --genome GENOME [-v] [-d DBSNP] + vcf [vcf ...] + Args that start with '--' (eg. --genome) can also be set in a config file - (/etc/settings.ini or /home/jeff/.my_settings or provided via -c) by using - .ini or .yaml-style syntax (eg. genome=value). Command-line values override - environment variables which override config file values which override - defaults. - + (/etc/app/conf.d/*.conf or ~/.my_settings or specified via -c). Config file + syntax allows: key=value, flag=true, stuff=[a,b,c] (for details, see syntax at + https://goo.gl/R74nmi). If an arg is specified in more than one place, then + commandline values override environment variables which override config file + values which override defaults. + positional arguments: - vcf variant file + vcf variant file(s) + optional arguments: -h, --help show this help message and exit - --genome GENOME path to genome file - -v verbose -c MY_CONFIG, --my-config MY_CONFIG config file path + --genome GENOME path to genome file + -v verbose -d DBSNP, --dbsnp DBSNP known variants .vcf [env var: DBSNP_PATH] + ---------- - Command Line Args: --genome hg19 --my-config config.txt f1.vcf f2.vcf + Command Line Args: --my-config config.txt f1.vcf f2.vcf + Environment Variables: + DBSNP_PATH: /data/dbsnp/variants_v2.vcf Config File (config.txt): - dbsnp: /data/dbsnp/variants.vcf + genome: HCMV Special Values ~~~~~~~~~~~~~~ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ConfigArgParse-0.15.1/README.rst new/ConfigArgParse-1.0/README.rst --- old/ConfigArgParse-0.15.1/README.rst 2019-10-08 16:02:52.000000000 +0200 +++ new/ConfigArgParse-1.0/README.rst 2019-10-24 03:14:22.000000000 +0200 @@ -100,7 +100,7 @@ .. code:: bash - python my_script.py --genome hg19 --my-config config.txt f1.vcf f2.vcf + DBSNP_PATH=/data/dbsnp/variants_v2.vcf python config_test.py --my-config config.txt f1.vcf f2.vcf *output:* @@ -108,30 +108,36 @@ .. code:: bash - Namespace(dbsnp='/data/dbsnp/variants.vcf', genome='hg19', my_config='config.txt', vcf=['f1.vcf', 'f2.vcf'], verbose=False) + Namespace(dbsnp='/data/dbsnp/variants_v2.vcf', genome='HCMV', my_config='config.txt', v=False, vcf=['f1.vcf', 'f2.vcf']) ---------- - usage: my_script.py [-h] --genome GENOME [-v] -c MY_CONFIG [-d DBSNP] - vcf [vcf ...] + usage: config_test.py [-h] -c MY_CONFIG --genome GENOME [-v] [-d DBSNP] + vcf [vcf ...] + Args that start with '--' (eg. --genome) can also be set in a config file - (/etc/settings.ini or /home/jeff/.my_settings or provided via -c) by using - .ini or .yaml-style syntax (eg. genome=value). Command-line values override - environment variables which override config file values which override - defaults. - + (/etc/app/conf.d/*.conf or ~/.my_settings or specified via -c). Config file + syntax allows: key=value, flag=true, stuff=[a,b,c] (for details, see syntax at + https://goo.gl/R74nmi). If an arg is specified in more than one place, then + commandline values override environment variables which override config file + values which override defaults. + positional arguments: - vcf variant file + vcf variant file(s) + optional arguments: -h, --help show this help message and exit - --genome GENOME path to genome file - -v verbose -c MY_CONFIG, --my-config MY_CONFIG config file path + --genome GENOME path to genome file + -v verbose -d DBSNP, --dbsnp DBSNP known variants .vcf [env var: DBSNP_PATH] + ---------- - Command Line Args: --genome hg19 --my-config config.txt f1.vcf f2.vcf + Command Line Args: --my-config config.txt f1.vcf f2.vcf + Environment Variables: + DBSNP_PATH: /data/dbsnp/variants_v2.vcf Config File (config.txt): - dbsnp: /data/dbsnp/variants.vcf + genome: HCMV Special Values ~~~~~~~~~~~~~~ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ConfigArgParse-0.15.1/configargparse.py new/ConfigArgParse-1.0/configargparse.py --- old/ConfigArgParse-0.15.1/configargparse.py 2019-10-08 16:50:17.000000000 +0200 +++ new/ConfigArgParse-1.0/configargparse.py 2019-12-30 06:11:08.000000000 +0100 @@ -293,6 +293,8 @@ configargparse args will be ignored. If false, they will be processed and appended to the commandline like other args, and can be retrieved using parse_known_args() instead of parse_args() + config_file_open_func: function used to open a config file for reading + or writing. Needs to return a file-like object. config_file_parser_class: configargparse.ConfigFileParser subclass which determines the config file format. configargparse comes with DefaultConfigFileParser and YAMLConfigFileParser. @@ -335,6 +337,8 @@ "command line args and writes them out to a config file at the " "given path, then exits") + self._config_file_open_func = kwargs.pop('config_file_open_func', open) + self._add_config_file_help = add_config_file_help self._add_env_var_help = add_env_var_help self._auto_env_var_prefix = auto_env_var_prefix @@ -397,17 +401,6 @@ else: args = list(args) - # normalize args by converting args like --key=value to --key value - normalized_args = [] - for arg in args: - if arg and arg[0] in self.prefix_chars and '=' in arg: - key, value = arg.split('=', 1) - normalized_args.append(key) - normalized_args.append(value) - else: - normalized_args.append(arg) - args = normalized_args - for a in self._actions: a.is_positional_arg = not a.option_strings @@ -438,7 +431,7 @@ nargs = False actions_with_env_var_values = [a for a in self._actions if not a.is_positional_arg and a.env_var and a.env_var in env_vars - and not already_on_command_line(args, a.option_strings)] + and not already_on_command_line(args, a.option_strings, self.prefix_chars)] for action in actions_with_env_var_values: key = action.env_var value = env_vars[key] @@ -497,13 +490,14 @@ if key in known_config_keys: action = known_config_keys[key] discard_this_key = already_on_command_line( - args, action.option_strings) + args, action.option_strings, self.prefix_chars) else: action = None discard_this_key = self._ignore_unknown_config_file_keys or \ already_on_command_line( args, - [self.get_command_line_key_for_unknown_config_file_setting(key)]) + [self.get_command_line_key_for_unknown_config_file_setting(key)], + self.prefix_chars) if not discard_this_key: config_args += self.convert_item_to_command_line_arg( @@ -526,7 +520,7 @@ for action in self._actions: cares_about_default_value = (not action.is_positional_arg or action.nargs in [OPTIONAL, ZERO_OR_MORE]) - if (already_on_command_line(args, action.option_strings) or + if (already_on_command_line(args, action.option_strings, self.prefix_chars) or not cares_about_default_value or action.default is None or action.default == SUPPRESS or @@ -564,7 +558,7 @@ for output_file_path in output_file_paths: # validate the output file path try: - with open(output_file_path, "w") as output_file: + with self._config_file_open_func(output_file_path, "w") as output_file: pass except IOError as e: raise ValueError("Couldn't open {} for writing: {}".format( @@ -575,7 +569,7 @@ self._source_to_settings, parsed_namespace) file_contents = self._config_file_parser.serialize(config_items) for output_file_path in output_file_paths: - with open(output_file_path, "w") as output_file: + with self._config_file_open_func(output_file_path, "w") as output_file: output_file.write(file_contents) message = "Wrote config file to " + ", ".join(output_file_paths) if exit_after: @@ -617,7 +611,8 @@ config_file_keys = self.get_possible_config_keys(action) if config_file_keys and not action.is_positional_arg and \ already_on_command_line(existing_command_line_args, - action.option_strings): + action.option_strings, + self.prefix_chars): value = getattr(parsed_namespace, action.dest, None) if value is not None: if isinstance(value, bool): @@ -675,8 +670,7 @@ elif isinstance(value, list): if action is None or isinstance(action, argparse._AppendAction): for list_elem in value: - args.append( command_line_key ) - args.append( str(list_elem) ) + args.append( "%s=%s" % (command_line_key, str(list_elem)) ) elif (isinstance(action, argparse._StoreAction) and action.nargs in ('+', '*')) or ( isinstance(action.nargs, int) and action.nargs > 1): args.append( command_line_key ) @@ -686,8 +680,7 @@ self.error(("%s can't be set to a list '%s' unless its action type is changed " "to 'append' or nargs is set to '*', '+', or > 1") % (key, value)) elif isinstance(value, str): - args.append( command_line_key ) - args.append( value ) + args.append( "%s=%s" % (command_line_key, value) ) else: raise ValueError("Unexpected value type {} for value: {}".format( type(value), value)) @@ -719,11 +712,13 @@ constructor that are present on disk. Args: - command_line_args: List of all args (already split on spaces) + command_line_args: List of all args """ # open any default config files - config_files = [open(f) for files in map(glob.glob, map(os.path.expanduser, self._default_config_files)) - for f in files] + config_files = [] + for files in map(glob.glob, map(os.path.expanduser, self._default_config_files)): + for f in files: + config_files.append(self._config_file_open_func(f)) # list actions with is_config_file_arg=True. Its possible there is more # than one such arg. @@ -763,7 +758,7 @@ if not os.path.isfile(user_config_file): self.error('File not found: %s' % user_config_file) - config_files += [open(user_config_file)] + config_files += [self._config_file_open_func(user_config_file)] return config_files @@ -909,13 +904,21 @@ return action -def already_on_command_line(existing_args_list, potential_command_line_args): +def already_on_command_line(existing_args_list, potential_command_line_args, prefix_chars): """Utility method for checking if any of the potential_command_line_args is already present in existing_args. """ - return any(potential_arg in existing_args_list - for potential_arg in potential_command_line_args) + arg_names = [] + for arg_string in existing_args_list: + if arg_string and arg_string[0] in prefix_chars and "=" in arg_string : + option_string, explicit_arg = arg_string.split("=", 1) + arg_names.append(option_string) + else: + arg_names.append(arg_string) + return any( + potential_arg in arg_names for potential_arg in potential_command_line_args + ) # wrap ArgumentParser's add_argument(..) method with the one above diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ConfigArgParse-0.15.1/setup.py new/ConfigArgParse-1.0/setup.py --- old/ConfigArgParse-0.15.1/setup.py 2019-10-08 16:50:27.000000000 +0200 +++ new/ConfigArgParse-1.0/setup.py 2019-12-30 06:06:27.000000000 +0100 @@ -76,7 +76,7 @@ setup( name='ConfigArgParse', - version="0.15.1", + version="1.0", description='A drop-in replacement for argparse that allows options to ' 'also be set via config files and/or environment variables.', long_description=long_description, Binary files old/ConfigArgParse-0.15.1/tests/__init__.pyc and new/ConfigArgParse-1.0/tests/__init__.pyc differ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ConfigArgParse-0.15.1/tests/test_configargparse.py new/ConfigArgParse-1.0/tests/test_configargparse.py --- old/ConfigArgParse-0.15.1/tests/test_configargparse.py 2019-10-08 16:02:52.000000000 +0200 +++ new/ConfigArgParse-1.0/tests/test_configargparse.py 2019-12-30 06:11:36.000000000 +0100 @@ -1,5 +1,6 @@ import argparse import configargparse +from contextlib import contextmanager import inspect import logging import sys @@ -40,6 +41,20 @@ return arg_parser +@contextmanager +def captured_output(): + """ + swap stdout and stderr for StringIO so we can do asserts on outputs. + """ + new_out, new_err = StringIO(), StringIO() + old_out, old_err = sys.stdout, sys.stderr + try: + sys.stdout, sys.stderr = new_out, new_err + yield sys.stdout, sys.stderr + finally: + sys.stdout, sys.stderr = old_out, old_err + + class TestCase(unittest.TestCase): def initParser(self, *args, **kwargs): @@ -270,6 +285,28 @@ def testBasicCase2_WithGroups(self): self.testBasicCase2(use_groups=True) + def testCustomOpenFunction(self): + expected_output = 'dummy open called' + + def dummy_open(p): + print(expected_output) + return open(p) + + self.initParser(config_file_open_func=dummy_open) + self.add_arg('--config', is_config_file=True) + self.add_arg('--arg1', default=1, type=int) + + with tempfile.NamedTemporaryFile(mode='w', delete=False) as config_file: + config_file.write('arg1 2') + config_file_path = config_file.name + + with captured_output() as (out, _): + args = self.parse('--config {}'.format(config_file_path)) + self.assertTrue(hasattr(args, 'arg1')) + self.assertEqual(args.arg1, 2) + output = out.getvalue().strip() + self.assertEqual(output, expected_output) + def testPositionalAndConfigVarLists(self): self.initParser() self.add_arg("a") @@ -460,12 +497,12 @@ ns, args = self.parse_known("-x 10 --y 3.8", config_file_contents="bla=3", env_vars={"bla": "2"}) - self.assertListEqual(args, ["--bla", "3"]) + self.assertListEqual(args, ["--bla=3"]) self.initParser(ignore_unknown_config_file_keys=False) ns, args = self.parse_known(args="-x 1", config_file_contents="bla=3", env_vars={"bla": "2"}) - self.assertEqual(set(args), {"--bla", "3", "-x", "1"}) + self.assertEqual(set(args), {"--bla=3", "-x", "1"}) def testBooleanValuesCanBeExpressedAsNumbers(self): self.initParser() @@ -542,6 +579,70 @@ ns = self.parse("", env_vars = {"file": "[1,2,3]", "VERBOSE": "true"}) self.assertIsNone(ns.file) + def testValuesStartingWithDash(self): + self.initParser() + self.add_arg("--arg0") + self.add_arg("--arg1", env_var="ARG1") + self.add_arg("--arg2") + self.add_arg("--arg3", action='append') + self.add_arg("--arg4", action='append', env_var="ARG4") + self.add_arg("--arg5", action='append') + self.add_arg("--arg6") + + ns = self.parse( + "--arg0=-foo --arg3=-foo --arg3=-bar --arg6=-test-more-dashes", + config_file_contents="arg2: -foo\narg5: [-foo, -bar]", + env_vars={"ARG1": "-foo", "ARG4": "[-foo, -bar]"} + ) + self.assertEqual(ns.arg0, "-foo") + self.assertEqual(ns.arg1, "-foo") + self.assertEqual(ns.arg2, "-foo") + self.assertEqual(ns.arg3, ["-foo", "-bar"]) + self.assertEqual(ns.arg4, ["-foo", "-bar"]) + self.assertEqual(ns.arg5, ["-foo", "-bar"]) + self.assertEqual(ns.arg6, "-test-more-dashes") + + def testPriorityKnown(self): + self.initParser() + self.add_arg("--arg", env_var="ARG") + + ns = self.parse( + "--arg command_line_val", + config_file_contents="arg: config_val", + env_vars={"ARG": "env_val"} + ) + self.assertEqual(ns.arg, "command_line_val") + + ns = self.parse( + "--arg=command_line_val", + config_file_contents="arg: config_val", + env_vars={"ARG": "env_val"} + ) + self.assertEqual(ns.arg, "command_line_val") + + ns = self.parse( + "", + config_file_contents="arg: config_val", + env_vars={"ARG": "env_val"} + ) + self.assertEqual(ns.arg, "env_val") + + def testPriorityUnknown(self): + self.initParser() + + ns, args = self.parse_known( + "--arg command_line_val", + config_file_contents="arg: config_val", + env_vars={"arg": "env_val"} + ) + self.assertListEqual(args, ["--arg", "command_line_val"]) + + ns, args = self.parse_known( + "--arg=command_line_val", + config_file_contents="arg: config_val", + ) + self.assertListEqual(args, ["--arg=command_line_val"]) + def testAutoEnvVarPrefix(self): self.initParser(auto_env_var_prefix="TEST_") self.add_arg("-a", "--arg0", is_config_file_arg=True) @@ -719,7 +820,7 @@ known, unknown = self.parse_known(command) - self.assertListEqual(unknown, ['--a2a', '0.5', '--a3a', '0.5']) + self.assertListEqual(unknown, ['--a2a=0.5', '--a3a=0.5']) def test_FormatHelp(self): self.initParser(args_for_setting_config_path=["-c", "--config"], Binary files old/ConfigArgParse-0.15.1/tests/test_configargparse.pyc and new/ConfigArgParse-1.0/tests/test_configargparse.pyc differ