Commit f53ba6e3 authored by Pierre Augier's avatar Pierre Augier
Browse files

Start to work on PyPy3.5 compatibility

parent da0d14d510f8
......@@ -73,6 +73,8 @@ from .util import (
)
from .annotation import make_signatures_from_typehinted_func
from .compat import open
modules = {}
......
"""Compatibility layer for PyPy3.5
"""
import platform
import builtins
import runpy
import shutil
f"In >=2018, you should use a Python supporting f-strings!"
implementation = platform.python_implementation()
if implementation == "PyPy":
def open(file, *args, **kwargs):
return builtins.open(str(file), *args, **kwargs)
def run_path(path):
return runpy.run_path(str(path))
def rmtree(path):
shutil.rmtree(str(path))
else:
from builtins import open
from runpy import run_path
from shutil import rmtree
__all__ = ["open", "run_path", "rmtree"]
\ No newline at end of file
......@@ -42,7 +42,7 @@ def detect_pythran_extensions(name_package):
if not can_import_pythran:
return []
ext_names = []
for root, dirs, files in os.walk(name_package):
for root, dirs, files in os.walk(str(name_package)):
path_dir = Path(root)
for name in files:
if (
......
from pathlib import Path
import shutil
import importlib
from . import FluidPythran
from .compat import rmtree
def test_not_fluidpythranized():
......@@ -12,7 +14,7 @@ def test_not_fluidpythranized():
path_output = path_for_test.parent / "__pythran__"
if path_output.exists():
shutil.rmtree(path_output)
rmtree(path_output)
from . import for_test_init
......
import sys
from shutil import rmtree
import time
from . import path_data_tests
......@@ -7,6 +7,8 @@ from . import path_data_tests
from .run import run
from . import util
from .compat import rmtree
path_dir_out = path_data_tests / "__pythran__"
......
......@@ -44,6 +44,7 @@ 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 .compat import open
import fluidpythran
......
......@@ -63,6 +63,8 @@ import time
from typing import Callable, Iterable, Union, Optional
from .compat import open, implementation
import astunparse
try:
......@@ -105,7 +107,7 @@ def get_module_name(frame):
def modification_date(filename):
"""Get the modification date of a file"""
return datetime.fromtimestamp(os.path.getmtime(filename))
return datetime.fromtimestamp(os.path.getmtime(str(filename)))
def has_to_build(output_file: Path, input_file: Path):
......@@ -204,6 +206,10 @@ class SchedulerPopen:
process for process in self.processes if process.poll() is None
]
if implementation == "PyPy":
cwd = str(cwd)
words_command = [str(word) for word in words_command]
process = subprocess.Popen(words_command, cwd=cwd)
self.processes.append(process)
return process
......@@ -293,11 +299,21 @@ def import_from_path(path: Path, module_name: str):
f"[path.name for path in path.parent.glob('*')]:\n{[path.name for path in path.parent.glob('*')]}\n"
)
if implementation == "PyPy" and path.suffix == ext_suffix_short:
new_path = path.with_suffix(ext_suffix)
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
......@@ -309,7 +325,9 @@ def import_from_path(path: Path, module_name: str):
else:
module_name = path.stem
spec = importlib.util.spec_from_file_location(module_name, path)
# print("in util", module_name, str(path))
spec = importlib.util.spec_from_file_location(module_name, str(path))
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
......
from setuptools import setup, find_packages
from runpy import run_path
from runpy import run_path as run_path_
from pathlib import Path
import platform
f"In >=2018, you should use a Python supporting f-strings!"
if platform.python_implementation() == "PyPy":
def run_path(path):
return run_path_(str(path))
else:
run_path = run_path_
here = Path(__file__).parent.absolute()
d = run_path(here / "fluidpythran/_version.py")
......
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