From c6e17df809ed3d0f476a3588e6a21d25a6fb7f0d Mon Sep 17 00:00:00 2001 From: paugier Date: Wed, 14 Feb 2024 22:34:39 +0100 Subject: [PATCH 1/2] Reproduce issue with Meson + editable mode in test_meson.py --- .../src/package_for_test_meson/foo.py | 5 ++++- tests/test_meson.py | 20 ++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/data_tests/package_for_test_meson/src/package_for_test_meson/foo.py b/data_tests/package_for_test_meson/src/package_for_test_meson/foo.py index 7a0704d..a5b9d2d 100644 --- a/data_tests/package_for_test_meson/src/package_for_test_meson/foo.py +++ b/data_tests/package_for_test_meson/src/package_for_test_meson/foo.py @@ -1,4 +1,7 @@ -from transonic import boost +from transonic import boost, Transonic + +# used for testing +ts = Transonic() @boost diff --git a/tests/test_meson.py b/tests/test_meson.py index 9b48b2d..e243df1 100644 --- a/tests/test_meson.py +++ b/tests/test_meson.py @@ -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)" ) @@ -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" @@ -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") From 3765204212face7fe29f8038117585d33a167c86 Mon Sep 17 00:00:00 2001 From: paugier Date: Wed, 14 Feb 2024 23:40:46 +0100 Subject: [PATCH 2/2] Fix issue with Meson + editable mode (at least for Pythran) --- src/transonic/aheadoftime.py | 16 ++++++++++++++-- src/transonic/backends/py.py | 7 ++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/transonic/aheadoftime.py b/src/transonic/aheadoftime.py index 72bbfa7..53b85ba 100644 --- a/src/transonic/aheadoftime.py +++ b/src/transonic/aheadoftime.py @@ -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 @@ -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) diff --git a/src/transonic/backends/py.py b/src/transonic/backends/py.py index 2ce75ef..9f0a7dd 100644 --- a/src/transonic/backends/py.py +++ b/src/transonic/backends/py.py @@ -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