Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix absolute paths for Cygwin #1970

Merged
merged 8 commits into from
Oct 12, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/virtualenv/activation/bash/activate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ deactivate () {
# unset irrelevant variables
deactivate nondestructive

VIRTUAL_ENV="$(if [ "$OSTYPE" = "cygwin" ]; then cygpath -u '__VIRTUAL_ENV__'; else echo '__VIRTUAL_ENV__'; fi;)"
VIRTUAL_ENV='__VIRTUAL_ENV__'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for this empty line 👍

if [ "$OSTYPE" = "cygwin" ]; then
VIRTUAL_ENV=$(cygpath -u "$VIRTUAL_ENV")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should validate that cygpath is an existing command, and ignore if it fails 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested the updated code on cygwin & msys, and it works for both.

I've added the check to make sure cygpath exists before we invoke it. Do you mean that we should also ignore the error if invoking cygpath fails? I think we probably want to fail the operation in that case, don't we, since the virtualenv isn't going to work?

fi

export VIRTUAL_ENV

_OLD_VIRTUAL_PATH="$PATH"
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/activation/test_activation_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ def __init__(self):


@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")
@pytest.mark.parametrize("activator_class,platform", [(BashActivator,"mingw"),(BashActivator,"msys")])
def test_mingw_path_conversion(mocker, activator_class, platform):
mocker.patch("sysconfig.get_platform", return_value=platform)
activator = activator_class(Namespace(prompt=None))
creator = Creator()
mocker.stub(creator.bin_dir.relative_to)
Expand All @@ -87,9 +87,9 @@ def test_win_path_no_conversion(mocker, activator_class):


@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")
@pytest.mark.parametrize("activator_class,platform", [(BashActivator,"mingw"),(BashActivator,"msys")])
def test_mingw_path_no_conversion(mocker, activator_class, platform):
mocker.patch("sysconfig.get_platform", return_value=platform)
activator = activator_class(Namespace(prompt=None))
creator = Creator()
creator.dest = "/c/tools/msys64/home"
Expand Down