Skip to content

Commit

Permalink
Merge branch 'topic/default/bug-meson-editable' into 'branch/default'
Browse files Browse the repository at this point in the history
Fix bug Meson and editable install

See merge request fluiddyn/transonic!133
  • Loading branch information
paugier committed Feb 15, 2024
2 parents 867ad23 + 3765204 commit 18e242f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from transonic import boost
from transonic import boost, Transonic

# used for testing
ts = Transonic()


@boost
Expand Down
16 changes: 14 additions & 2 deletions src/transonic/aheadoftime.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import os
import functools
import sys
from importlib import import_module

from transonic.backends import backends, get_backend_name_module
from transonic.config import has_to_replace, backend_default
Expand Down Expand Up @@ -236,9 +237,20 @@ def __init__(
path_mod.parent / f"__{backend.name}__" / (module_short_name + suffix)
)

path_ext = None
# for Meson, we try to import module_backend_name
try:
_module_backend = import_module(module_backend_name)
except ImportError:
path_ext = None
else:
if backend.check_if_compiled(_module_backend):
path_ext = Path(_module_backend.__file__)
if not path_ext.exists():
path_ext = None
else:
path_ext = None

if has_to_compile_at_import() and path_mod.exists():
if has_to_compile_at_import() and path_mod.exists() and path_ext is None:
if mpi.has_to_build(path_backend, path_mod):
if path_backend.exists():
time_backend = mpi.modification_date(path_backend)
Expand Down
7 changes: 6 additions & 1 deletion src/transonic/backends/py.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ def compile_extension(
if name_ext_file is None:
name_ext_file = self.name_ext_from_path_backend(path_backend)

copyfile(path_backend, path_backend.with_name(name_ext_file))
if not path_backend.exists():
raise IOError("not path_backend.exists()")

path_ext = path_backend.with_name(name_ext_file)
if path_backend != path_ext:
copyfile(path_backend, path_ext)
compiling = False
process = None
return compiling, process
20 changes: 19 additions & 1 deletion tests/test_meson.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ def run_in_venv(venv, command, cwd=None):
subprocess.run(args, cwd=cwd, check=True, env=env)


def eval_in_venv(venv, code):
process = subprocess.run(
[venv.python, "-c", code],
env=venv.env,
check=True,
capture_output=True,
text=True,
encoding="utf-8",
)
return process.stdout


@pytest.mark.xfail(
sys.platform.startswith("win"), reason="Buggy on Windows (TODO: debug)"
)
Expand Down Expand Up @@ -89,7 +101,7 @@ def test_install_package(tmpdir, venv):
if backend_default == "pythran":
run_in_venv(venv, "pip install pythran")

install_command = "pip install . --no-build-isolation"
install_command = "pip install -e . --no-build-isolation"
if backend_default == "python":
install_command += (
" --config-settings=setup-args=-Dtransonic-backend=python"
Expand All @@ -98,6 +110,12 @@ def test_install_package(tmpdir, venv):
run_in_venv(venv, install_command, cwd=tmpdir)
run_in_venv(venv, "pytest tests", cwd=tmpdir)

out = eval_in_venv(
venv, "from package_for_test_meson.foo import ts; print(ts.is_compiled)"
).strip()
is_compiled = out == "True"
assert is_compiled


@pytest.mark.skipif(nb_proc > 1, reason="No commandline in MPI")
@pytest.mark.xfail(backend_default == "cython", reason="Not yet implemented")
Expand Down

0 comments on commit 18e242f

Please sign in to comment.