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 0873a74b authored by Pierre Augier's avatar Pierre Augier
Browse files

Cleanup

parent f503b2c6bddd
......@@ -215,8 +215,6 @@ def analyse_aot(code, pathfile):
code_dependance = capturex.make_code_external()
import sys
code_ext = {"function": {}, "classe": {}}
def get_exterior_code(
......@@ -229,9 +227,7 @@ def analyse_aot(code, pathfile):
if dep:
module_ext = extast.parse(dep)
for node in module_ext.body:
if isinstance(node, ast.ImportFrom) or isinstance(
node, ast.Import
):
if isinstance(node, (ast.ImportFrom, ast.Import)):
# get the path of the imported module
file_name, file_path = find_path(node, pathfile)
if file_name:
......
......@@ -81,8 +81,6 @@ def analysis_jit(code, pathfile):
codes_dependance_classes[key] = capturex.make_code_external()
import sys
code_ext = {}
code_ext_cls = {}
......@@ -90,75 +88,70 @@ def analysis_jit(code, pathfile):
codes_dependance: dict, previous_file_name=None, cls=None
):
""" Get all imported functions needed by jitted functions add multiple levels,
i.e get functions needed by functions needed by jitted function.
i.e get functions needed by functions needed by jitted function.
"""
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) or isinstance(
node, ast.Import
):
# get the path of the imported module
file_name, file_path = find_path(node, pathfile)
if file_name:
file_name = "__" + func + "__" + file_name
# get the content of the file
with open(str(file_path), "r") as file:
content = file.read()
mod = extast.parse(content)
if cls:
# filter the code and add it to code_ext dict
code_ext_cls[file_name] = str(
filter_external_code(mod, node.names)
)
# change imported module names
codes_dependance_classes[
func
] = change_import_name(
codes_dependance_classes[func],
node,
func,
if not dep:
continue
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)
if file_name:
file_name = "__" + func + "__" + file_name
# get the content of the file
with open(str(file_path), "r") as file:
content = file.read()
mod = extast.parse(content)
if cls:
# filter the code and add it to code_ext dict
code_ext_cls[file_name] = str(
filter_external_code(mod, node.names)
)
# change imported module names
codes_dependance_classes[func] = change_import_name(
codes_dependance_classes[func],
node,
func,
cls="yes",
)
# recursively get the exteriors codes
if code_ext_cls[file_name]:
get_exterior_code(
{func: code_ext_cls[file_name]},
file_name,
cls="yes",
)
# recursively get the exteriors codes
if code_ext_cls[file_name]:
get_exterior_code(
{func: code_ext_cls[file_name]},
file_name,
if previous_file_name:
code_ext_cls[
previous_file_name
] = change_import_name(
code_ext_cls[previous_file_name],
node,
func,
cls="yes",
)
if previous_file_name:
code_ext_cls[
previous_file_name
] = change_import_name(
code_ext_cls[previous_file_name],
node,
func,
cls="yes",
)
else:
# filter the code and add it to code_ext dict
code_ext[file_name] = str(
filter_external_code(mod, node.names)
)
# change imported module names
codes_dependance[func] = change_import_name(
codes_dependance[func], node, func
else:
# filter the code and add it to code_ext dict
code_ext[file_name] = str(
filter_external_code(mod, node.names)
)
# change imported module names
codes_dependance[func] = change_import_name(
codes_dependance[func], node, func
)
# recursively get the exteriors codes
if code_ext[file_name]:
get_exterior_code(
{func: code_ext[file_name]}, file_name
)
# recursively get the exteriors codes
if code_ext[file_name]:
get_exterior_code(
{func: code_ext[file_name]}, file_name
if previous_file_name:
code_ext[
previous_file_name
] = change_import_name(
code_ext[previous_file_name], node, func
)
if previous_file_name:
code_ext[
previous_file_name
] = change_import_name(
code_ext[previous_file_name],
node,
func,
)
if jitted_dicts["methods"]:
get_exterior_code(codes_dependance_classes, cls="yes")
......
......@@ -174,7 +174,9 @@ def gather_rawcode_comments(node, code_module):
return rawcode, comments
# TODO complete the list
packages_supported_by_pythran = ["numpy", "math", "functools", "cmath"]
# FIXME find path in non local imports
def find_path(node: object, pathfile: str):
""" Return the path of node (instance of ast.Import or ast.ImportFrom)
......@@ -187,11 +189,9 @@ def find_path(node: object, pathfile: str):
if name in packages_supported_by_pythran:
return None, None
else:
parent = parent = Path(pathfile).parent
path = parent / Path(str(name.replace(".", "/")) + ".py")
parent = Path(pathfile).parent
path = parent / (str(name.replace(".", "/")) + ".py")
else:
# TODO complete the list
if node.names[0].name in packages_supported_by_pythran:
pass
else:
......@@ -203,7 +203,7 @@ def find_path(node: object, pathfile: str):
def change_import_name(
code_dep: str, changed_node: object, func_name: str, cls: str = None
):
""" Change the name of changed_node in code_dep by adding "__"+func+"__"
""" Change the name of changed_node in code_dep by adding "__" + func + "__"
at the beginning of the imported module, and return the modified code
"""
mod = extast.parse(code_dep)
......@@ -219,7 +219,7 @@ def change_import_name(
def filter_external_code(module: object, names: list):
""" Filter the module to keep only the necessary nodes
""" Filter the module to keep only the necessary nodes
needed by functions or class in the parameter names
"""
code_dependance_annotations = ""
......
......@@ -243,17 +243,11 @@ def make_pythran_file(path_py: Path, force=False, log_level=None):
return
for file_name, code in code_ext["function"].items():
path_ext_file = path_dir / (file_name.replace(".", "/") + ".py")
path_ext_file.parent.mkdir(exist_ok=True, parents=True)
path_ext_file = path_dir / (file_name + ".py")
write_if_has_to_write(path_ext_file, code, logger.info)
for file_name, code in code_ext["classe"].items():
path_ext_file = (
path_dir.parent
/ "__pythran__"
/ (file_name.replace(".", "/") + ".py")
)
path_ext_file.parent.mkdir(exist_ok=True, parents=True)
path_ext_file = path_dir.parent / "__pythran__" / (file_name + ".py")
write_if_has_to_write(path_ext_file, code, logger.info)
if path_pythran.exists() and not force:
......
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