From 6a2dbbd99fabf63aff4871f4917df6574b05b05d83b949d6115f913d5d3a0091 Mon Sep 17 00:00:00 2001 From: Nico Krapp Date: Mon, 2 Dec 2024 15:32:18 +0000 Subject: [PATCH] - Add patch parentheses.patch to fix tests on Python 3.13 OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-astunparse?expand=0&rev=22 --- .gitattributes | 23 ++++ .gitignore | 1 + astunparse-1.6.3.tar.gz | 3 + astunparse-pr57-py39.patch | 74 ++++++++++++ fix-formatted-value.patch | 23 ++++ parentheses.patch | 229 +++++++++++++++++++++++++++++++++++++ python-astunparse.changes | 72 ++++++++++++ python-astunparse.spec | 80 +++++++++++++ 8 files changed, 505 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 astunparse-1.6.3.tar.gz create mode 100644 astunparse-pr57-py39.patch create mode 100644 fix-formatted-value.patch create mode 100644 parentheses.patch create mode 100644 python-astunparse.changes create mode 100644 python-astunparse.spec diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..9b03811 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,23 @@ +## Default LFS +*.7z filter=lfs diff=lfs merge=lfs -text +*.bsp filter=lfs diff=lfs merge=lfs -text +*.bz2 filter=lfs diff=lfs merge=lfs -text +*.gem filter=lfs diff=lfs merge=lfs -text +*.gz filter=lfs diff=lfs merge=lfs -text +*.jar filter=lfs diff=lfs merge=lfs -text +*.lz filter=lfs diff=lfs merge=lfs -text +*.lzma filter=lfs diff=lfs merge=lfs -text +*.obscpio filter=lfs diff=lfs merge=lfs -text +*.oxt filter=lfs diff=lfs merge=lfs -text +*.pdf filter=lfs diff=lfs merge=lfs -text +*.png filter=lfs diff=lfs merge=lfs -text +*.rpm filter=lfs diff=lfs merge=lfs -text +*.tbz filter=lfs diff=lfs merge=lfs -text +*.tbz2 filter=lfs diff=lfs merge=lfs -text +*.tgz filter=lfs diff=lfs merge=lfs -text +*.ttf filter=lfs diff=lfs merge=lfs -text +*.txz filter=lfs diff=lfs merge=lfs -text +*.whl filter=lfs diff=lfs merge=lfs -text +*.xz filter=lfs diff=lfs merge=lfs -text +*.zip filter=lfs diff=lfs merge=lfs -text +*.zst filter=lfs diff=lfs merge=lfs -text diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..57affb6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.osc diff --git a/astunparse-1.6.3.tar.gz b/astunparse-1.6.3.tar.gz new file mode 100644 index 0000000..e676dd1 --- /dev/null +++ b/astunparse-1.6.3.tar.gz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5ad93a8456f0d084c3456d059fd9a92cce667963232cbf763eac3bc5b7940872 +size 18290 diff --git a/astunparse-pr57-py39.patch b/astunparse-pr57-py39.patch new file mode 100644 index 0000000..1e46001 --- /dev/null +++ b/astunparse-pr57-py39.patch @@ -0,0 +1,74 @@ +From 0388a0d2f42401dcedf7f89d3c291cfed3e4a3d5 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= +Date: Wed, 8 Jul 2020 20:15:57 +0200 +Subject: [PATCH 1/2] Adapt dump() behavior to match ast.dump() on Python 3.9+ + +In Python 3.9+, ast.dump() omits optional fields/attributes from the output if +their value is None. Such defaults are defined as class attributes. + +See https://bugs.python.org/issue36287 +And https://github.com/python/cpython/pull/18843 + +This patch does not change the output on previous Python versions, +because the class attributes are missing there. + +Fixes https://github.com/simonpercivall/astunparse/issues/56 +--- + lib/astunparse/printer.py | 7 ++++++- + 1 file changed, 6 insertions(+), 1 deletion(-) + +diff --git a/lib/astunparse/printer.py b/lib/astunparse/printer.py +index 92d64f7..7a33deb 100644 +--- a/lib/astunparse/printer.py ++++ b/lib/astunparse/printer.py +@@ -4,6 +4,9 @@ + import six + + ++_NOPE = object() ++ ++ + class Printer(ast.NodeVisitor): + + def __init__(self, file=sys.stdout, indent=" "): +@@ -19,6 +22,7 @@ def write(self, text): + self.f.write(six.text_type(text)) + + def generic_visit(self, node): ++ cls = type(node) + + if isinstance(node, list): + nodestart = "[" +@@ -27,7 +31,8 @@ def generic_visit(self, node): + else: + nodestart = type(node).__name__ + "(" + nodeend = ")" +- children = [(name + "=", value) for name, value in ast.iter_fields(node)] ++ children = [(name + "=", value) for name, value in ast.iter_fields(node) ++ if not (value is None and getattr(cls, name, _NOPE) is None)] + + if len(children) > 1: + self.indentation += 1 + +From ea2b578a1b653e73696db2392b8e3d5bf75dadc7 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= +Date: Wed, 8 Jul 2020 20:21:17 +0200 +Subject: [PATCH 2/2] Test and support Python 3.9 + +--- + setup.py | 1 + + (tox.ini | 2 +-) removed from openSUSE patch for PyPI package + 2 files changed, 2 insertions(+), 1 deletion(-) + +diff --git a/setup.py b/setup.py +index e5a277a..29b384b 100755 +--- a/setup.py ++++ b/setup.py +@@ -52,6 +52,7 @@ def read_version(): + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', ++ 'Programming Language :: Python :: 3.9', + 'Topic :: Software Development :: Code Generators', + ], + test_suite='tests', diff --git a/fix-formatted-value.patch b/fix-formatted-value.patch new file mode 100644 index 0000000..950b353 --- /dev/null +++ b/fix-formatted-value.patch @@ -0,0 +1,23 @@ +From 3c661cb35b62268a553dd548a73178b5d7f708c7 Mon Sep 17 00:00:00 2001 +From: Vincent Hellendoorn +Date: Tue, 29 Sep 2020 14:11:11 -0400 +Subject: [PATCH] Use correct write call for FormattedValue + +The unparser for formatted values incorrectly referred to `_fstring_JoinedStr`, which expects a `values` property that `FormattedValue`s don't have. This PR updates to the correct call. +--- + lib/astunparse/unparser.py | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/lib/astunparse/unparser.py b/lib/astunparse/unparser.py +index 0ef6fd8..7e8c1ca 100644 +--- a/lib/astunparse/unparser.py ++++ b/lib/astunparse/unparser.py +@@ -482,7 +482,7 @@ def _FormattedValue(self, t): + # FormattedValue(expr value, int? conversion, expr? format_spec) + self.write("f") + string = StringIO() +- self._fstring_JoinedStr(t, string.write) ++ self._fstring_FormattedValue(t, string.write) + self.write(repr(string.getvalue())) + + def _fstring_JoinedStr(self, t, write): diff --git a/parentheses.patch b/parentheses.patch new file mode 100644 index 0000000..289b273 --- /dev/null +++ b/parentheses.patch @@ -0,0 +1,229 @@ +From 8f3af04c64c39b13f65c58a14f09433661d63a79 Mon Sep 17 00:00:00 2001 +From: eff-kay +Date: Fri, 18 Aug 2023 19:39:00 -0400 +Subject: [PATCH] fix extra parenthsis addition + +--- + lib/astunparse/unparser.py | 66 +++++++++++++++++++++++++++----------- + test_requirements.txt | 2 ++ + tests/common.py | 3 +- + tests/test_dump.py | 22 ++++++------- + tests/test_unparse.py | 14 +++++++- + tox.ini | 2 +- + 6 files changed, 76 insertions(+), 33 deletions(-) + +Index: astunparse-1.6.3/lib/astunparse/unparser.py +=================================================================== +--- astunparse-1.6.3.orig/lib/astunparse/unparser.py ++++ astunparse-1.6.3/lib/astunparse/unparser.py +@@ -56,14 +56,17 @@ class Unparser: + "Decrease the indentation level." + self._indent -= 1 + +- def dispatch(self, tree): ++ def dispatch(self, tree, parent_t=None): + "Dispatcher function, dispatching tree type T to method _T." + if isinstance(tree, list): + for t in tree: + self.dispatch(t) + return + meth = getattr(self, "_"+tree.__class__.__name__) +- meth(tree) ++ if parent_t: ++ meth(tree, parent_t=parent_t) ++ else: ++ meth(tree) + + + ############### Unparsing methods ###################### +@@ -517,7 +520,8 @@ class Unparser: + meth(t.format_spec, write) + write("}") + +- def _Name(self, t): ++ def _Name(self, t, parent_t=None): ++ + self.write(t.id) + + def _NameConstant(self, t): +@@ -535,7 +539,7 @@ class Unparser: + else: + self.write(repr(value)) + +- def _Constant(self, t): ++ def _Constant(self, t, parent_t=None): + value = t.value + if isinstance(value, tuple): + self.write("(") +@@ -659,8 +663,12 @@ class Unparser: + self.write(")") + + unop = {"Invert":"~", "Not": "not", "UAdd":"+", "USub":"-"} +- def _UnaryOp(self, t): +- self.write("(") ++ def _UnaryOp(self, t, parent_t=None): ++ if isinstance(parent_t, ast.Call): ++ pass ++ else: ++ self.write("(") ++ + self.write(self.unop[t.op.__class__.__name__]) + self.write(" ") + if six.PY2 and isinstance(t.op, ast.USub) and isinstance(t.operand, ast.Num): +@@ -674,34 +682,57 @@ class Unparser: + self.write(")") + else: + self.dispatch(t.operand) +- self.write(")") ++ ++ if isinstance(parent_t, ast.Call): ++ pass ++ else: ++ self.write(")") + + binop = { "Add":"+", "Sub":"-", "Mult":"*", "MatMult":"@", "Div":"/", "Mod":"%", + "LShift":"<<", "RShift":">>", "BitOr":"|", "BitXor":"^", "BitAnd":"&", + "FloorDiv":"//", "Pow": "**"} +- def _BinOp(self, t): +- self.write("(") ++ def _BinOp(self, t, parent_t=None): ++ if isinstance(parent_t, ast.Call): ++ pass ++ else: ++ self.write("(") + self.dispatch(t.left) + self.write(" " + self.binop[t.op.__class__.__name__] + " ") + self.dispatch(t.right) +- self.write(")") ++ if isinstance(parent_t, ast.Call): ++ pass ++ else: ++ self.write(")") + + cmpops = {"Eq":"==", "NotEq":"!=", "Lt":"<", "LtE":"<=", "Gt":">", "GtE":">=", + "Is":"is", "IsNot":"is not", "In":"in", "NotIn":"not in"} +- def _Compare(self, t): +- self.write("(") ++ def _Compare(self, t, parent_t=None): ++ if isinstance(parent_t, ast.Call): ++ pass ++ else: ++ self.write("(") + self.dispatch(t.left) + for o, e in zip(t.ops, t.comparators): + self.write(" " + self.cmpops[o.__class__.__name__] + " ") + self.dispatch(e) +- self.write(")") ++ if isinstance(parent_t, ast.Call): ++ pass ++ else: ++ self.write(")") + + boolops = {ast.And: 'and', ast.Or: 'or'} +- def _BoolOp(self, t): +- self.write("(") ++ def _BoolOp(self, t, parent_t=None): ++ if isinstance(parent_t, ast.Call): ++ pass ++ else: ++ self.write("(") ++ + s = " %s " % self.boolops[t.op.__class__] + interleave(lambda: self.write(s), self.dispatch, t.values) +- self.write(")") ++ if isinstance(parent_t, ast.Call): ++ pass ++ else: ++ self.write(")") + + def _Attribute(self,t): + self.dispatch(t.value) +@@ -720,22 +751,22 @@ class Unparser: + for e in t.args: + if comma: self.write(", ") + else: comma = True +- self.dispatch(e) ++ self.dispatch(e, parent_t=t) + for e in t.keywords: + if comma: self.write(", ") + else: comma = True +- self.dispatch(e) ++ self.dispatch(e, parent_t=t) + if sys.version_info[:2] < (3, 5): + if t.starargs: + if comma: self.write(", ") + else: comma = True + self.write("*") +- self.dispatch(t.starargs) ++ self.dispatch(t.starargs, parent_t=t) + if t.kwargs: + if comma: self.write(", ") + else: comma = True + self.write("**") +- self.dispatch(t.kwargs) ++ self.dispatch(t.kwargs, parent_t=t) + self.write(")") + + def _Subscript(self, t): +Index: astunparse-1.6.3/test_requirements.txt +=================================================================== +--- astunparse-1.6.3.orig/test_requirements.txt ++++ astunparse-1.6.3/test_requirements.txt +@@ -1,2 +1,4 @@ + coverage == 3.7.1 ++flake8 ++tox + -rrequirements.txt +Index: astunparse-1.6.3/tests/common.py +=================================================================== +--- astunparse-1.6.3.orig/tests/common.py ++++ astunparse-1.6.3/tests/common.py +@@ -262,7 +262,6 @@ class AstunparseCommonTestCase: + self.check_roundtrip("a is b is c is not d") + + def test_function_arguments(self): +- self.check_roundtrip("def f(): pass") + self.check_roundtrip("def f(a): pass") + self.check_roundtrip("def f(b = 2): pass") + self.check_roundtrip("def f(a, b): pass") +@@ -394,7 +393,7 @@ class AstunparseCommonTestCase: + self.check_roundtrip("a: int = None") + self.check_roundtrip("some_list: List[int]") + self.check_roundtrip("some_list: List[int] = []") +- self.check_roundtrip("t: Tuple[int, ...] = (1, 2, 3)") ++ self.check_roundtrip("t: Tuple[(int, ...)] = (1, 2, 3)") + self.check_roundtrip("(a): int") + self.check_roundtrip("(a): int = 0") + self.check_roundtrip("(a): int = None") +Index: astunparse-1.6.3/tests/test_dump.py +=================================================================== +--- astunparse-1.6.3.orig/tests/test_dump.py ++++ astunparse-1.6.3/tests/test_dump.py +@@ -9,16 +9,16 @@ else: + import astunparse + from tests.common import AstunparseCommonTestCase + +-class DumpTestCase(AstunparseCommonTestCase, unittest.TestCase): ++# class DumpTestCase(AstunparseCommonTestCase, unittest.TestCase): + +- def assertASTEqual(self, dump1, dump2): +- # undo the pretty-printing +- dump1 = re.sub(r"(?<=[\(\[])\n\s+", "", dump1) +- dump1 = re.sub(r"\n\s+", " ", dump1) +- self.assertEqual(dump1, dump2) ++# def assertASTEqual(self, dump1, dump2): ++# # undo the pretty-printing ++# dump1 = re.sub(r"(?<=[\(\[])\n\s+", "", dump1) ++# dump1 = re.sub(r"\n\s+", " ", dump1) ++# self.assertEqual(dump1, dump2) + +- def check_roundtrip(self, code1, filename="internal", mode="exec"): +- ast_ = compile(str(code1), filename, mode, ast.PyCF_ONLY_AST) +- dump1 = astunparse.dump(ast_) +- dump2 = ast.dump(ast_) +- self.assertASTEqual(dump1, dump2) ++# def check_roundtrip(self, code1, filename="internal", mode="exec"): ++# ast_ = compile(str(code1), filename, mode, ast.PyCF_ONLY_AST) ++# dump1 = astunparse.dump(ast_) ++# dump2 = ast.dump(ast_) ++# self.assertASTEqual(dump1, dump2) diff --git a/python-astunparse.changes b/python-astunparse.changes new file mode 100644 index 0000000..a919388 --- /dev/null +++ b/python-astunparse.changes @@ -0,0 +1,72 @@ +------------------------------------------------------------------- +Mon Dec 2 15:15:22 UTC 2024 - Markéta Machová + +- Add patch parentheses.patch to fix tests on Python 3.13 + +------------------------------------------------------------------- +Thu Nov 21 10:08:41 UTC 2024 - Dirk Müller + +- skip for python 3.13 + +------------------------------------------------------------------- +Fri Oct 20 19:42:26 UTC 2023 - Matej Cepl + +- Clean up the SPEC file + +------------------------------------------------------------------- +Fri Apr 21 12:22:15 UTC 2023 - Dirk Müller + +- add sle15_python_module_pythons (jsc#PED-68) + +------------------------------------------------------------------- +Thu Apr 13 22:40:05 UTC 2023 - Matej Cepl + +- Make calling of %{sle15modernpython} optional. + +------------------------------------------------------------------- +Fri Feb 17 10:59:59 UTC 2023 - Dirk Müller + +- need to turn off noarch to be able to skip tests on 32bit arches + +------------------------------------------------------------------- +Thu Feb 16 22:39:53 UTC 2023 - Dirk Müller + +- add fix-formatted-value.patch +- skip tests on 32bit platforms + +------------------------------------------------------------------- +Fri Sep 10 05:23:39 UTC 2021 - pgajdos@suse.com + +- %check: use %pyunittest rpm macro + +------------------------------------------------------------------- +Sun Apr 18 12:03:07 UTC 2021 - Ben Greiner + +- Add astunparse-pr57-py39.patch by Fedora maintainer for Python + 3.9 support -- gh#simonpercivall/astunparse#57 + +------------------------------------------------------------------- +Fri Jan 17 15:36:43 UTC 2020 - Marketa Calabkova + +- update to 1.6.3 + * Add full support for Python 3.8 + +------------------------------------------------------------------- +Wed Mar 6 12:29:21 UTC 2019 - Tomáš Chvátal + +- Update to 1.6.2: + * Python 3.7 compatibility + * Fix the roundtripping of very complex f-strings. + * Add support for the Constant node in Python 3.8 + * Add tests to the sdist +- Execute tests + +------------------------------------------------------------------- +Tue Dec 4 12:45:45 UTC 2018 - Matej Cepl + +- Remove superfluous devel dependency for noarch package + +------------------------------------------------------------------- +Fri Aug 3 03:33:04 UTC 2018 - toddrme2178@gmail.com + +- Initial version diff --git a/python-astunparse.spec b/python-astunparse.spec new file mode 100644 index 0000000..18eca0c --- /dev/null +++ b/python-astunparse.spec @@ -0,0 +1,80 @@ +# +# spec file for package python-astunparse +# +# Copyright (c) 2024 SUSE LLC +# +# All modifications and additions to the file contributed by third parties +# remain the property of their copyright owners, unless otherwise agreed +# upon. The license for this file, and modifications and additions to the +# file, is the same license as for the pristine package itself (unless the +# license for the pristine package is not an Open Source License, in which +# case the license is the MIT License). An "Open Source License" is a +# license that conforms to the Open Source Definition (Version 1.9) +# published by the Open Source Initiative. + +# Please submit bugfixes or comments via https://bugs.opensuse.org/ +# + + +%{?sle15_python_module_pythons} +Name: python-astunparse +Version: 1.6.3 +Release: 0 +Summary: An AST unparser for Python +License: BSD-3-Clause AND Python-2.0 +Group: Development/Languages/Python +URL: https://github.com/simonpercivall/astunparse +Source: https://files.pythonhosted.org/packages/source/a/astunparse/astunparse-%{version}.tar.gz +# PATCH-FIX-UPSTREAM astunparse-pr57-py39.patch -- gh#simonpercivall/astunparse#57 +Patch0: astunparse-pr57-py39.patch +# https://github.com/simonpercivall/astunparse/pull/59 +Patch1: fix-formatted-value.patch +# https://github.com/simonpercivall/astunparse/pull/70 +# it is a bit overpowered, but it fixes the issue +Patch2: parentheses.patch +BuildRequires: %{python_module pip} +BuildRequires: %{python_module setuptools} +BuildRequires: %{python_module six >= 1.6.1} +BuildRequires: %{python_module wheel >= 0.23.0} +BuildRequires: fdupes +BuildRequires: python-rpm-macros +Requires: python-six >= 1.6.1 +Requires: python-wheel >= 0.23.0 +%python_subpackages + +%description +This is a factored out version of ``unparse`` found in the Python +source distribution; under Demo/parser in Python 2 and under +Tools/parser in Python 3. + +This library is single-source compatible with Python 2.6 through +Python 3.5. It is authored by the Python core developers; I have +simply merged the Python 2.7 and the Python 3.5 source and test +suites, and added a wrapper. This factoring out is to provide a +library implementation that supports both versions. + +Added to this is a pretty-printing dump utility function. + +%prep +%autosetup -p1 -n astunparse-%{version} + +%build +%pyproject_wheel + +%install +%pyproject_install +%python_expand %fdupes %{buildroot}%{$python_sitelib} + +# fails to parse the 32bit stdlib +%if "%{_lib}" == "lib64" +%check +%pyunittest discover -v +%endif + +%files %{python_files} +%doc AUTHORS.rst README.rst HISTORY.rst +%license LICENSE +%{python_sitelib}/astunparse +%{python_sitelib}/astunparse-%{version}*-info + +%changelog