Skip to content

Commit 18d7246

Browse files
committed
Normalize path before hashing so that the generated venv name is independent of case on case insensitive file systems
1 parent cdbacd6 commit 18d7246

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/poetry/utils/env.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,8 @@ def get_base_prefix(cls) -> Path:
10721072
def generate_env_name(cls, name: str, cwd: str) -> str:
10731073
name = name.lower()
10741074
sanitized_name = re.sub(r'[ $`!*@"\\\r\n\t]', "_", name)[:42]
1075-
h = hashlib.sha256(encode(cwd)).digest()
1075+
normalized_cwd = os.path.normcase(cwd)
1076+
h = hashlib.sha256(encode(normalized_cwd)).digest()
10761077
h = base64.urlsafe_b64encode(h).decode()[:8]
10771078

10781079
return f"{sanitized_name}-{h}"

tests/utils/test_env.py

+12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import shutil
33
import subprocess
44
import sys
5+
import tempfile
56

67
from pathlib import Path
78
from typing import Any
@@ -1120,3 +1121,14 @@ def test_create_venv_accepts_fallback_version_w_nonzero_patchlevel(
11201121
with_setuptools=True,
11211122
with_wheel=True,
11221123
)
1124+
1125+
1126+
def test_generate_env_name_ignores_case_for_case_insensitive_fs(tmp_dir):
1127+
venv_name1 = EnvManager.generate_env_name("simple-project", "MyDiR")
1128+
venv_name2 = EnvManager.generate_env_name("simple-project", "mYdIr")
1129+
with tempfile.NamedTemporaryFile(prefix="TmP") as tmp_file:
1130+
is_case_insensitive_fs = os.path.exists(tmp_file.name.lower())
1131+
if is_case_insensitive_fs:
1132+
assert venv_name1 == venv_name2
1133+
else:
1134+
assert venv_name1 != venv_name2

0 commit comments

Comments
 (0)