Skip to content

Commit ebc8103

Browse files
authored
gh-103088: Sanitize venv paths when using MSYS or Cygwin Bash (GH-103325)
1 parent b57105a commit ebc8103

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

Lib/venv/scripts/common/activate

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,15 @@ deactivate () {
3838
# unset irrelevant variables
3939
deactivate nondestructive
4040

41-
VIRTUAL_ENV="__VENV_DIR__"
42-
export VIRTUAL_ENV
41+
# on Windows, a path can contain colons and backslashes and has to be converted:
42+
if [ "$OSTYPE" = "cygwin" ] || [ "$OSTYPE" = "msys" ] ; then
43+
# transform D:\path\to\venv to /d/path/to/venv on MSYS
44+
# and to /cygdrive/d/path/to/venv on Cygwin
45+
export VIRTUAL_ENV=$(cygpath "__VENV_DIR__")
46+
else
47+
# use the path as-is
48+
export VIRTUAL_ENV="__VENV_DIR__"
49+
fi
4350

4451
_OLD_VIRTUAL_PATH="$PATH"
4552
PATH="$VIRTUAL_ENV/__VENV_BIN_NAME__:$PATH"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixes venvs not working in bash on Windows across different disks

PCbuild/find_python.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
@if NOT "%HOST_PYTHON%"=="" @%HOST_PYTHON% -Ec "import sys; assert sys.version_info[:2] >= (3, 9)" >nul 2>nul && (set PYTHON="%HOST_PYTHON%") && (set _Py_Python_Source=found as HOST_PYTHON) && goto :found
4343

4444
@rem If py.exe finds a recent enough version, use that one
45-
@for %%p in (3.10 3.9) do @py -%%p -EV >nul 2>&1 && (set PYTHON=py -%%p) && (set _Py_Python_Source=found %%p with py.exe) && goto :found
45+
@for %%p in (3.11 3.10 3.9) do @py -%%p -EV >nul 2>&1 && (set PYTHON=py -%%p) && (set _Py_Python_Source=found %%p with py.exe) && goto :found
4646

4747
@if NOT exist "%_Py_EXTERNALS_DIR%" mkdir "%_Py_EXTERNALS_DIR%"
4848
@set _Py_NUGET=%NUGET%

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy