Skip to content

Commit 5bddd22

Browse files
committed
build: compile module was removed in Python 3
1 parent 66ad305 commit 5bddd22

File tree

1 file changed

+18
-28
lines changed

1 file changed

+18
-28
lines changed

gyp/pylib/gyp/input.py

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,8 @@
44

55
from __future__ import print_function
66

7-
from compiler.ast import Const
8-
from compiler.ast import Dict
9-
from compiler.ast import Discard
10-
from compiler.ast import List
11-
from compiler.ast import Module
12-
from compiler.ast import Node
13-
from compiler.ast import Stmt
14-
import compiler
7+
import ast
8+
159
import gyp.common
1610
import gyp.simple_copy
1711
import multiprocessing
@@ -184,43 +178,39 @@ def CheckedEval(file_contents):
184178
Note that this is slower than eval() is.
185179
"""
186180

187-
ast = compiler.parse(file_contents)
188-
assert isinstance(ast, Module)
189-
c1 = ast.getChildren()
190-
assert c1[0] is None
191-
assert isinstance(c1[1], Stmt)
192-
c2 = c1[1].getChildren()
193-
assert isinstance(c2[0], Discard)
194-
c3 = c2[0].getChildren()
195-
assert len(c3) == 1
196-
return CheckNode(c3[0], [])
181+
syntax_tree = ast.parse(file_contents)
182+
assert isinstance(syntax_tree, ast.Module)
183+
c1 = syntax_tree.body
184+
assert len(c1) == 1
185+
c2 = c1[0]
186+
assert isinstance(c2, ast.Expr)
187+
return CheckNode(c2.value, [])
197188

198189

199190
def CheckNode(node, keypath):
200-
if isinstance(node, Dict):
191+
if isinstance(node, ast.Dict):
201192
c = node.getChildren()
202193
dict = {}
203-
for n in range(0, len(c), 2):
204-
assert isinstance(c[n], Const)
205-
key = c[n].getChildren()[0]
194+
for key, value in zip(node.keys, node.values):
195+
assert isinstance(key, ast.Str)
196+
key = key.s
206197
if key in dict:
207198
raise GypError("Key '" + key + "' repeated at level " +
208199
repr(len(keypath) + 1) + " with key path '" +
209200
'.'.join(keypath) + "'")
210201
kp = list(keypath) # Make a copy of the list for descending this node.
211202
kp.append(key)
212-
dict[key] = CheckNode(c[n + 1], kp)
203+
dict[key] = CheckNode(value, kp)
213204
return dict
214-
elif isinstance(node, List):
215-
c = node.getChildren()
205+
elif isinstance(node, ast.List):
216206
children = []
217-
for index, child in enumerate(c):
207+
for index, child in enumerate(node.elts):
218208
kp = list(keypath) # Copy list.
219209
kp.append(repr(index))
220210
children.append(CheckNode(child, kp))
221211
return children
222-
elif isinstance(node, Const):
223-
return node.getChildren()[0]
212+
elif isinstance(node, ast.Str):
213+
return node.s
224214
else:
225215
raise TypeError("Unknown AST node at key path '" + '.'.join(keypath) +
226216
"': " + repr(node))

0 commit comments

Comments
 (0)