Skip to content

Commit 1f4c76e

Browse files
authored
refactor: Decouple discovery by duplicating info utils (#2951)
1 parent c41da72 commit 1f4c76e

File tree

5 files changed

+39
-6
lines changed

5 files changed

+39
-6
lines changed

docs/changelog/2074d.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Decouple discovery by duplicating info utils - by :user:`esafak`.

src/virtualenv/discovery/builtin.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@
99

1010
from platformdirs import user_data_path
1111

12-
from virtualenv.info import IS_WIN, fs_path_id
13-
1412
from .discover import Discover
13+
from .info import IS_WIN, fs_path_id
1514
from .py_info import PythonInfo
1615
from .py_spec import PythonSpec
1716

src/virtualenv/discovery/cached_py_info.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
import logging
1313
import os
1414
import random
15+
import subprocess
1516
import sys
1617
from collections import OrderedDict
1718
from pathlib import Path
1819
from shlex import quote
1920
from string import ascii_lowercase, ascii_uppercase, digits
20-
from subprocess import Popen
2121
from typing import TYPE_CHECKING
2222

2323
from virtualenv.app_data.na import AppDataDisabled
@@ -27,7 +27,6 @@
2727
from virtualenv.app_data.base import AppData
2828
from virtualenv.cache import Cache
2929
from virtualenv.discovery.py_info import PythonInfo
30-
from virtualenv.util.subprocess import subprocess
3130

3231
_CACHE = OrderedDict()
3332
_CACHE[Path(sys.executable)] = PythonInfo()
@@ -145,7 +144,7 @@ def _run_subprocess(cls, exe, app_data, env):
145144
env.pop("__PYVENV_LAUNCHER__", None)
146145
LOGGER.debug("get interpreter info via cmd: %s", LogCmd(cmd))
147146
try:
148-
process = Popen(
147+
process = subprocess.Popen(
149148
cmd,
150149
universal_newlines=True,
151150
stdin=subprocess.PIPE,

src/virtualenv/discovery/info.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from __future__ import annotations
2+
3+
import logging
4+
import os
5+
import sys
6+
import tempfile
7+
8+
_FS_CASE_SENSITIVE = None
9+
LOGGER = logging.getLogger(__name__)
10+
IS_WIN = sys.platform == "win32"
11+
12+
13+
def fs_is_case_sensitive():
14+
"""Check if the file system is case-sensitive."""
15+
global _FS_CASE_SENSITIVE # noqa: PLW0603
16+
17+
if _FS_CASE_SENSITIVE is None:
18+
with tempfile.NamedTemporaryFile(prefix="TmP") as tmp_file:
19+
_FS_CASE_SENSITIVE = not os.path.exists(tmp_file.name.lower())
20+
LOGGER.debug("filesystem is %scase-sensitive", "" if _FS_CASE_SENSITIVE else "not ")
21+
return _FS_CASE_SENSITIVE
22+
23+
24+
def fs_path_id(path: str) -> str:
25+
"""Get a case-normalized path identifier."""
26+
return path.casefold() if fs_is_case_sensitive() else path
27+
28+
29+
__all__ = (
30+
"IS_WIN",
31+
"fs_is_case_sensitive",
32+
"fs_path_id",
33+
)

src/virtualenv/discovery/py_info.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,8 @@ def _possible_base(self):
659659
for base in possible_base:
660660
lower = base.lower()
661661
yield lower
662-
from virtualenv.info import fs_is_case_sensitive # noqa: PLC0415
662+
663+
from .info import fs_is_case_sensitive # noqa: PLC0415
663664

664665
if fs_is_case_sensitive():
665666
if base != lower:

0 commit comments

Comments
 (0)