Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog/2074d.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Decouple discovery by duplicating info utils - by :user:`esafak`.
3 changes: 1 addition & 2 deletions src/virtualenv/discovery/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@

from platformdirs import user_data_path

from virtualenv.info import IS_WIN, fs_path_id

from .discover import Discover
from .info import IS_WIN, fs_path_id
from .py_info import PythonInfo
from .py_spec import PythonSpec

Expand Down
5 changes: 2 additions & 3 deletions src/virtualenv/discovery/cached_py_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
import logging
import os
import random
import subprocess
import sys
from collections import OrderedDict
from pathlib import Path
from shlex import quote
from string import ascii_lowercase, ascii_uppercase, digits
from subprocess import Popen
from typing import TYPE_CHECKING

from virtualenv.app_data.na import AppDataDisabled
Expand All @@ -27,7 +27,6 @@
from virtualenv.app_data.base import AppData
from virtualenv.cache import Cache
from virtualenv.discovery.py_info import PythonInfo
from virtualenv.util.subprocess import subprocess

_CACHE = OrderedDict()
_CACHE[Path(sys.executable)] = PythonInfo()
Expand Down Expand Up @@ -145,7 +144,7 @@ def _run_subprocess(cls, exe, app_data, env):
env.pop("__PYVENV_LAUNCHER__", None)
LOGGER.debug("get interpreter info via cmd: %s", LogCmd(cmd))
try:
process = Popen(
process = subprocess.Popen(
cmd,
universal_newlines=True,
stdin=subprocess.PIPE,
Expand Down
33 changes: 33 additions & 0 deletions src/virtualenv/discovery/info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from __future__ import annotations

import logging
import os
import sys
import tempfile

_FS_CASE_SENSITIVE = None
LOGGER = logging.getLogger(__name__)
IS_WIN = sys.platform == "win32"


def fs_is_case_sensitive():
"""Check if the file system is case-sensitive."""
global _FS_CASE_SENSITIVE # noqa: PLW0603

if _FS_CASE_SENSITIVE is None:
with tempfile.NamedTemporaryFile(prefix="TmP") as tmp_file:
_FS_CASE_SENSITIVE = not os.path.exists(tmp_file.name.lower())
LOGGER.debug("filesystem is %scase-sensitive", "" if _FS_CASE_SENSITIVE else "not ")
return _FS_CASE_SENSITIVE


def fs_path_id(path: str) -> str:
"""Get a case-normalized path identifier."""
return path.casefold() if fs_is_case_sensitive() else path


__all__ = (
"IS_WIN",
"fs_is_case_sensitive",
"fs_path_id",
)
3 changes: 2 additions & 1 deletion src/virtualenv/discovery/py_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,8 @@ def _possible_base(self):
for base in possible_base:
lower = base.lower()
yield lower
from virtualenv.info import fs_is_case_sensitive # noqa: PLC0415

from .info import fs_is_case_sensitive # noqa: PLC0415

if fs_is_case_sensitive():
if base != lower:
Expand Down
Loading