mirror of
https://gitlab.alpinelinux.org/alpine/aports.git
synced 2026-03-29 01:12:16 +01:00
Update ast types for python 3.14 to fix error: `ImportError: cannot import name 'Str' from 'ast' (/usr/lib/python3.14/ast.py)` Ref: https://gitlab.alpinelinux.org/alpine/aports/-/issues/18025
127 lines
5.0 KiB
Diff
127 lines
5.0 KiB
Diff
Ref: https://sourceforge.net/p/ruamel-yaml-clib/code/ci/dd6339faf0f6bb1b5ac99c92fd3d0b8b25412c72/
|
|
Adapted for ruamel.std.pathlib 0.12.0.
|
|
---
|
|
diff -rupN a/setup.py b/setup.py
|
|
--- a/setup.py 2023-02-06 09:33:09.000000000 +0000
|
|
+++ b/setup.py 2026-03-23 03:06:48.490000000 +0000
|
|
@@ -13,7 +13,7 @@ import traceback
|
|
|
|
sys.path = [path for path in sys.path if path not in [os.getcwd(), ""]]
|
|
import platform # NOQA
|
|
-from _ast import * # NOQA
|
|
+import _ast as Ast # NOQA
|
|
from ast import parse # NOQA
|
|
|
|
from setuptools import setup, Extension, Distribution # NOQA
|
|
@@ -37,11 +37,6 @@ if __name__ != '__main__':
|
|
|
|
full_package_name = None
|
|
|
|
-if sys.version_info < (3,):
|
|
- string_type = basestring
|
|
-else:
|
|
- string_type = str
|
|
-
|
|
|
|
if sys.version_info < (3, 4):
|
|
|
|
@@ -80,10 +75,6 @@ else:
|
|
print(*args, **kw1)
|
|
|
|
|
|
-if sys.version_info >= (3, 8):
|
|
- from ast import Str, Num, Bytes, NameConstant # NOQA
|
|
-
|
|
-
|
|
def literal_eval(node_or_string):
|
|
"""
|
|
Safely evaluate an expression node or a string containing a Python
|
|
@@ -94,59 +85,47 @@ def literal_eval(node_or_string):
|
|
Even when passing in Unicode, the resulting Str types parsed are 'str' in Python 2.
|
|
I don't now how to set 'unicode_literals' on parse -> Str is explicitly converted.
|
|
"""
|
|
- _safe_names = {'None': None, 'True': True, 'False': False}
|
|
- if isinstance(node_or_string, string_type):
|
|
+ if isinstance(node_or_string, str):
|
|
node_or_string = parse(node_or_string, mode='eval')
|
|
- if isinstance(node_or_string, Expression):
|
|
+ if isinstance(node_or_string, Ast.Expression):
|
|
node_or_string = node_or_string.body
|
|
else:
|
|
raise TypeError('only string or AST nodes supported')
|
|
|
|
def _convert(node):
|
|
- if isinstance(node, Str):
|
|
- if sys.version_info < (3,) and not isinstance(node.s, unicode):
|
|
- return node.s.decode('utf-8')
|
|
- return node.s
|
|
- elif isinstance(node, Bytes):
|
|
- return node.s
|
|
- elif isinstance(node, Num):
|
|
- return node.n
|
|
- elif isinstance(node, Tuple):
|
|
+ if isinstance(node, Ast.Constant):
|
|
+ return node.value
|
|
+ elif isinstance(node, Ast.Tuple):
|
|
return tuple(map(_convert, node.elts))
|
|
- elif isinstance(node, List):
|
|
+ elif isinstance(node, Ast.List):
|
|
return list(map(_convert, node.elts))
|
|
- elif isinstance(node, Set):
|
|
+ elif isinstance(node, Ast.Set):
|
|
return set(map(_convert, node.elts))
|
|
- elif isinstance(node, Dict):
|
|
- return dict((_convert(k), _convert(v)) for k, v in zip(node.keys, node.values))
|
|
- elif isinstance(node, NameConstant):
|
|
- return node.value
|
|
- elif sys.version_info < (3, 4) and isinstance(node, Name):
|
|
- if node.id in _safe_names:
|
|
- return _safe_names[node.id]
|
|
+ elif isinstance(node, Ast.Dict):
|
|
+ return {_convert(k): _convert(v) for k, v in zip(node.keys, node.values)}
|
|
elif (
|
|
- isinstance(node, UnaryOp)
|
|
- and isinstance(node.op, (UAdd, USub))
|
|
- and isinstance(node.operand, (Num, UnaryOp, BinOp))
|
|
+ isinstance(node, Ast.UnaryOp)
|
|
+ and isinstance(node.op, (Ast.UAdd, Ast.USub))
|
|
+ and isinstance(node.operand, (Ast.Num, Ast.UnaryOp, Ast.BinOp))
|
|
): # NOQA
|
|
operand = _convert(node.operand)
|
|
- if isinstance(node.op, UAdd):
|
|
+ if isinstance(node.op, Ast.UAdd):
|
|
return +operand
|
|
else:
|
|
return -operand
|
|
elif (
|
|
- isinstance(node, BinOp)
|
|
- and isinstance(node.op, (Add, Sub))
|
|
- and isinstance(node.right, (Num, UnaryOp, BinOp))
|
|
- and isinstance(node.left, (Num, UnaryOp, BinOp))
|
|
+ isinstance(node, Ast.BinOp)
|
|
+ and isinstance(node.op, (Ast.Add, Ast.Sub))
|
|
+ and isinstance(node.right, (Ast.Num, Ast.UnaryOp, Ast.BinOp))
|
|
+ and isinstance(node.left, (Ast.Num, Ast.UnaryOp, Ast.BinOp))
|
|
): # NOQA
|
|
left = _convert(node.left)
|
|
right = _convert(node.right)
|
|
- if isinstance(node.op, Add):
|
|
+ if isinstance(node.op, Ast.Add):
|
|
return left + right
|
|
else:
|
|
return left - right
|
|
- elif isinstance(node, Call):
|
|
+ elif isinstance(node, Ast.Call):
|
|
func_id = getattr(node.func, 'id', None)
|
|
if func_id == 'dict':
|
|
return dict((k.arg, _convert(k.value)) for k in node.keywords)
|
|
@@ -646,7 +625,7 @@ class NameSpacePackager(object):
|
|
return self._pkg
|
|
# 'any' for all builds, 'py27' etc for specifics versions
|
|
packages = ir.get('any', [])
|
|
- if isinstance(packages, string_type):
|
|
+ if isinstance(packages, str):
|
|
packages = packages.split() # assume white space separated string
|
|
if self.nested:
|
|
# parent dir is also a package, make sure it is installed (need its .pth file)
|