Skip to content

Commit

Permalink
normalize path if it is a case insensitive file system
Browse files Browse the repository at this point in the history
close python-poetry#2419(Virtualenv not always found in case insensitive filesystem)
the util func for checking whether it is a case sentive
or not is from [Steve Cohen](https://stackoverflow.com/a/36580834/7899226)
  • Loading branch information
dongho-jung committed May 14, 2020
1 parent 621f698 commit d00a79e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
3 changes: 2 additions & 1 deletion poetry/utils/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,8 @@ def get_base_prefix(self): # type: () -> Path
def generate_env_name(cls, name, cwd): # type: (str, str) -> str
name = name.lower()
sanitized_name = re.sub(r'[ $`!*@"\\\r\n\t]', "_", name)[:42]
h = hashlib.sha256(encode(cwd)).digest()
normalized_cwd = os.path.normcase(cwd)
h = hashlib.sha256(encode(normalized_cwd)).digest()
h = base64.urlsafe_b64encode(h).decode()[:8]

return "{}-{}".format(sanitized_name, h)
Expand Down
21 changes: 21 additions & 0 deletions tests/utils/test_env.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import shutil
import sys
import tempfile

import pytest
import tomlkit
Expand Down Expand Up @@ -831,3 +832,23 @@ def test_env_site_packages_should_raise_an_error_if_no_site_packages(tmp_dir):

with pytest.raises(RuntimeError):
env.site_packages


def test_case_should_be_ignored_if_fs_is_case_sensitive(tmp_dir):
with tempfile.NamedTemporaryFile(prefix="TmP") as tmp_file:
if not os.path.exists(tmp_file.name.lower()):
path_with_lowercase = Path(tmp_dir) / "lowerpath"
path_with_uppercase = Path(tmp_dir) / "UPPERPATH"
path_with_bothcase = Path(tmp_dir) / "BoThCaSe"

venv_with_lowercase = EnvManager.generate_env_name(
"simple-project", str(path_with_lowercase)
)
venv_with_uppercase = EnvManager.generate_env_name(
"simple-project", str(path_with_uppercase)
)
venv_with_bothcase = EnvManager.generate_env_name(
"simple-project", str(path_with_bothcase)
)

assert venv_with_lowercase != venv_with_uppercase != venv_with_bothcase

0 comments on commit d00a79e

Please sign in to comment.