summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordavidcoghlan <42351331+davidcoghlan@users.noreply.github.com>2020-10-12 10:51:18 +0100
committerGitHub <noreply@github.com>2020-10-12 10:51:18 +0100
commit2b0bbbabb45044c44d35e65bfc5aa60403b4906b (patch)
treeed3c9ad5385679901ae71ac996ecfcb363d2147b
parent8df26493c467204dc6f94a9055aced3d74e4f95a (diff)
downloadvirtualenv-2b0bbbabb45044c44d35e65bfc5aa60403b4906b.tar.gz
Fix absolute paths for Cygwin (#1970)
* Fix absolute paths for Cygwin Absolute paths on Windows take the form "c:\somePath" -- these need to be mapped to the form "/cygdrive/c/somePath" on Cygwin. Otherwise, the virtualenv path gets garbled when activated on Cygwin, which can cause the wrong Python environment to be used. * Remove Cygwin from the list, rely on the shell script for that * Improved formatting * Update tests to handle mingw + msys explicitly * Add changelog entry * lint errors * Add msys support to the activation script * Fix script error & linting
-rw-r--r--docs/changelog/1969.bugfix.rst1
-rw-r--r--src/virtualenv/activation/bash/activate.sh3
-rw-r--r--src/virtualenv/activation/via_template.py15
-rw-r--r--tests/unit/activation/test_activation_support.py44
4 files changed, 5 insertions, 58 deletions
diff --git a/docs/changelog/1969.bugfix.rst b/docs/changelog/1969.bugfix.rst
new file mode 100644
index 0000000..6e6e706
--- /dev/null
+++ b/docs/changelog/1969.bugfix.rst
@@ -0,0 +1 @@
+Handle Cygwin path conversion in the activation script - by :user:`davidcoghlan`.
diff --git a/src/virtualenv/activation/bash/activate.sh b/src/virtualenv/activation/bash/activate.sh
index 19bf552..222d982 100644
--- a/src/virtualenv/activation/bash/activate.sh
+++ b/src/virtualenv/activation/bash/activate.sh
@@ -47,6 +47,9 @@ deactivate () {
deactivate nondestructive
VIRTUAL_ENV='__VIRTUAL_ENV__'
+if ([ "$OSTYPE" = "cygwin" ] || [ "$OSTYPE" = "msys" ]) && $(command -v cygpath &> /dev/null) ; then
+ VIRTUAL_ENV=$(cygpath -u "$VIRTUAL_ENV")
+fi
export VIRTUAL_ENV
_OLD_VIRTUAL_PATH="$PATH"
diff --git a/src/virtualenv/activation/via_template.py b/src/virtualenv/activation/via_template.py
index 6839f05..14f0979 100644
--- a/src/virtualenv/activation/via_template.py
+++ b/src/virtualenv/activation/via_template.py
@@ -1,9 +1,7 @@
from __future__ import absolute_import, unicode_literals
import os
-import re
import sys
-import sysconfig
from abc import ABCMeta, abstractmethod
from six import add_metaclass
@@ -33,20 +31,9 @@ class ViaTemplateActivator(Activator):
return generated
def replacements(self, creator, dest_folder):
- current_platform = sysconfig.get_platform()
- platforms = ["mingw", "cygwin", "msys"]
- if any(platform in current_platform for platform in platforms):
- pattern = re.compile("^([A-Za-z]):(.*)")
- match = pattern.match(str(creator.dest))
- if match:
- virtual_env = "/" + match.group(1).lower() + match.group(2)
- else:
- virtual_env = str(creator.dest)
- else:
- virtual_env = str(creator.dest)
return {
"__VIRTUAL_PROMPT__": "" if self.flag_prompt is None else self.flag_prompt,
- "__VIRTUAL_ENV__": ensure_text(virtual_env),
+ "__VIRTUAL_ENV__": ensure_text(str(creator.dest)),
"__VIRTUAL_NAME__": creator.env_name,
"__BIN_NAME__": ensure_text(str(creator.bin_dir.relative_to(creator.dest))),
"__PATH_SEP__": ensure_text(os.pathsep),
diff --git a/tests/unit/activation/test_activation_support.py b/tests/unit/activation/test_activation_support.py
index 5a234f9..d493c23 100644
--- a/tests/unit/activation/test_activation_support.py
+++ b/tests/unit/activation/test_activation_support.py
@@ -13,8 +13,6 @@ from virtualenv.activation import (
PythonActivator,
)
from virtualenv.discovery.py_info import PythonInfo
-from virtualenv.info import IS_WIN
-from virtualenv.util.path import Path
@pytest.mark.parametrize(
@@ -55,45 +53,3 @@ def test_activator_no_support_posix(mocker, activator_class):
interpreter = mocker.Mock(spec=PythonInfo)
interpreter.os = "posix"
assert not activator.supports(interpreter)
-
-
-class Creator:
- def __init__(self):
- self.dest = "C:/tools/msys64/home"
- self.env_name = "venv"
- self.bin_dir = Path("C:/tools/msys64/home/bin")
-
-
-@pytest.mark.skipif(IS_WIN, reason="Github Actions ships with WSL bash")
-@pytest.mark.parametrize("activator_class", [BashActivator])
-def test_cygwin_msys2_path_conversion(mocker, activator_class):
- mocker.patch("sysconfig.get_platform", return_value="mingw")
- activator = activator_class(Namespace(prompt=None))
- creator = Creator()
- mocker.stub(creator.bin_dir.relative_to)
- resource = activator.replacements(creator, "")
- assert resource["__VIRTUAL_ENV__"] == "/c/tools/msys64/home"
-
-
-@pytest.mark.skipif(IS_WIN, reason="Github Actions ships with WSL bash")
-@pytest.mark.parametrize("activator_class", [BashActivator])
-def test_win_path_no_conversion(mocker, activator_class):
- mocker.patch("sysconfig.get_platform", return_value="win-amd64")
- activator = activator_class(Namespace(prompt=None))
- creator = Creator()
- mocker.stub(creator.bin_dir.relative_to)
- resource = activator.replacements(creator, "")
- assert resource["__VIRTUAL_ENV__"] == "C:/tools/msys64/home"
-
-
-@pytest.mark.skipif(IS_WIN, reason="Github Actions ships with WSL bash")
-@pytest.mark.parametrize("activator_class", [BashActivator])
-def test_cygwin_path_no_conversion(mocker, activator_class):
- mocker.patch("sysconfig.get_platform", return_value="cygwin")
- activator = activator_class(Namespace(prompt=None))
- creator = Creator()
- creator.dest = "/c/tools/msys64/home"
- creator.bin_dir = Path("/c/tools/msys64/home/bin")
- mocker.stub(creator.bin_dir.relative_to)
- resource = activator.replacements(creator, "")
- assert resource["__VIRTUAL_ENV__"] == "/c/tools/msys64/home"