Read about our upcoming Code of Conduct on this issue

Commit 0e765ca3 authored by Pierre Augier's avatar Pierre Augier
Browse files

Fix bug module_name

--HG--
branch : dev
parent ec715fd799b4
......@@ -323,17 +323,7 @@ class FluidPythran:
if path_ext_alt.exists():
self.path_extension = path_ext = path_ext_alt
if path_ext.exists() and not self.is_compiling:
self.module_pythran = import_from_path(
self.path_extension, module_pythran_name
)
elif path_pythran.exists():
self.module_pythran = import_from_path(
path_pythran, module_pythran_name
)
else:
self.is_transpiled = False
self.is_compiled = False
self.reload_module_pythran(module_pythran_name)
if self.is_transpiled:
self.is_compiled = hasattr(self.module_pythran, "__pythran__")
......@@ -351,14 +341,16 @@ class FluidPythran:
modules[module_name] = self
def reload_module_pythran(self):
def reload_module_pythran(self, module_pythran_name=None):
if module_pythran_name is None:
module_pythran_name = self.module_pythran.__name__
if self.path_extension.exists() and not self.is_compiling:
self.module_pythran = import_from_path(
self.path_extension, self.module_pythran.__name__
self.path_extension, module_pythran_name
)
elif self.path_pythran.exists():
self.module_pythran = import_from_path(
self.path_pythran, self.module_pythran.__name__
self.path_pythran, module_pythran_name
)
else:
self.is_transpiled = False
......@@ -390,15 +382,14 @@ class FluidPythran:
if not self.is_transpiled:
return func
if not hasattr(self.module_pythran, func.__name__):
self.reload_module_pythran()
try:
func_tmp = getattr(self.module_pythran, func.__name__)
except AttributeError:
logger.warning("Pythran file does not seem to be up-to-date.")
self.reload_module_pythran()
try:
func_tmp = getattr(self.module_pythran, func.__name__)
except AttributeError:
func_tmp = func
func_tmp = func
if self.is_compiling:
return functools.wraps(func)(CheckCompiling(self, func_tmp))
......@@ -414,9 +405,6 @@ class FluidPythran:
func: a function
"""
print("pythran_def_method", func, is_transpiling, self.is_transpiled)
if is_transpiling:
func.__fluidpythran__ = "pythran_def_method"
return func
......@@ -456,11 +444,7 @@ class FluidPythran:
)
if not hasattr(self.module_pythran, name_pythran_func):
print("self.module_pythran", self.module_pythran)
self.reload_module_pythran()
print("self.module_pythran", self.module_pythran)
with open(self.module_pythran.__file__, "r") as file:
print(file.read())
try:
pythran_func = getattr(self.module_pythran, name_pythran_func)
......@@ -552,7 +536,6 @@ class FluidPythran:
class FluidPythranTemporaryMethod:
def __init__(self, func):
print("init FluidPythranTemporaryMethod", func)
self.func = func
def __call__(self, self_bis, *args, **kwargs):
......
......@@ -62,16 +62,10 @@ class TestsInit(unittest.TestCase):
if self.path_pythran.exists():
self.path_pythran.unlink()
print("make_pythran_file", self.path_for_test)
make_pythran_file(self.path_for_test)
print("from . import for_test_init")
from . import for_test_init
print("importlib.reload(for_test_init)")
importlib.reload(for_test_init)
assert self.path_pythran.exists()
......@@ -108,6 +102,8 @@ class TestsInit(unittest.TestCase):
if not for_test_init.fp.is_compiling:
importlib.reload(for_test_init)
assert module_name in modules, modules
assert self.path_pythran.exists()
fp = for_test_init.fp
......
......@@ -36,7 +36,6 @@ from tokenize import (
OP,
)
import os
from logging import DEBUG
from token import tok_name
......@@ -56,7 +55,11 @@ except ImportError:
from .log import logger, set_log_level
from .annotation import compute_pythran_types_from_valued_types
from .util import has_to_build, get_source_without_decorator
from .util import (
has_to_build,
get_source_without_decorator,
find_module_name_from_path,
)
from .compat import open
from .mpi import Path
import fluidpythran
......@@ -379,9 +382,8 @@ def make_pythran_code(path_py: Path):
code = file.read()
namespace = None
module_name = ".".join(
path_py.absolute().relative_to(os.getcwd()).with_suffix("").parts
)
module_name = find_module_name_from_path(path_py)
if "# FLUIDPYTHRAN_NO_IMPORT" not in code:
# we have to import the module!
......@@ -430,13 +432,6 @@ imports: {imports}\n"""
if imports:
code_pythran += "\n" + "\n".join(imports) + "\n"
print(f"\n\n {path_py} \n {module_name} \n\n")
print(
"if module_name in fluidpythran.aheadoftime.modules:",
module_name in fluidpythran.aheadoftime.modules,
)
print(module_name, fluidpythran.aheadoftime.modules)
if module_name in fluidpythran.aheadoftime.modules:
fp = fluidpythran.aheadoftime.modules[module_name]
fp._make_signatures_from_annotations()
......@@ -451,11 +446,17 @@ imports: {imports}\n"""
signatures_func_all[name_func] = []
signatures_func_all[name_func].extend(signatures)
print("for cls in fp.classes.values():")
for cls in fp.classes.values():
code_pythran += produce_pythran_code_class(cls)
else:
if "# FLUIDPYTHRAN_NO_IMPORT" not in code:
logger.warning(
"module_name not in fluidpythran.aheadoftime.modules\n"
f"module_name = {module_name}"
f"path_py = {path_py}"
)
codes_functions = get_code_functions(code, functions)
signatures_func_all = signatures_func
......
......@@ -4,6 +4,8 @@
Internal API
------------
.. autofunction:: find_module_name_from_path
.. autofunction:: get_module_name
.. autofunction:: modification_date
......@@ -64,15 +66,35 @@ path_root = Path(
)
def find_module_name_from_path(path_py: Path):
cwd = Path.cwd()
path = path_py.absolute().parent
module_name = path_py.stem
while path.parents:
if path == cwd or str(path) in sys.path:
return module_name
module_name = path.name + "." + module_name
path = path.parent
return path_py.stem
def get_module_name(frame):
"""Get the full module name"""
module = inspect.getmodule(frame[0])
filename = None
if module is not None:
module_name = module.__name__
if module_name in ("__main__", "<run_path>"):
module_name = inspect.getmodulename(frame.filename)
filename = frame.filename
else:
module_name = inspect.getmodulename(frame.filename)
filename = frame.filename
if filename is not None:
module_name = find_module_name_from_path(Path(filename))
if module_name is None:
# ipython ?
......
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