Gentoo Archives: gentoo-commits

From: Patrick McLean <chutzpah@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: dev-python/astunparse/, dev-python/astunparse/files/
Date: Thu, 07 May 2020 00:16:42
Message-Id: 1588810583.7d989fd8c1cba17b9c913baacca013695eca9c37.chutzpah@gentoo
1 commit: 7d989fd8c1cba17b9c913baacca013695eca9c37
2 Author: Patrick McLean <patrick.mclean <AT> sony <DOT> com>
3 AuthorDate: Wed May 6 22:23:42 2020 +0000
4 Commit: Patrick McLean <chutzpah <AT> gentoo <DOT> org>
5 CommitDate: Thu May 7 00:16:23 2020 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=7d989fd8
7
8 dev-python/astunparse-1.6.2: enable tests, add py38
9
10 Copyright: Sony Interactive Entertainment Inc.
11 Package-Manager: Portage-2.3.99, Repoman-2.3.22
12 Signed-off-by: Patrick McLean <chutzpah <AT> gentoo.org>
13
14 dev-python/astunparse/astunparse-1.6.2.ebuild | 10 +-
15 .../astunparse/files/astunparse-1.6.2-py38.patch | 259 +++++++++++++++++++++
16 .../astunparse/files/astunparse-1.6.2-tests.patch | 23 ++
17 3 files changed, 291 insertions(+), 1 deletion(-)
18
19 diff --git a/dev-python/astunparse/astunparse-1.6.2.ebuild b/dev-python/astunparse/astunparse-1.6.2.ebuild
20 index 304fa3dd21c..824af0fdce1 100644
21 --- a/dev-python/astunparse/astunparse-1.6.2.ebuild
22 +++ b/dev-python/astunparse/astunparse-1.6.2.ebuild
23 @@ -3,7 +3,7 @@
24
25 EAPI=7
26
27 -PYTHON_COMPAT=( python3_6 python3_7 )
28 +PYTHON_COMPAT=( python3_{6,7,8} )
29 inherit distutils-r1
30
31 DESCRIPTION="Astun parser for python"
32 @@ -18,6 +18,14 @@ RDEPEND="
33 >=dev-python/six-1.6.1[${PYTHON_USEDEP}]
34 >=dev-python/wheel-0.23.0[${PYTHON_USEDEP}]
35 "
36 +PATCHES=(
37 + "${FILESDIR}/astunparse-1.6.2-tests.patch"
38 +
39 + # https://github.com/simonpercivall/astunparse/commit/2bd946919076f993cee1173611914372a0a25f00
40 + "${FILESDIR}/astunparse-1.6.2-py38.patch"
41 +)
42 +
43 +distutils_enable_tests setup.py
44
45 python_install_all() {
46 distutils-r1_python_install_all
47
48 diff --git a/dev-python/astunparse/files/astunparse-1.6.2-py38.patch b/dev-python/astunparse/files/astunparse-1.6.2-py38.patch
49 new file mode 100644
50 index 00000000000..aa27112393c
51 --- /dev/null
52 +++ b/dev-python/astunparse/files/astunparse-1.6.2-py38.patch
53 @@ -0,0 +1,259 @@
54 +diff --git a/lib/astunparse/unparser.py b/lib/astunparse/unparser.py
55 +index edf8c68..0ef6fd8 100644
56 +--- a/lib/astunparse/unparser.py
57 ++++ b/lib/astunparse/unparser.py
58 +@@ -29,7 +29,7 @@ class Unparser:
59 + output source code for the abstract syntax; original formatting
60 + is disregarded. """
61 +
62 +- def __init__(self, tree, file=sys.stdout):
63 ++ def __init__(self, tree, file = sys.stdout):
64 + """Unparser(tree, file=sys.stdout) -> None.
65 + Print the source for tree to file."""
66 + self.f = file
67 +@@ -89,6 +89,13 @@ class Unparser:
68 + self.fill()
69 + self.dispatch(tree.value)
70 +
71 ++ def _NamedExpr(self, tree):
72 ++ self.write("(")
73 ++ self.dispatch(tree.target)
74 ++ self.write(" := ")
75 ++ self.dispatch(tree.value)
76 ++ self.write(")")
77 ++
78 + def _Import(self, t):
79 + self.fill("import ")
80 + interleave(lambda: self.write(", "), self.dispatch, t.names)
81 +@@ -120,11 +127,11 @@ class Unparser:
82 +
83 + def _AnnAssign(self, t):
84 + self.fill()
85 +- if not t.simple:
86 +- self.write("(")
87 ++ if not t.simple and isinstance(t.target, ast.Name):
88 ++ self.write('(')
89 + self.dispatch(t.target)
90 +- if not t.simple:
91 +- self.write(")")
92 ++ if not t.simple and isinstance(t.target, ast.Name):
93 ++ self.write(')')
94 + self.write(": ")
95 + self.dispatch(t.annotation)
96 + if t.value:
97 +@@ -189,6 +196,14 @@ class Unparser:
98 + self.fill("nonlocal ")
99 + interleave(lambda: self.write(", "), self.write, t.names)
100 +
101 ++ def _Await(self, t):
102 ++ self.write("(")
103 ++ self.write("await")
104 ++ if t.value:
105 ++ self.write(" ")
106 ++ self.dispatch(t.value)
107 ++ self.write(")")
108 ++
109 + def _Yield(self, t):
110 + self.write("(")
111 + self.write("yield")
112 +@@ -328,12 +343,19 @@ class Unparser:
113 + self.dispatch(t.body)
114 + self.leave()
115 +
116 +- def _generic_FunctionDef(self, t, async_=False):
117 ++ def _FunctionDef(self, t):
118 ++ self.__FunctionDef_helper(t, "def")
119 ++
120 ++ def _AsyncFunctionDef(self, t):
121 ++ self.__FunctionDef_helper(t, "async def")
122 ++
123 ++ def __FunctionDef_helper(self, t, fill_suffix):
124 + self.write("\n")
125 + for deco in t.decorator_list:
126 + self.fill("@")
127 + self.dispatch(deco)
128 +- self.fill(("async " if async_ else "") + "def " + t.name + "(")
129 ++ def_str = fill_suffix+" "+t.name + "("
130 ++ self.fill(def_str)
131 + self.dispatch(t.args)
132 + self.write(")")
133 + if getattr(t, "returns", False):
134 +@@ -343,14 +365,14 @@ class Unparser:
135 + self.dispatch(t.body)
136 + self.leave()
137 +
138 +- def _FunctionDef(self, t):
139 +- self._generic_FunctionDef(t)
140 ++ def _For(self, t):
141 ++ self.__For_helper("for ", t)
142 +
143 +- def _AsyncFunctionDef(self, t):
144 +- self._generic_FunctionDef(t, async_=True)
145 ++ def _AsyncFor(self, t):
146 ++ self.__For_helper("async for ", t)
147 +
148 +- def _generic_For(self, t, async_=False):
149 +- self.fill("async for " if async_ else "for ")
150 ++ def __For_helper(self, fill, t):
151 ++ self.fill(fill)
152 + self.dispatch(t.target)
153 + self.write(" in ")
154 + self.dispatch(t.iter)
155 +@@ -363,12 +385,6 @@ class Unparser:
156 + self.dispatch(t.orelse)
157 + self.leave()
158 +
159 +- def _For(self, t):
160 +- self._generic_For(t)
161 +-
162 +- def _AsyncFor(self, t):
163 +- self._generic_For(t, async_=True)
164 +-
165 + def _If(self, t):
166 + self.fill("if ")
167 + self.dispatch(t.test)
168 +@@ -586,8 +604,9 @@ class Unparser:
169 +
170 + def _comprehension(self, t):
171 + if getattr(t, 'is_async', False):
172 +- self.write(" async")
173 +- self.write(" for ")
174 ++ self.write(" async for ")
175 ++ else:
176 ++ self.write(" for ")
177 + self.dispatch(t.target)
178 + self.write(" in ")
179 + self.dispatch(t.iter)
180 +@@ -612,26 +631,27 @@ class Unparser:
181 +
182 + def _Dict(self, t):
183 + self.write("{")
184 +- def write_pair(pair):
185 +- (k, v) = pair
186 ++ def write_key_value_pair(k, v):
187 ++ self.dispatch(k)
188 ++ self.write(": ")
189 ++ self.dispatch(v)
190 ++
191 ++ def write_item(item):
192 ++ k, v = item
193 + if k is None:
194 +- self.write('**')
195 ++ # for dictionary unpacking operator in dicts {**{'y': 2}}
196 ++ # see PEP 448 for details
197 ++ self.write("**")
198 + self.dispatch(v)
199 + else:
200 +- self.dispatch(k)
201 +- self.write(": ")
202 +- self.dispatch(v)
203 +- self.write(",")
204 +- self._indent +=1
205 +- self.fill("")
206 +- interleave(lambda: self.fill(""), write_pair, zip(t.keys, t.values))
207 +- self._indent -=1
208 +- self.fill("}")
209 ++ write_key_value_pair(k, v)
210 ++ interleave(lambda: self.write(", "), write_item, zip(t.keys, t.values))
211 ++ self.write("}")
212 +
213 + def _Tuple(self, t):
214 + self.write("(")
215 + if len(t.elts) == 1:
216 +- (elt,) = t.elts
217 ++ elt = t.elts[0]
218 + self.dispatch(elt)
219 + self.write(",")
220 + else:
221 +@@ -656,10 +676,9 @@ class Unparser:
222 + self.dispatch(t.operand)
223 + self.write(")")
224 +
225 +- binop = { "Add":"+", "Sub":"-", "Mult":"*", "Div":"/", "Mod":"%",
226 ++ binop = { "Add":"+", "Sub":"-", "Mult":"*", "MatMult":"@", "Div":"/", "Mod":"%",
227 + "LShift":"<<", "RShift":">>", "BitOr":"|", "BitXor":"^", "BitAnd":"&",
228 +- "FloorDiv":"//", "Pow": "**",
229 +- "MatMult":"@"}
230 ++ "FloorDiv":"//", "Pow": "**"}
231 + def _BinOp(self, t):
232 + self.write("(")
233 + self.dispatch(t.left)
234 +@@ -689,7 +708,7 @@ class Unparser:
235 + # Special case: 3.__abs__() is a syntax error, so if t.value
236 + # is an integer literal then we need to either parenthesize
237 + # it or add an extra space to get 3 .__abs__().
238 +- if isinstance(t.value, ast.Num) and isinstance(t.value.n, int):
239 ++ if isinstance(t.value, getattr(ast, 'Constant', getattr(ast, 'Num', None))) and isinstance(t.value.n, int):
240 + self.write(" ")
241 + self.write(".")
242 + self.write(t.attr)
243 +@@ -760,18 +779,22 @@ class Unparser:
244 + def _arguments(self, t):
245 + first = True
246 + # normal arguments
247 +- defaults = [None] * (len(t.args) - len(t.defaults)) + t.defaults
248 +- for a,d in zip(t.args, defaults):
249 ++ all_args = getattr(t, 'posonlyargs', []) + t.args
250 ++ defaults = [None] * (len(all_args) - len(t.defaults)) + t.defaults
251 ++ for index, elements in enumerate(zip(all_args, defaults), 1):
252 ++ a, d = elements
253 + if first:first = False
254 + else: self.write(", ")
255 + self.dispatch(a)
256 + if d:
257 + self.write("=")
258 + self.dispatch(d)
259 ++ if index == len(getattr(t, 'posonlyargs', ())):
260 ++ self.write(", /")
261 +
262 + # varargs, or bare '*' if no varargs but keyword-only arguments present
263 + if t.vararg or getattr(t, "kwonlyargs", False):
264 +- if first: first = False
265 ++ if first:first = False
266 + else: self.write(", ")
267 + self.write("*")
268 + if t.vararg:
269 +@@ -839,14 +862,6 @@ class Unparser:
270 + self.write(" as ")
271 + self.dispatch(t.optional_vars)
272 +
273 +- def _Await(self, t):
274 +- self.write("(")
275 +- self.write("await")
276 +- if t.value:
277 +- self.write(" ")
278 +- self.dispatch(t.value)
279 +- self.write(")")
280 +-
281 + def roundtrip(filename, output=sys.stdout):
282 + if six.PY3:
283 + with open(filename, "rb") as pyfile:
284 +diff --git a/setup.py b/setup.py
285 +index 6f62fd9..e5a277a 100755
286 +--- a/setup.py
287 ++++ b/setup.py
288 +@@ -48,11 +48,10 @@ setup(
289 + "Programming Language :: Python :: 2",
290 + 'Programming Language :: Python :: 2.7',
291 + 'Programming Language :: Python :: 3',
292 +- 'Programming Language :: Python :: 3.3',
293 +- 'Programming Language :: Python :: 3.4',
294 + 'Programming Language :: Python :: 3.5',
295 + 'Programming Language :: Python :: 3.6',
296 + 'Programming Language :: Python :: 3.7',
297 ++ 'Programming Language :: Python :: 3.8',
298 + 'Topic :: Software Development :: Code Generators',
299 + ],
300 + test_suite='tests',
301 +diff --git a/tests/common.py b/tests/common.py
302 +index c8db903..95b9755 100644
303 +--- a/tests/common.py
304 ++++ b/tests/common.py
305 +@@ -215,6 +215,7 @@ class AstunparseCommonTestCase:
306 + self.check_roundtrip("not True or False")
307 + self.check_roundtrip("True or not False")
308 +
309 ++ @unittest.skipUnless(sys.version_info < (3, 6), "Only works for Python < 3.6")
310 + def test_integer_parens(self):
311 + self.check_roundtrip("3 .__abs__()")
312 +
313
314 diff --git a/dev-python/astunparse/files/astunparse-1.6.2-tests.patch b/dev-python/astunparse/files/astunparse-1.6.2-tests.patch
315 new file mode 100644
316 index 00000000000..b82c22831a9
317 --- /dev/null
318 +++ b/dev-python/astunparse/files/astunparse-1.6.2-tests.patch
319 @@ -0,0 +1,23 @@
320 +diff --git a/tests/common.py b/tests/common.py
321 +index 95b9755..41123de 100644
322 +--- a/tests/common.py
323 ++++ b/tests/common.py
324 +@@ -1,6 +1,7 @@
325 + import codecs
326 + import os
327 + import sys
328 ++import site
329 + if sys.version_info < (2, 7):
330 + import unittest2 as unittest
331 + else:
332 +@@ -175,9 +176,7 @@ class AstunparseCommonTestCase:
333 + def check_roundtrip(self, code1, filename="internal", mode="exec"):
334 + raise NotImplementedError()
335 +
336 +- test_directories = [
337 +- os.path.join(getattr(sys, 'real_prefix', sys.prefix),
338 +- 'lib', 'python%s.%s' % sys.version_info[:2])]
339 ++ test_directories = [os.path.dirname(d) for d in site.getsitepackages()]
340 +
341 + def test_files(self):
342 + names = []