SHA256
1
0
forked from pool/python-astor

18 Commits

Author SHA256 Message Date
fd98c32d27 Accepting request 1303552 from devel:languages:python
OBS-URL: https://build.opensuse.org/request/show/1303552
OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/python-astor?expand=0&rev=17
2025-09-11 12:38:06 +00:00
86f4ad2f32 - Add py314.patch to support Python 3.14
OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-astor?expand=0&rev=37
2025-09-10 09:01:25 +00:00
330dd3b35f Accepting request 1285331 from devel:languages:python
- Switch to pyproject macros.
- Add patches, to support Python 3.12+:
  * lower-huge-int.patch
  * support-match.patch

OBS-URL: https://build.opensuse.org/request/show/1285331
OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/python-astor?expand=0&rev=16
2025-06-13 16:43:33 +00:00
5446354dc8 - Switch to pyproject macros.
- Add patches, to support Python 3.12+:
  * lower-huge-int.patch
  * support-match.patch

OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-astor?expand=0&rev=35
2025-06-13 05:41:53 +00:00
3df5f0a5c2 Accepting request 1185383 from devel:languages:python
- Skip same tests for python-3.13

OBS-URL: https://build.opensuse.org/request/show/1185383
OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/python-astor?expand=0&rev=15
2024-07-05 17:45:09 +00:00
ccbf3a1ba8 Accepting request 1114089 from devel:languages:python
- Skip same tests for python-3.12

OBS-URL: https://build.opensuse.org/request/show/1114089
OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/python-astor?expand=0&rev=14
2023-09-29 19:12:52 +00:00
827c82083b Accepting request 1082003 from devel:languages:python
OBS-URL: https://build.opensuse.org/request/show/1082003
OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/python-astor?expand=0&rev=13
2023-04-22 20:02:07 +00:00
03cc243883 Accepting request 1057599 from devel:languages:python
- Skip same tests for python-3.11

OBS-URL: https://build.opensuse.org/request/show/1057599
OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/python-astor?expand=0&rev=12
2023-01-11 13:33:38 +00:00
bfcdb3a45f Accepting request 1002922 from devel:languages:python
- Skip test_huge_int due to new security feature in Python
  * https://github.com/python/cpython/issues/95778

OBS-URL: https://build.opensuse.org/request/show/1002922
OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/python-astor?expand=0&rev=11
2022-09-17 18:08:12 +00:00
98d10e69d8 Accepting request 941565 from devel:languages:python
OBS-URL: https://build.opensuse.org/request/show/941565
OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/python-astor?expand=0&rev=10
2021-12-25 19:16:30 +00:00
d9449d2dfd Accepting request 880498 from devel:languages:python
OBS-URL: https://build.opensuse.org/request/show/880498
OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/python-astor?expand=0&rev=9
2021-03-24 15:10:38 +00:00
99278576a6 Accepting request 810588 from devel:languages:python
- Remove patch remove_unittest2.patch as we use pytest to load
  stuff it is no longer really needed

- for python3, drop dependency on unittest2
- added patches
  + remove_unittest2.patch

OBS-URL: https://build.opensuse.org/request/show/810588
OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/python-astor?expand=0&rev=8
2020-06-02 12:39:40 +00:00
96c68aa34a Accepting request 791387 from devel:languages:python
OBS-URL: https://build.opensuse.org/request/show/791387
OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/python-astor?expand=0&rev=7
2020-04-05 18:53:41 +00:00
d83175a8c5 Accepting request 788380 from devel:languages:python
OBS-URL: https://build.opensuse.org/request/show/788380
OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/python-astor?expand=0&rev=6
2020-03-26 22:33:20 +00:00
c17169c4f1 Accepting request 765352 from devel:languages:python
OBS-URL: https://build.opensuse.org/request/show/765352
OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/python-astor?expand=0&rev=5
2020-01-18 11:18:22 +00:00
11f766e538 Accepting request 750111 from devel:languages:python
Automatic submission by obs-autosubmit

OBS-URL: https://build.opensuse.org/request/show/750111
OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/python-astor?expand=0&rev=4
2019-11-22 09:27:20 +00:00
539101c711 Accepting request 729897 from devel:languages:python
- Add patch to build with py 3.8:
  * python38.patch

OBS-URL: https://build.opensuse.org/request/show/729897
OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/python-astor?expand=0&rev=3
2019-09-11 08:39:58 +00:00
2ba24f4ffc Accepting request 707079 from devel:languages:python
OBS-URL: https://build.opensuse.org/request/show/707079
OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/python-astor?expand=0&rev=2
2019-06-03 16:56:38 +00:00
5 changed files with 189 additions and 17 deletions

25
lower-huge-int.patch Normal file
View File

@@ -0,0 +1,25 @@
From 8342d6aa5dcdcf20f89a19057527510c245c7a2e Mon Sep 17 00:00:00 2001
From: Jochen Sprickerhof <jspricke@debian.org>
Date: Fri, 30 Dec 2022 14:47:57 +0100
Subject: [PATCH] Reduce huge int in test (Closes: #212)
Int was above limits:
https://docs.python.org/3/library/stdtypes.html#int-max-str-digits
---
tests/test_code_gen.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/test_code_gen.py b/tests/test_code_gen.py
index 0d01be7..6cc0f4c 100644
--- a/tests/test_code_gen.py
+++ b/tests/test_code_gen.py
@@ -291,7 +291,7 @@ def test_with(self):
self.assertAstRoundtripsGtVer(source, (2, 7))
def test_huge_int(self):
- for n in (10**10000,
+ for n in (10**1000,
0xdfa21cd2a530ccc8c870aa60d9feb3b35deeab81c3215a96557abbd683d21f4600f38e475d87100da9a4404220eeb3bb5584e5a2b5b48ffda58530ea19104a32577d7459d91e76aa711b241050f4cc6d5327ccee254f371bcad3be56d46eb5919b73f20dbdb1177b700f00891c5bf4ed128bb90ed541b778288285bcfa28432ab5cbcb8321b6e24760e998e0daa519f093a631e44276d7dd252ce0c08c75e2ab28a7349ead779f97d0f20a6d413bf3623cd216dc35375f6366690bcc41e3b2d5465840ec7ee0dc7e3f1c101d674a0c7dbccbc3942788b111396add2f8153b46a0e4b50d66e57ee92958f1c860dd97cc0e40e32febff915343ed53573142bdf4b):
self.assertEqual(astornum(n), n)

99
py314.patch Normal file
View File

@@ -0,0 +1,99 @@
From d0b5563cc1e263f08df9312d89a7691167448f4d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgorny@gentoo.org>
Date: Wed, 14 May 2025 19:52:30 +0200
Subject: [PATCH] Fix compatibility with Python 3.14 (mostly)
Fix the code and the test suite to work with Python 3.14, where
deprecated constant-like AST nodes were removed. Notably:
1. Skip tests for deprecated nodes in Python 3.14.
2. Use `ast.Constant` over `ast.Num` for non-deprecated code
in Python 3.6+.
3. Check for `ast.Str` only in Python < 3.14, and handle `ast.Constant`
being used to represent a string instead.
With these changes, all tests except for:
tests/test_rtrip.py::RtripTestCase::test_convert_stdlib
pass. However, this particular test also hanged for me with older Python
versions.
Related to #217
---
astor/code_gen.py | 9 +++++++--
tests/test_code_gen.py | 11 ++++++++---
2 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/astor/code_gen.py b/astor/code_gen.py
index b2bae12..4330f49 100644
--- a/astor/code_gen.py
+++ b/astor/code_gen.py
@@ -692,6 +692,7 @@ def _handle_string_constant(self, node, value, is_joined=False):
current_line = ''.join(current_line)
has_ast_constant = sys.version_info >= (3, 6)
+ has_ast_str = sys.version_info < (3, 14)
if is_joined:
# Handle new f-strings. This is a bit complicated, because
@@ -700,7 +701,7 @@ def _handle_string_constant(self, node, value, is_joined=False):
def recurse(node):
for value in node.values:
- if isinstance(value, ast.Str):
+ if has_ast_str and isinstance(value, ast.Str):
# Double up braces to escape them.
self.write(value.s.replace('{', '{{').replace('}', '}}'))
elif isinstance(value, ast.FormattedValue):
@@ -713,7 +714,11 @@ def recurse(node):
self.write(':')
recurse(value.format_spec)
elif has_ast_constant and isinstance(value, ast.Constant):
- self.write(value.value)
+ if isinstance(value.value, str):
+ # Double up braces to escape them.
+ self.write(value.value.replace('{', '{{').replace('}', '}}'))
+ else:
+ self.write(value.value)
else:
kind = type(value).__name__
assert False, 'Invalid node %s inside JoinedStr' % kind
diff --git a/tests/test_code_gen.py b/tests/test_code_gen.py
index e828eb9..1825030 100644
--- a/tests/test_code_gen.py
+++ b/tests/test_code_gen.py
@@ -28,7 +28,10 @@ def astorexpr(x):
return eval(astor.to_source(ast.Expression(body=x)))
def astornum(x):
- return astorexpr(ast.Num(n=x))
+ if sys.version_info >= (3, 6):
+ return astorexpr(ast.Constant(x))
+ else:
+ return astorexpr(ast.Num(n=x))
class Comparisons(object):
@@ -515,8 +518,8 @@ def test_deprecated_constants_as_name(self):
ast.Assign(targets=[ast.Name(id='spam')], value=ast.Name(id='None')),
"spam = None")
- @unittest.skipUnless(sys.version_info >= (3, 4),
- "ast.NameConstant introduced in Python 3.4")
+ @unittest.skipUnless((3, 4) <= sys.version_info < (3, 14),
+ "ast.NameConstant introduced in Python 3.4, removed in 3.14")
def test_deprecated_name_constants(self):
self.assertAstEqualsSource(
ast.Assign(targets=[ast.Name(id='spam')], value=ast.NameConstant(value=True)),
@@ -530,6 +533,8 @@ def test_deprecated_name_constants(self):
ast.Assign(targets=[ast.Name(id='spam')], value=ast.NameConstant(value=None)),
"spam = None")
+ @unittest.skipIf(sys.version_info >= (3, 14),
+ "Deprecated Constant nodes removed in Python 3.14")
def test_deprecated_constant_nodes(self):
self.assertAstEqualsSource(
ast.Assign(targets=[ast.Name(id='spam')], value=ast.Num(3)),

View File

@@ -1,3 +1,16 @@
-------------------------------------------------------------------
Mon Sep 8 12:44:02 UTC 2025 - Markéta Machová <mmachova@suse.com>
- Add py314.patch to support Python 3.14
-------------------------------------------------------------------
Fri Jun 13 05:37:21 UTC 2025 - Steve Kowalik <steven.kowalik@suse.com>
- Switch to pyproject macros.
- Add patches, to support Python 3.12+:
* lower-huge-int.patch
* support-match.patch
-------------------------------------------------------------------
Thu Jul 4 12:06:42 UTC 2024 - Daniel Garcia <daniel.garcia@suse.com>

View File

@@ -1,7 +1,7 @@
#
# spec file for package python-astor
#
# Copyright (c) 2024 SUSE LLC
# Copyright (c) 2025 SUSE LLC and contributors
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
@@ -23,21 +23,23 @@ Version: 0.8.1
Release: 0
Summary: Read/rewrite/write Python ASTs
License: BSD-3-Clause
Group: Development/Languages/Python
URL: https://github.com/berkerpeksag/astor
Source: https://github.com/berkerpeksag/astor/archive/%{version}.tar.gz#/astor-%{version}.tar.gz
# https://github.com/berkerpeksag/astor/pull/177
Patch0: remove_nose.patch
# https://github.com/berkerpeksag/astor/commit/8342d6aa5dcdcf20f89a19057527510c245c7a2e
Patch1: lower-huge-int.patch
Patch2: support-match.patch
# PATCH-FIX-UPSTREAM https://github.com/berkerpeksag/astor/pull/233 Fix compatibility with Python 3.14 (mostly)
Patch3: py314.patch
BuildRequires: %{python_module pip}
BuildRequires: %{python_module setuptools}
BuildRequires: %{python_module wheel}
BuildRequires: fdupes
BuildRequires: python-rpm-macros
BuildArch: noarch
# SECTION test requirements
BuildRequires: %{python_module pytest}
%if %{with python2}
# The tests use it internally, even when called from pytest-2
BuildRequires: python-unittest2
%endif
# /SECTION
%python_subpackages
@@ -72,29 +74,22 @@ There are some other similar libraries, but astor focuses on the following areas
# ugly fix for the use of /usr/bin/env
sed -i 's@#!.*@@' astor/rtrip.py
chmod a-x astor/rtrip.py
%python_build
%pyproject_wheel
%install
%python_install
%pyproject_install
%python_expand %fdupes %{buildroot}%{$python_sitelib}
# fix executeable bits
%python_expand chmod 755 %{buildroot}%{$python_sitelib}/astor/rtrip.py
%check
# https://github.com/berkerpeksag/astor/issues/212
python38_donttest="test_huge_int"
# https://github.com/berkerpeksag/astor/issues/196
python39_donttest="${python38_donttest} or test_convert_stdlib"
python310_donttest=${python39_donttest}
python311_donttest=${python310_donttest}
python312_donttest=${python311_donttest}
python313_donttest=${python312_donttest}
%pytest tests ${$python_donttest:+ -k "not (${$python_donttest})"}
%pytest tests -k "not test_convert_stdlib"
%files %{python_files}
%doc AUTHORS README.rst docs/*.rst
%license LICENSE
%{python_sitelib}/astor
%{python_sitelib}/astor-%{version}*-info
%{python_sitelib}/astor-%{version}.dist-info
%changelog

40
support-match.patch Normal file
View File

@@ -0,0 +1,40 @@
Index: astor-0.8.1/astor/code_gen.py
===================================================================
--- astor-0.8.1.orig/astor/code_gen.py
+++ astor-0.8.1/astor/code_gen.py
@@ -546,6 +546,35 @@ class SourceGenerator(ExplicitNodeVisito
def visit_Name(self, node):
self.write(node.id)
+ # ast.Match is new in Python 3.10
+ def visit_Match(self, node):
+ self.write(node.subject)
+ for c in node.cases:
+ self.write(c)
+
+ # ast.match_case is new in Python 3.10
+ def visit_match_case(self, node):
+ self.write(node.pattern)
+ self.write(node.guard)
+ self.write(node.body)
+
+ # ast.MatchSingleton is new in Python 3.10
+ def visit_MatchSingleton(self, node):
+ self.write(node.value)
+
+ # ast.MatchClass is new in Python 3.10
+ def visit_MatchClass(self, node):
+ self.write(node.cls)
+ for p in node.patterns:
+ self.write(p)
+ self.write(node.kwd_attrs)
+ self.write(node.kwd_patterns)
+
+ # ast.MatchAs is new in Python 3.10
+ def visit_MatchAs(self, node):
+ self.write(node.pattern)
+ self.write(node.name)
+
# ast.Constant is new in Python 3.6 and it replaces ast.Bytes,
# ast.Ellipsis, ast.NameConstant, ast.Num, ast.Str in Python 3.8
def visit_Constant(self, node):