From ae14a4b9e7181203bb03d005c7edeb59bf222fd3 Mon Sep 17 00:00:00 2001 From: Matthew Broadway Date: Thu, 29 Feb 2024 11:15:25 +0000 Subject: [PATCH] temporary debug messages --- .github/workflows/test_pypy.yml | 21 +++++++++++++++++++ example.py | 19 +++++++++++++++++ src/maturin_import_hook/project_importer.py | 2 ++ tests/test_import_hook/common.py | 11 ++++++++-- .../test_import_hook/test_project_importer.py | 1 + 5 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/test_pypy.yml create mode 100644 example.py diff --git a/.github/workflows/test_pypy.yml b/.github/workflows/test_pypy.yml new file mode 100644 index 0000000..1954e3f --- /dev/null +++ b/.github/workflows/test_pypy.yml @@ -0,0 +1,21 @@ +name: TestPyPy + +on: + workflow_dispatch: + +jobs: + test: + name: Test + runs-on: windows-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: pypy3.10 + architecture: "x64" + - name: Create venv + run: python -m venv venv + - name: Run test + run: | + venv\Scripts\activate.bat + python example.py diff --git a/example.py b/example.py new file mode 100644 index 0000000..1a0850f --- /dev/null +++ b/example.py @@ -0,0 +1,19 @@ +import multiprocessing +import os +import sys + + +def worker() -> None: + print(f"worker process executable: {sys.executable}") + print(f"worker process exec_prefix: {sys.exec_prefix}") + print(f"worker process env: {os.environ}") + + +if __name__ == "__main__": + print(f"main process executable: {sys.executable}") + print(f"main process exec_prefix: {sys.exec_prefix}") + print(f"main process env: {os.environ}") + + p = multiprocessing.Process(target=worker) + p.start() + p.join() diff --git a/src/maturin_import_hook/project_importer.py b/src/maturin_import_hook/project_importer.py index a145397..5646674 100644 --- a/src/maturin_import_hook/project_importer.py +++ b/src/maturin_import_hook/project_importer.py @@ -124,6 +124,7 @@ def find_spec( logger.debug( '%s searching for "%s"%s', type(self).__name__, package_name, " (reload)" if already_loaded else "" ) + logger.debug("search paths: %s", sys.path) start = time.perf_counter() @@ -133,6 +134,7 @@ def find_spec( spec = None rebuilt = False for search_path in search_paths: + logger.debug("contents of %s:\n%s", search_path, sorted(os.listdir(search_path))) project_dir, is_editable = _load_dist_info(search_path, package_name) if project_dir is not None: logger.debug('found project linked by dist-info: "%s"', project_dir) diff --git a/tests/test_import_hook/common.py b/tests/test_import_hook/common.py index d4216e0..0dc4007 100644 --- a/tests/test_import_hook/common.py +++ b/tests/test_import_hook/common.py @@ -139,11 +139,16 @@ def run_python( ) -> Tuple[str, float]: start = time.perf_counter() - cmd = [sys.executable] + interpreter_path = sys.executable + + msg = f"python executable on the subprocess: {sys.executable} ({sys.exec_prefix})" + raise PythonProcessError(msg) + + cmd = [interpreter_path] if profile is not None: cmd += ["-m", "cProfile", "-o", str(profile.resolve())] cmd.extend(args) - log.info("running python") + log.info("running python ('%s')", interpreter_path) try: proc = subprocess.run( cmd, @@ -161,6 +166,8 @@ def run_python( "-" * 40, "Called Process Error:", subprocess.list2cmdline(cmd), + "Env:", + str(os.environ), "Output:", output, "-" * 40, diff --git a/tests/test_import_hook/test_project_importer.py b/tests/test_import_hook/test_project_importer.py index 06ce1af..7cb98ef 100644 --- a/tests/test_import_hook/test_project_importer.py +++ b/tests/test_import_hook/test_project_importer.py @@ -358,6 +358,7 @@ def test_concurrent_import(workspace: Path, initially_mixed: bool, mixed: bool) args = {"python_script": check_installed_with_hook, "quiet": True} + log.info("python executable on the main thread: %s (%s)", sys.executable, sys.exec_prefix) outputs = run_concurrent_python(3, run_python_code, args) num_compilations = 0