]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-112507: Detect Cygwin and MSYS with `uname` instead of `$OSTYPE` (GH-112508)
authorJames Morris <6653392+J-M0@users.noreply.github.com>
Mon, 11 Dec 2023 17:27:15 +0000 (12:27 -0500)
committerGitHub <noreply@github.com>
Mon, 11 Dec 2023 17:27:15 +0000 (17:27 +0000)
Detect Cygwin and MSYS with `uname` instead of `$OSTYPE`

`$OSTYPE` is not defined by POSIX and may not be present in other shells.
`uname` is always available in any shell.

Lib/venv/scripts/common/activate

index 6fdf423a1c516a4e48f9810d3974f8e965c60a6b..a4e0609045a9d5e1f4c63022aec0559feaf2ad65 100644 (file)
@@ -36,14 +36,18 @@ deactivate () {
 deactivate nondestructive
 
 # on Windows, a path can contain colons and backslashes and has to be converted:
-if [ "${OSTYPE:-}" = "cygwin" ] || [ "${OSTYPE:-}" = "msys" ] ; then
-    # transform D:\path\to\venv to /d/path/to/venv on MSYS
-    # and to /cygdrive/d/path/to/venv on Cygwin
-    export VIRTUAL_ENV=$(cygpath "__VENV_DIR__")
-else
-    # use the path as-is
-    export VIRTUAL_ENV="__VENV_DIR__"
-fi
+case "$(uname)" in
+    CYGWIN*|MSYS*)
+        # transform D:\path\to\venv to /d/path/to/venv on MSYS
+        # and to /cygdrive/d/path/to/venv on Cygwin
+        VIRTUAL_ENV=$(cygpath "__VENV_DIR__")
+        export VIRTUAL_ENV
+        ;;
+    *)
+        # use the path as-is
+        export VIRTUAL_ENV="__VENV_DIR__"
+        ;;
+esac
 
 _OLD_VIRTUAL_PATH="$PATH"
 PATH="$VIRTUAL_ENV/__VENV_BIN_NAME__:$PATH"