Skip to content

Commit

Permalink
env: prevent warning from being emitted on venv creation
Browse files Browse the repository at this point in the history
After python/cpython@6811fda
the venv module produces spurious warnings for venv paths which contain
DOS-encoded parts e.g. "USER~1" in "C:\Users\USER~1".
`tempfile.gettempdir()` returns legacy paths like these for
user temp dirs.

MRE:

    python -c "import tempfile
    import venv

    venv.create(tempfile.mkdtemp())"

    Actual environment location may have moved due to redirects, links or junctions.
    Requested location: "C:\Users\RUNNER~1\AppData\Local\Temp\tmpfoobar\Scripts\python.exe"
    Actual location:    "C:\Users\runneradmin\AppData\Local\Temp\tmpfoobar\Scripts\python.exe"

Closes pypa#413.
  • Loading branch information
layday committed Dec 24, 2021
1 parent cb91293 commit fd26419
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/build/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ def __enter__(self) -> IsolatedEnv:
:return: The isolated build environment
"""
self._path = tempfile.mkdtemp(prefix='build-env-')
# ``realpath`` is used to prevent warning from being emitted that
# the venv location has moved on Windows.
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():
Expand Down

0 comments on commit fd26419

Please sign in to comment.