Skip to content

Commit

Permalink
Normalize path before hashing so that the generated venv name is inde…
Browse files Browse the repository at this point in the history
…pendent of case on case insensitive file systems
  • Loading branch information
radoering committed Nov 22, 2021
1 parent cdbacd6 commit 18d7246
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/poetry/utils/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,8 @@ def get_base_prefix(cls) -> Path:
def generate_env_name(cls, name: str, cwd: 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 f"{sanitized_name}-{h}"
Expand Down
12 changes: 12 additions & 0 deletions tests/utils/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import shutil
import subprocess
import sys
import tempfile

from pathlib import Path
from typing import Any
Expand Down Expand Up @@ -1120,3 +1121,14 @@ def test_create_venv_accepts_fallback_version_w_nonzero_patchlevel(
with_setuptools=True,
with_wheel=True,
)


def test_generate_env_name_ignores_case_for_case_insensitive_fs(tmp_dir):
venv_name1 = EnvManager.generate_env_name("simple-project", "MyDiR")
venv_name2 = EnvManager.generate_env_name("simple-project", "mYdIr")
with tempfile.NamedTemporaryFile(prefix="TmP") as tmp_file:
is_case_insensitive_fs = os.path.exists(tmp_file.name.lower())
if is_case_insensitive_fs:
assert venv_name1 == venv_name2
else:
assert venv_name1 != venv_name2

0 comments on commit 18d7246

Please sign in to comment.