120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 | |
def parse_path(path): |
if not isinstance(path, PathBase): |
path = py.path.local(path) |
buf = path.open().read() |
st = parse(buf) |
|
nodes = dir_nodes(st) |
function_ast = [i for i in nodes if isinstance(i, ast.Function)] |
classes_ast = [i for i in nodes if isinstance(i, ast.Class)] |
mod_dict = dict([(i.name, function_from_ast(i, None)) for i in function_ast] |
+ [(i.name, class_from_ast(i)) for i in classes_ast]) |
|
try: |
-> mod = path.pyimport() |
except (KeyboardInterrupt, SystemExit): |
raise |
except: |
|
|
pass |
else: |
update_mod_dict(mod, mod_dict) |
return Module(path, mod_dict) | |