diff --git a/src/build/env.py b/src/build/env.py index e6d22b5d..80c42d8e 100644 --- a/src/build/env.py +++ b/src/build/env.py @@ -92,7 +92,12 @@ def __enter__(self) -> IsolatedEnv: :return: The isolated build environment """ - self._path = tempfile.mkdtemp(prefix='build-env-') + # Call ``realpath`` to prevent spurious warning from being emitted + # that the venv location has changed on Windows. The username is + # DOS-encoded in the output of tempfile - the location is the same + # but the representation of it is different, which confuses venv. + # Ref: https://bugs.python.org/issue46171 + self._path = os.path.realpath(tempfile.mkdtemp(prefix='build-env-')) try: # use virtualenv when available (as it's faster than venv) if _should_use_virtualenv(): diff --git a/tests/test_env.py b/tests/test_env.py index 9b5506fa..831d7254 100644 --- a/tests/test_env.py +++ b/tests/test_env.py @@ -112,7 +112,7 @@ def test_isolated_env_log(mocker, caplog, package_test_flit): ('INFO', 'Installing packages in isolated environment... (something)'), ] if sys.version_info >= (3, 8): # stacklevel - assert [(record.lineno) for record in caplog.records] == [105, 102, 193] + assert [(record.lineno) for record in caplog.records] == [105, 107, 198] @pytest.mark.isolated