Hello community, here is the log from the commit of package python-yq for openSUSE:Factory checked in at 2019-10-31 18:18:03 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python-yq (Old) and /work/SRC/openSUSE:Factory/.python-yq.new.2990 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-yq" Thu Oct 31 18:18:03 2019 rev:5 rq:744155 version:2.8.1 Changes: -------- --- /work/SRC/openSUSE:Factory/python-yq/python-yq.changes 2019-05-22 15:41:59.322427068 +0200 +++ /work/SRC/openSUSE:Factory/.python-yq.new.2990/python-yq.changes 2019-10-31 18:18:21.662203418 +0100 @@ -1,0 +2,9 @@ +Wed Oct 30 12:17:49 UTC 2019 - Tomáš Chvátal <[email protected]> + +- Update to 2.8.1: + * Filter out -C and separate commingled yq and jq short options + * Set default block sequence indentation to 2 spaces, –indentless for 0 + * Make main body of yq callable as a library function + * Test and release infrastructure updates + +------------------------------------------------------------------- Old: ---- yq-2.7.2.tar.gz New: ---- yq-2.8.1.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-yq.spec ++++++ --- /var/tmp/diff_new_pack.dGx87x/_old 2019-10-31 18:18:22.474204259 +0100 +++ /var/tmp/diff_new_pack.dGx87x/_new 2019-10-31 18:18:22.474204259 +0100 @@ -18,11 +18,10 @@ %{?!python_module:%define python_module() python-%{**} python3-%{**}} Name: python-yq -Version: 2.7.2 +Version: 2.8.1 Release: 0 Summary: Command-line YAML processor - jq wrapper for YAML documents License: Apache-2.0 -Group: Development/Languages/Python URL: https://github.com/kislyuk/yq Source: https://files.pythonhosted.org/packages/source/y/yq/yq-%{version}.tar.gz BuildRequires: %{python_module setuptools} @@ -69,7 +68,7 @@ %check export LANG=en_US.UTF-8 -PYTHONPATH=%{buildroot}%{python3_sitelib} python3 test/test.py -v +%python_expand PYTHONPATH=%{buildroot}%{$python_sitelib} $python test/test.py -v %files %{python_files} %license LICENSE ++++++ yq-2.7.2.tar.gz -> yq-2.8.1.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yq-2.7.2/MANIFEST.in new/yq-2.8.1/MANIFEST.in --- old/yq-2.7.2/MANIFEST.in 2018-04-28 16:21:59.000000000 +0200 +++ new/yq-2.8.1/MANIFEST.in 2019-10-16 18:29:39.000000000 +0200 @@ -1 +1,2 @@ include LICENSE +recursive-include test * diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yq-2.7.2/PKG-INFO new/yq-2.8.1/PKG-INFO --- old/yq-2.7.2/PKG-INFO 2019-01-09 19:55:01.000000000 +0100 +++ new/yq-2.8.1/PKG-INFO 2019-10-28 17:16:45.000000000 +0100 @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: yq -Version: 2.7.2 +Version: 2.8.1 Summary: Command-line YAML/XML processor - jq wrapper for YAML/XML documents Home-page: https://github.com/kislyuk/yq Author: Andrey Kislyuk @@ -43,6 +43,8 @@ YAML `tags <http://www.yaml.org/spec/1.2/spec.html#id2764295>`_ in the input are ignored (any nested data is treated as untagged). Key order is preserved. + Because YAML treats JSON as a dialect of YAML, you can use yq to convert JSON to YAML: ``yq -y . < in.json > out.yml``. + XML support ----------- ``yq`` also supports XML. The ``yq`` package installs an executable, ``xq``, which diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yq-2.7.2/README.rst new/yq-2.8.1/README.rst --- old/yq-2.7.2/README.rst 2018-08-04 04:43:19.000000000 +0200 +++ new/yq-2.8.1/README.rst 2019-10-16 18:29:39.000000000 +0200 @@ -35,6 +35,8 @@ YAML `tags <http://www.yaml.org/spec/1.2/spec.html#id2764295>`_ in the input are ignored (any nested data is treated as untagged). Key order is preserved. +Because YAML treats JSON as a dialect of YAML, you can use yq to convert JSON to YAML: ``yq -y . < in.json > out.yml``. + XML support ----------- ``yq`` also supports XML. The ``yq`` package installs an executable, ``xq``, which diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yq-2.7.2/setup.py new/yq-2.8.1/setup.py --- old/yq-2.7.2/setup.py 2019-01-09 19:51:35.000000000 +0100 +++ new/yq-2.8.1/setup.py 2019-10-28 17:16:14.000000000 +0100 @@ -6,7 +6,7 @@ setup( name="yq", - version="2.7.2", + version="2.8.1", url="https://github.com/kislyuk/yq", license="Apache Software License", author="Andrey Kislyuk", @@ -27,7 +27,7 @@ include_package_data=True, entry_points={ 'console_scripts': [ - 'yq=yq:main', + 'yq=yq:cli', 'xq=yq:xq_cli' ], }, diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yq-2.7.2/test/test.py new/yq-2.8.1/test/test.py --- old/yq-2.7.2/test/test.py 2019-01-09 19:47:40.000000000 +0100 +++ new/yq-2.8.1/test/test.py 2019-10-28 16:41:04.000000000 +0100 @@ -6,7 +6,7 @@ import os, sys, unittest, tempfile, json, io, platform, subprocess sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) -from yq import main # noqa +from yq import yq, cli # noqa USING_PYTHON2 = True if sys.version_info < (3, 0) else False USING_PYPY = True if platform.python_implementation() == "PyPy" else False @@ -38,7 +38,7 @@ try: sys.stdin = io.StringIO(input_data) sys.stdout = io.BytesIO() if USING_PYTHON2 else io.StringIO() - main(args, input_format=input_format) + cli(args, input_format=input_format) except SystemExit as e: self.assertIn(e.code, expect_exit_codes) finally: @@ -51,7 +51,7 @@ def test_yq(self): for input_format in "yaml", "xml", "toml": try: - main(["--help"], input_format=input_format) + cli(["--help"], input_format=input_format) except SystemExit as e: self.assertEqual(e.code, 0) self.assertEqual(self.run_yq("{}", ["."]), "") @@ -87,9 +87,21 @@ @unittest.skipIf(subprocess.check_output(["jq", "--version"]) < b"jq-1.6", "Test options introduced in jq 1.6") def test_jq16_arg_passthrough(self): - self.assertEqual(self.run_yq("{}", ["-y", ".a=$ARGS.positional", "--args", "a", "b"]), "a:\n- a\n- b\n") + self.assertEqual(self.run_yq("{}", ["--indentless", "-y", ".a=$ARGS.positional", "--args", "a", "b"]), + "a:\n- a\n- b\n") + self.assertEqual(self.run_yq("{}", ["-y", ".a=$ARGS.positional", "--args", "a", "b"]), "a:\n - a\n - b\n") self.assertEqual(self.run_yq("{}", [".", "--jsonargs", "a", "b"]), "") + def test_short_option_separation(self): + # self.assertEqual(self.run_yq('{"a": 1}', ["-yCcC", "."]), "a: 1\n") - Fails on 2.7 and 3.8 + self.assertEqual(self.run_yq('{"a": 1}', ["-CcCy", "."]), "a: 1\n") + self.assertEqual(self.run_yq('{"a": 1}', ["-y", "-CS", "."]), "a: 1\n") + self.assertEqual(self.run_yq('{"a": 1}', ["-y", "-CC", "."]), "a: 1\n") + self.assertEqual(self.run_yq('{"a": 1}', ["-y", "-cC", "."]), "a: 1\n") + self.assertEqual(self.run_yq('{"a": 1}', ["-x", "-cC", "."]), "<a>1</a>\n") + self.assertEqual(self.run_yq('{"a": 1}', ["-C", "."]), "") + self.assertEqual(self.run_yq('{"a": 1}', ["-Cc", "."]), "") + def fd_path(self, fh): return "/dev/fd/{}".format(fh.fileno()) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yq-2.7.2/yq/__init__.py new/yq-2.8.1/yq/__init__.py --- old/yq-2.7.2/yq/__init__.py 2019-01-09 19:50:25.000000000 +0100 +++ new/yq-2.8.1/yq/__init__.py 2019-10-28 16:32:15.000000000 +0100 @@ -27,9 +27,13 @@ class OrderedLoader(yaml.SafeLoader): pass -class OrderedDumper(yaml.SafeDumper): +class OrderedIndentlessDumper(yaml.SafeDumper): pass +class OrderedDumper(yaml.SafeDumper): + def increase_indent(self, flow=False, indentless=False): + return super(OrderedDumper, self).increase_indent(flow, False) + class JSONDateTimeEncoder(json.JSONEncoder): def default(self, o): if isinstance(o, (datetime, date, time)): @@ -59,7 +63,9 @@ OrderedLoader.add_constructor(yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG, construct_mapping) OrderedLoader.add_multi_constructor('', parse_unknown_tags) -OrderedDumper.add_representer(OrderedDict, represent_dict_order) + +for dumper in OrderedIndentlessDumper, OrderedDumper: + dumper.add_representer(OrderedDict, represent_dict_order) # jq arguments that consume positionals must be listed here to avoid our parser mistaking them for our positionals jq_arg_spec = {"--indent": 1, "-f": 1, "--from-file": 1, "-L": 1, "--arg": 2, "--argjson": 2, "--slurpfile": 2, @@ -70,7 +76,7 @@ def get_parser(program_name): # By default suppress these help strings and only enable them in the specific programs. - yaml_output_help, width_help = argparse.SUPPRESS, argparse.SUPPRESS + yaml_output_help, width_help, indentless_help = argparse.SUPPRESS, argparse.SUPPRESS, argparse.SUPPRESS xml_output_help, xml_dtd_help, xml_root_help = argparse.SUPPRESS, argparse.SUPPRESS, argparse.SUPPRESS toml_output_help = argparse.SUPPRESS @@ -78,6 +84,7 @@ current_language = "YAML" yaml_output_help = "Transcode jq JSON output back into YAML and emit it" width_help = "When using --yaml-output, specify string wrap width" + indentless_help = 'When using --yaml-output, indent block style lists (sequences) with 0 spaces instead of 2' elif program_name == "xq": current_language = "XML" xml_output_help = "Transcode jq JSON output back into XML and emit it" @@ -94,64 +101,96 @@ if sys.version_info >= (3, 5): parser_args.update(allow_abbrev=False) # required to disambiguate options listed in jq_arg_spec parser = Parser(**parser_args) - parser.add_argument("--yaml-output", "--yml-output", "-y", action="store_true", help=yaml_output_help) + parser.add_argument("--output-format", default="json", help=argparse.SUPPRESS) + parser.add_argument("--yaml-output", "--yml-output", "-y", dest="output_format", action="store_const", const="yaml", + help=yaml_output_help) parser.add_argument("--width", "-w", type=int, help=width_help) - parser.add_argument("--xml-output", "-x", action="store_true", help=xml_output_help) + parser.add_argument("--indentless-lists", "--indentless", action="store_true", help=indentless_help) + parser.add_argument("--xml-output", "-x", dest="output_format", action="store_const", const="xml", + help=xml_output_help) parser.add_argument("--xml-dtd", action="store_true", help=xml_dtd_help) parser.add_argument("--xml-root", help=xml_root_help) - parser.add_argument("--toml-output", "-t", action="store_true", help=toml_output_help) + parser.add_argument("--toml-output", "-t", dest="output_format", action="store_const", const="toml", + help=toml_output_help) parser.add_argument("--version", action="version", version="%(prog)s {version}".format(version=__version__)) for arg in jq_arg_spec: parser.add_argument(arg, nargs=jq_arg_spec[arg], dest=arg, action="append", help=argparse.SUPPRESS) parser.add_argument("jq_filter") - parser.add_argument("files", nargs="*", type=argparse.FileType()) + parser.add_argument("input_streams", nargs="*", type=argparse.FileType(), metavar="files", default=[sys.stdin]) return parser def xq_cli(): - main(input_format="xml", program_name="xq") + cli(input_format="xml", program_name="xq") def tq_cli(): - main(input_format="toml", program_name="tq") + cli(input_format="toml", program_name="tq") -def main(args=None, input_format="yaml", program_name="yq"): +def cli(args=None, input_format="yaml", program_name="yq"): parser = get_parser(program_name) args, jq_args = parser.parse_known_args(args=args) + + for i, arg in enumerate(jq_args): + if arg.startswith("-") and not arg.startswith("--"): + if "y" in arg: + args.output_format = "yaml" + elif "x" in arg: + args.output_format = "xml" + jq_args[i] = arg.replace("x", "").replace("y", "") + if args.output_format != "json": + jq_args[i] = jq_args[i].replace("C", "") + if jq_args[i] == "-": + jq_args[i] = None + + jq_args = [arg for arg in jq_args if arg is not None] + for arg in jq_arg_spec: values = getattr(args, arg, None) + delattr(args, arg) if values is not None: for value_group in values: jq_args.append(arg) jq_args.extend(value_group) - if getattr(args, "--from-file") or getattr(args, "-f"): - args.files.insert(0, argparse.FileType()(args.jq_filter)) + + if "--from-file" in jq_args or "-f" in jq_args: + args.input_streams.insert(0, argparse.FileType()(args.jq_filter)) else: jq_filter_arg_loc = len(jq_args) - if getattr(args, "--args"): + if "--args" in jq_args: jq_filter_arg_loc = jq_args.index('--args') + 1 - elif getattr(args, "--jsonargs"): + elif "--jsonargs" in jq_args: jq_filter_arg_loc = jq_args.index('--jsonargs') + 1 jq_args.insert(jq_filter_arg_loc, args.jq_filter) + delattr(args, "jq_filter") - if sys.stdin.isatty() and not args.files: + if sys.stdin.isatty() and not args.input_streams: return parser.print_help() - converting_output = args.yaml_output or args.xml_output or args.toml_output + yq(input_format=input_format, program_name=program_name, jq_args=jq_args, **vars(args)) + +def yq(input_streams=None, output_stream=None, input_format="yaml", output_format="json", + program_name="yq", width=None, indentless_lists=False, xml_root=None, xml_dtd=False, jq_args=frozenset(), + exit_func=None): + if not input_streams: + input_streams = [sys.stdin] + if not output_stream: + output_stream = sys.stdout + if not exit_func: + exit_func = sys.exit + converting_output = True if output_format != "json" else False try: # Note: universal_newlines is just a way to induce subprocess to make stdin a text buffer and encode it for us - jq = subprocess.Popen(["jq"] + jq_args, + jq = subprocess.Popen(["jq"] + list(jq_args), stdin=subprocess.PIPE, stdout=subprocess.PIPE if converting_output else None, universal_newlines=True) except OSError as e: msg = "{}: Error starting jq: {}: {}. Is jq installed and available on PATH?" - parser.exit(msg.format(program_name, type(e).__name__, e)) + exit_func(msg.format(program_name, type(e).__name__, e)) try: - input_streams = args.files if args.files else [sys.stdin] - if converting_output: # TODO: enable true streaming in this branch (with asyncio, asyncproc, a multi-shot variant of # subprocess.Popen._communicate, etc.) @@ -171,41 +210,43 @@ input_payload = "\n".join(json.dumps(doc, cls=JSONDateTimeEncoder) for doc in input_docs) jq_out, jq_err = jq.communicate(input_payload) json_decoder = json.JSONDecoder(object_pairs_hook=OrderedDict) - if args.yaml_output: - yaml.dump_all(decode_docs(jq_out, json_decoder), stream=sys.stdout, Dumper=OrderedDumper, - width=args.width, allow_unicode=True, default_flow_style=False) - elif args.xml_output: + if output_format == "yaml": + dumper_class = OrderedIndentlessDumper if indentless_lists else OrderedDumper + yaml.dump_all(decode_docs(jq_out, json_decoder), stream=output_stream, Dumper=dumper_class, + width=width, allow_unicode=True, default_flow_style=False) + elif output_format == "xml": import xmltodict for doc in decode_docs(jq_out, json_decoder): - if args.xml_root: - doc = {args.xml_root: doc} + if xml_root: + doc = {xml_root: doc} elif not isinstance(doc, OrderedDict): msg = ("{}: Error converting JSON to XML: cannot represent non-object types at top level. " "Use --xml-root=name to envelope your output with a root element.") - parser.exit(msg.format(program_name)) - full_document = True if args.xml_dtd else False + exit_func(msg.format(program_name)) + full_document = True if xml_dtd else False try: - xmltodict.unparse(doc, output=sys.stdout, full_document=full_document, pretty=True, indent=" ") + xmltodict.unparse(doc, output=output_stream, full_document=full_document, pretty=True, + indent=" ") except ValueError as e: if "Document must have exactly one root" in str(e): raise Exception(str(e) + " Use --xml-root=name to envelope your output with a root element") else: raise - sys.stdout.write(b"\n" if sys.version_info < (3, 0) else "\n") - elif args.toml_output: + output_stream.write(b"\n" if sys.version_info < (3, 0) else "\n") + elif output_format == "toml": import toml for doc in decode_docs(jq_out, json_decoder): if not isinstance(doc, OrderedDict): msg = "{}: Error converting JSON to TOML: cannot represent non-object types at top level." - parser.exit(msg.format(program_name)) + exit_func(msg.format(program_name)) if USING_PYTHON2: # For Python 2, dump the string and encode it into bytes. output = toml.dumps(doc) - sys.stdout.write(output.encode("utf-8")) + output_stream.write(output.encode("utf-8")) else: # For Python 3, write the unicode to the buffer directly. - toml.dump(doc, sys.stdout) + toml.dump(doc, output_stream) else: if input_format == "yaml": for input_stream in input_streams: @@ -229,6 +270,6 @@ jq.wait() for input_stream in input_streams: input_stream.close() - exit(jq.returncode) + exit_func(jq.returncode) except Exception as e: - parser.exit("{}: Error running jq: {}: {}.".format(program_name, type(e).__name__, e)) + exit_func("{}: Error running jq: {}: {}.".format(program_name, type(e).__name__, e)) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yq-2.7.2/yq/version.py new/yq-2.8.1/yq/version.py --- old/yq-2.7.2/yq/version.py 2019-01-09 19:54:54.000000000 +0100 +++ new/yq-2.8.1/yq/version.py 2019-10-28 17:16:41.000000000 +0100 @@ -1 +1 @@ -__version__ = '2.7.2' +__version__ = '2.8.1' diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yq-2.7.2/yq.egg-info/PKG-INFO new/yq-2.8.1/yq.egg-info/PKG-INFO --- old/yq-2.7.2/yq.egg-info/PKG-INFO 2019-01-09 19:55:01.000000000 +0100 +++ new/yq-2.8.1/yq.egg-info/PKG-INFO 2019-10-28 17:16:45.000000000 +0100 @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: yq -Version: 2.7.2 +Version: 2.8.1 Summary: Command-line YAML/XML processor - jq wrapper for YAML/XML documents Home-page: https://github.com/kislyuk/yq Author: Andrey Kislyuk @@ -43,6 +43,8 @@ YAML `tags <http://www.yaml.org/spec/1.2/spec.html#id2764295>`_ in the input are ignored (any nested data is treated as untagged). Key order is preserved. + Because YAML treats JSON as a dialect of YAML, you can use yq to convert JSON to YAML: ``yq -y . < in.json > out.yml``. + XML support ----------- ``yq`` also supports XML. The ``yq`` package installs an executable, ``xq``, which diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yq-2.7.2/yq.egg-info/entry_points.txt new/yq-2.8.1/yq.egg-info/entry_points.txt --- old/yq-2.7.2/yq.egg-info/entry_points.txt 2019-01-09 19:55:01.000000000 +0100 +++ new/yq-2.8.1/yq.egg-info/entry_points.txt 2019-10-28 17:16:45.000000000 +0100 @@ -1,4 +1,4 @@ [console_scripts] xq = yq:xq_cli -yq = yq:main +yq = yq:cli
