Commit 9a41dab1 authored by Pierre Augier's avatar Pierre Augier
Browse files

Debug PyPy3.5

parent e9b88a5913f7
......@@ -207,8 +207,12 @@ class FluidPythran:
if "." in module_name:
package, module_short_name = module_name.rsplit(".", 1)
module_pythran_name = package + "."
else:
module_short_name = module_name
module_pythran_name = ""
module_pythran_name += "__pythran__._" + module_short_name
self.path_mod = path_mod = Path(frame.filename)
self.path_pythran = path_pythran = (
......@@ -263,10 +267,12 @@ class FluidPythran:
self.is_transpiled = True
if path_ext.exists() and not self.is_compiling:
self.module_pythran = import_from_path(
self.path_extension, module_name
self.path_extension, module_pythran_name
)
elif path_pythran.exists():
self.module_pythran = import_from_path(path_pythran, module_name)
self.module_pythran = import_from_path(
path_pythran, module_pythran_name
)
else:
self.is_transpiled = False
self.is_compiled = False
......
......@@ -32,4 +32,4 @@ else:
from shutil import rmtree
__all__ = ["open", "run_path", "rmtree"]
\ No newline at end of file
__all__ = ["open", "run_path", "rmtree"]
......@@ -11,7 +11,11 @@ except ImportError:
from .transpiler import make_pythran_file
from .util import has_to_pythranize_at_import, ext_suffix
from .util import (
has_to_pythranize_at_import,
ext_suffix,
name_ext_from_path_pythran,
)
from .aheadoftime import modules
module_name = "fluidpythran.for_test_init"
......@@ -24,7 +28,7 @@ class TestsInit(unittest.TestCase):
assert path_for_test.exists()
path_pythran = path_for_test.parent / ("__pythran__/_" + path_for_test.name)
path_ext = path_pythran.with_suffix(ext_suffix)
path_ext = path_pythran.with_name(name_ext_from_path_pythran(path_pythran))
@classmethod
def tearDownClass(cls):
......@@ -32,6 +36,10 @@ class TestsInit(unittest.TestCase):
if cls.path_ext.exists():
cls.path_ext.unlink()
path_ext = cls.path_ext.with_suffix(ext_suffix)
if path_ext.exists():
path_ext.unlink()
try:
os.environ.pop("PYTHRANIZE_AT_IMPORT")
except KeyError:
......@@ -81,6 +89,13 @@ class TestsInit(unittest.TestCase):
if self.path_pythran.exists():
self.path_pythran.unlink()
if self.path_ext.exists():
self.path_ext.unlink()
path_ext = self.path_ext.with_suffix(ext_suffix)
if path_ext.exists():
path_ext.unlink()
from . import for_test_init
if not for_test_init.fp.is_compiling:
......
......@@ -39,7 +39,7 @@ def test_create_pythran_simple():
def test_create_pythran_classic():
util.input = lambda : 'y'
util.input = lambda: "y"
if path_dir_out.exists():
rmtree(path_dir_out)
......
......@@ -301,22 +301,10 @@ def import_from_path(path: Path, module_name: str):
if implementation == "PyPy" and path.suffix == ext_suffix_short:
new_path = path.with_suffix(ext_suffix)
shutil.copy(str(path), str(new_path))
if has_to_build(new_path, path):
shutil.copy(str(path), str(new_path))
path = new_path
if module_name in sys.modules:
module = sys.modules[module_name]
# print("module.__file__", module.__file__)
# print("path", path, flush=True)
if (
module.__file__.endswith(ext_suffix_short)
and Path(module.__file__) == path
or Path(module.__file__).with_suffix(ext_suffix_short) == path
):
return module
if "." in module_name:
package_name, mod_name = module_name.rsplit(".", 1)
name_file = path.name.split(".", 1)[0]
......@@ -325,7 +313,14 @@ def import_from_path(path: Path, module_name: str):
else:
module_name = path.stem
# print("in util", module_name, str(path))
if module_name in sys.modules:
module = sys.modules[module_name]
if (
module.__file__.endswith(ext_suffix_short)
and Path(module.__file__) == path
):
return module
spec = importlib.util.spec_from_file_location(module_name, str(path))
module = importlib.util.module_from_spec(spec)
......
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