From c333b131d3ef5c7ab3ec1c5f220db23e061fbe3a Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Wed, 29 May 2024 02:20:02 -0400 Subject: [PATCH] fix: include VIRTUAL_ENV variable (#1842) Signed-off-by: Henry Schreiner --- cibuildwheel/linux.py | 1 + cibuildwheel/macos.py | 1 + cibuildwheel/pyodide.py | 1 + cibuildwheel/util.py | 1 + cibuildwheel/windows.py | 1 + test/test_testing.py | 1 + 6 files changed, 6 insertions(+) diff --git a/cibuildwheel/linux.py b/cibuildwheel/linux.py index b245d1cdd..c33c0de4f 100644 --- a/cibuildwheel/linux.py +++ b/cibuildwheel/linux.py @@ -343,6 +343,7 @@ def build_in_container( virtualenv_env = env.copy() virtualenv_env["PATH"] = f"{venv_dir / 'bin'}:{virtualenv_env['PATH']}" + virtualenv_env["VIRTUAL_ENV"] = str(venv_dir) # TODO remove me once virtualenv provides pip>=24.1b1 if config.version == "3.13": diff --git a/cibuildwheel/macos.py b/cibuildwheel/macos.py index c54b83b4e..977f7f203 100644 --- a/cibuildwheel/macos.py +++ b/cibuildwheel/macos.py @@ -576,6 +576,7 @@ def build(options: Options, tmp_path: Path) -> None: virtualenv_env["PATH"], ] ) + virtualenv_env["VIRTUAL_ENV"] = str(venv_dir) # check that we are using the Python from the virtual environment call_with_arch("which", "python", env=virtualenv_env) diff --git a/cibuildwheel/pyodide.py b/cibuildwheel/pyodide.py index 02a036bc0..30345f7bb 100644 --- a/cibuildwheel/pyodide.py +++ b/cibuildwheel/pyodide.py @@ -353,6 +353,7 @@ def build(options: Options, tmp_path: Path) -> None: virtualenv_env["PATH"], ] ) + virtualenv_env["VIRTUAL_ENV"] = str(venv_dir) # check that we are using the Python from the virtual environment call("which", "python", env=virtualenv_env) diff --git a/cibuildwheel/util.py b/cibuildwheel/util.py index 7ac842cf7..22e2c212b 100644 --- a/cibuildwheel/util.py +++ b/cibuildwheel/util.py @@ -700,6 +700,7 @@ def virtualenv( paths = [str(venv_path), str(venv_path / "Scripts")] if IS_WIN else [str(venv_path / "bin")] env = os.environ.copy() env["PATH"] = os.pathsep.join([*paths, env["PATH"]]) + env["VIRTUAL_ENV"] = str(venv_path) return env diff --git a/cibuildwheel/windows.py b/cibuildwheel/windows.py index 570a51cd1..3c0b87792 100644 --- a/cibuildwheel/windows.py +++ b/cibuildwheel/windows.py @@ -501,6 +501,7 @@ def build(options: Options, tmp_path: Path) -> None: virtualenv_env["PATH"], ] ) + virtualenv_env["VIRTUAL_ENV"] = str(venv_dir) # check that we are using the Python from the virtual environment call("where", "python", env=virtualenv_env) diff --git a/test/test_testing.py b/test/test_testing.py index 2e6fe3c37..2f2a366f1 100644 --- a/test/test_testing.py +++ b/test/test_testing.py @@ -58,6 +58,7 @@ def test_virtualenv(self): self.assertTrue(path_contains(sys.prefix, sys.executable)) self.assertTrue(path_contains(sys.prefix, spam.__file__)) + self.assertIn("VIRTUAL_ENV", os.environ) def test_uname(self): if platform.system() == "Windows":