Read about our upcoming Code of Conduct on this issue

Commit 8810ba3f authored by Pierre Blanc-fatin's avatar Pierre Blanc-fatin
Browse files

Detect_transonic_extensions fixes : deal with .pyx and filter exterior files

parent e3070a9154c4
import numpy as np
from __MyClass2__exterior_import_boost import func_import
from __ext__MyClass2__exterior_import_boost import func_import
# pythran export __for_method__MyClass2__myfunc(int, int, int)
......
import numpy as np
from __func__exterior_import_boost import func_import
from __ext__func__exterior_import_boost import func_import
# pythran export func(float[][], float[][])
......
......@@ -213,9 +213,11 @@ def change_import_name(
for node in mod.body:
if extast.unparse(node) == extast.unparse(changed_node):
if isinstance(node, ast.ImportFrom):
node.module = "__" + func_name + "__" + node.module
node.module = "__ext__" + func_name + "__" + node.module
elif isinstance(node, ast.Import):
node.names[0].name = "__" + func_name + "__" + node.names[0].name
node.names[0].name = (
"__ext__" + func_name + "__" + node.names[0].name
)
if not relative:
node.level = 0
return extast.unparse(mod)
......@@ -375,7 +377,7 @@ def get_exterior_code(
# a jitted function or method needs another jitted function
if not (file_name and not file_name in treated):
continue
new_file_name = "__" + func + "__" + file_name
new_file_name = "__ext__" + func + "__" + file_name
# get the content of the file
try:
with open(str(file_path), "r") as file:
......@@ -407,17 +409,3 @@ def get_exterior_code(
relative,
)
return codes_dependance, code_ext, jitted_dicts, special
def get_source_with_numba(func: Callable):
"""Get the source and adapt to numba"""
src = inspect.getsource(func)
src = dedent(src)
mod = extast.parse(src)
for node in mod.body:
node.decorator_list[0].keywords = [
ast.keyword("nopython", value=ast.Str("True")),
ast.keyword("nogil", value=ast.Str("True")),
]
src = "\nfrom numba import jit \n" + extast.unparse(mod) + "\n"
return src
......@@ -85,21 +85,28 @@ def detect_transonic_extensions(
present in the current working directory.
"""
# TODO Deal with pyx
# TODO Filter exterior functions
if not can_import_pythran:
return []
ext_names = []
if not os.path.exists(str(name_package)):
raise FileNotFoundError(f"Check the name of the package: {name_package}")
if backend == "cython":
extension = ".pyx"
else:
extension = ".py"
for root, dirs, files in os.walk(str(name_package)):
path_dir = Path(root)
for name in files:
if path_dir.name == f"__{backend}__" and name.endswith(".py"):
if (
path_dir.name == f"__{backend}__"
and name.endswith(extension)
and not name.startswith("__ext__")
):
path = path_dir / name
ext_names.append(
str(path).replace(os.path.sep, ".").split(".py")[0]
str(path).replace(os.path.sep, ".").split(extension)[0]
)
return ext_names
......
......@@ -44,8 +44,8 @@ def test_detect_pythran_extensions():
make_backend_files((path_data_tests / name for name in names))
ext_names = detect_transonic_extensions(path_data_tests)
# -2 files (no_pythran.py and assign_fun_jit.py) +2 files (__func__exterior_import_boost.py and __func__exterior_import_boost_2.py)
assert len(ext_names) == len(names)
# -2 files (no_pythran.py and assign_fun_jit.py)
assert len(ext_names) == len(names) - 2
shutil.rmtree(path_data_tests / "__pythran__", ignore_errors=True)
......
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