Read about our upcoming Code of Conduct on this issue

This instance will be upgraded to Heptapod 0.28.1 on 2022-01-26 at 16:00 UTC+1 (a few minutes of down time)

Commit 6aa9c626 authored by Pierre Blanc-fatin's avatar Pierre Blanc-fatin
Browse files

Fix two files created for one imported jitted function

parent 0404687423fc
......@@ -45,14 +45,13 @@ def analysis_jit(code, pathfile):
codes_dependance = {}
# get code dependance for a decorated function from a imported module
# get code dependance of a decorated function from a imported module
for func_name, (func_node, imported_module) in jitted_dicts[
"functions_ext"
].items():
capturex = CaptureX(
(func_node,), imported_module, consider_annotations=False
)
# replace the tuple (func_node, imported_module) in jitted_dicts by the dependance of func_node
codes_dependance[func_name] = capturex.make_code_external()
# remove the decorator (jit) to compute the code dependance
......
......@@ -329,14 +329,26 @@ def get_exterior_code(
codes_dependance[func] = adapt_code_dependance(
func, codes_dependance[func]
)
elif file_name:
file_name = "__" + func + "__" + file_name
for func, dep in codes_dependance.items():
if dep:
module_ext = extast.parse(dep)
for node in module_ext.body:
if isinstance(node, (ast.ImportFrom, ast.Import)):
# get the path of the imported module
file_name, file_path = find_path(node, pathfile)
# a jitted function or method needs another jitted function
if file_name:
new_file_name = "__" + func + "__" + file_name
# get the content of the file
with open(str(file_path), "r") as file:
content = file.read()
try:
with open(str(file_path), "r") as file:
content = file.read()
except:
break
mod = extast.parse(content)
# filter the code and add it to code_ext dict
code_ext[classes][file_name] = str(
code_ext[classes][new_file_name] = str(
filter_external_code(mod, node.names)
)
# change imported module names
......@@ -344,15 +356,14 @@ def get_exterior_code(
codes_dependance[func], node, func, relative
)
# recursively get the exterior codes
if code_ext[classes][file_name]:
if code_ext[classes][new_file_name]:
get_exterior_code(
{func: code_ext[classes][file_name]},
{func: code_ext[classes][new_file_name]},
pathfile,
file_name,
new_file_name,
classes,
)
if previous_file_name:
print(code_ext)
code_ext[classes][
previous_file_name
] = change_import_name(
......
......@@ -79,6 +79,7 @@ from numpy import pi
const = 1
# FIXME support multilevel with jit(func_import)
# FIXME support a different name
jitted_func_import = jit(func_import)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment