Skip to content

Commit

Permalink
Fix cygwin NoneType error if POSIX path in dest (#1964)
Browse files Browse the repository at this point in the history
Closes #1962. Corrects an AttributeError for a regex match not
found if the cygwin path is already in posix format.
  • Loading branch information
danyeaw authored Oct 3, 2020
1 parent 59277f0 commit adcf327
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/changelog/1962.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix Nonetype error in cygwin if POSIX path in dest - by :user:`danyeaw`.
5 changes: 4 additions & 1 deletion src/virtualenv/activation/via_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ def replacements(self, creator, dest_folder):
if any(platform in current_platform for platform in platforms):
pattern = re.compile("^([A-Za-z]):(.*)")
match = pattern.match(str(creator.dest))
virtual_env = "/" + match.group(1).lower() + match.group(2)
if match:
virtual_env = "/" + match.group(1).lower() + match.group(2)
else:
virtual_env = str(creator.dest)
else:
virtual_env = str(creator.dest)
return {
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/activation/test_activation_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,16 @@ def test_win_path_no_conversion(mocker, activator_class):
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"

0 comments on commit adcf327

Please sign in to comment.