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/2978.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Revert out changes related to the extraction of the discovery module - by :user:`gaborbernat`.
9 changes: 0 additions & 9 deletions src/virtualenv/cache/__init__.py

This file was deleted.

62 changes: 0 additions & 62 deletions src/virtualenv/cache/cache.py

This file was deleted.

47 changes: 0 additions & 47 deletions src/virtualenv/cache/file_cache.py

This file was deleted.

2 changes: 1 addition & 1 deletion src/virtualenv/create/via_global_ref/venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Venv(ViaGlobalRefApi):
def __init__(self, options, interpreter) -> None:
self.describe = options.describe
super().__init__(options, interpreter)
current = PythonInfo.current(options.app_data, options.cache)
current = PythonInfo.current()
self.can_be_inline = interpreter is current and interpreter.executable == interpreter.system_executable
self._context = None

Expand Down
23 changes: 0 additions & 23 deletions src/virtualenv/discovery/app_data.py

This file was deleted.

53 changes: 15 additions & 38 deletions src/virtualenv/discovery/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@

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

if TYPE_CHECKING:
from argparse import ArgumentParser
from collections.abc import Callable, Generator, Iterable, Mapping, Sequence

from .app_data import AppData
from virtualenv.app_data.base import AppData
LOGGER = logging.getLogger(__name__)


Expand All @@ -27,8 +28,8 @@ class Builtin(Discover):
app_data: AppData
try_first_with: Sequence[str]

def __init__(self, options, cache=None) -> None:
super().__init__(options, cache)
def __init__(self, options) -> None:
super().__init__(options)
self.python_spec = options.python or [sys.executable]
if self._env.get("VIRTUALENV_PYTHON"):
self.python_spec = self.python_spec[1:] + self.python_spec[:1] # Rotate the list
Expand Down Expand Up @@ -60,7 +61,7 @@ def add_parser_arguments(cls, parser: ArgumentParser) -> None:

def run(self) -> PythonInfo | None:
for python_spec in self.python_spec:
result = get_interpreter(python_spec, self.try_first_with, self.app_data, self.cache, self._env)
result = get_interpreter(python_spec, self.try_first_with, self.app_data, self._env)
if result is not None:
return result
return None
Expand All @@ -71,36 +72,13 @@ def __repr__(self) -> str:


def get_interpreter(
key,
try_first_with: Iterable[str],
app_data: AppData | None = None,
cache=None,
env: Mapping[str, str] | None = None,
key, try_first_with: Iterable[str], app_data: AppData | None = None, env: Mapping[str, str] | None = None
) -> PythonInfo | None:
"""
Find an interpreter that matches a given specification.

:param key: the specification of the interpreter to find
:param try_first_with: a list of interpreters to try first
:param app_data: the application data folder
:param cache: a cache of python information
:param env: the environment to use
:return: the interpreter if found, otherwise None
"""
if cache is None:
# Import locally to avoid a circular dependency
from virtualenv.app_data import AppDataDisabled # noqa: PLC0415
from virtualenv.cache import FileCache # noqa: PLC0415

if app_data is None:
app_data = AppDataDisabled()
cache = FileCache(store_factory=app_data.py_info, clearer=app_data.py_info_clear)

spec = PythonSpec.from_string_spec(key)
LOGGER.info("find interpreter for spec %r", spec)
proposed_paths = set()
env = os.environ if env is None else env
for interpreter, impl_must_match in propose_interpreters(spec, try_first_with, app_data, cache, env):
for interpreter, impl_must_match in propose_interpreters(spec, try_first_with, app_data, env):
key = interpreter.system_executable, impl_must_match
if key in proposed_paths:
continue
Expand All @@ -116,7 +94,6 @@ def propose_interpreters( # noqa: C901, PLR0912, PLR0915
spec: PythonSpec,
try_first_with: Iterable[str],
app_data: AppData | None = None,
cache=None,
env: Mapping[str, str] | None = None,
) -> Generator[tuple[PythonInfo, bool], None, None]:
# 0. if it's a path and exists, and is absolute path, this is the only option we consider
Expand All @@ -132,7 +109,7 @@ def propose_interpreters( # noqa: C901, PLR0912, PLR0915
exe_id = fs_path_id(exe_raw)
if exe_id not in tested_exes:
tested_exes.add(exe_id)
yield PythonInfo.from_exe(exe_raw, app_data, cache, env=env), True
yield PythonInfo.from_exe(exe_raw, app_data, env=env), True
return

# 1. try with first
Expand All @@ -148,7 +125,7 @@ def propose_interpreters( # noqa: C901, PLR0912, PLR0915
if exe_id in tested_exes:
continue
tested_exes.add(exe_id)
yield PythonInfo.from_exe(exe_raw, app_data, cache, env=env), True
yield PythonInfo.from_exe(exe_raw, app_data, env=env), True

# 1. if it's a path and exists
if spec.path is not None:
Expand All @@ -161,12 +138,12 @@ def propose_interpreters( # noqa: C901, PLR0912, PLR0915
exe_id = fs_path_id(exe_raw)
if exe_id not in tested_exes:
tested_exes.add(exe_id)
yield PythonInfo.from_exe(exe_raw, app_data, cache, env=env), True
yield PythonInfo.from_exe(exe_raw, app_data, env=env), True
if spec.is_abs:
return
else:
# 2. otherwise try with the current
current_python = PythonInfo.current_system(app_data, cache)
current_python = PythonInfo.current_system(app_data)
exe_raw = str(current_python.executable)
exe_id = fs_path_id(exe_raw)
if exe_id not in tested_exes:
Expand All @@ -177,7 +154,7 @@ def propose_interpreters( # noqa: C901, PLR0912, PLR0915
if IS_WIN:
from .windows import propose_interpreters # noqa: PLC0415

for interpreter in propose_interpreters(spec, app_data, cache, env):
for interpreter in propose_interpreters(spec, app_data, env):
exe_raw = str(interpreter.executable)
exe_id = fs_path_id(exe_raw)
if exe_id in tested_exes:
Expand All @@ -195,7 +172,7 @@ def propose_interpreters( # noqa: C901, PLR0912, PLR0915
if exe_id in tested_exes:
continue
tested_exes.add(exe_id)
interpreter = PathPythonInfo.from_exe(exe_raw, app_data, cache, raise_on_error=False, env=env)
interpreter = PathPythonInfo.from_exe(exe_raw, app_data, raise_on_error=False, env=env)
if interpreter is not None:
yield interpreter, impl_must_match

Expand All @@ -208,7 +185,7 @@ def propose_interpreters( # noqa: C901, PLR0912, PLR0915
uv_python_path = user_data_path("uv") / "python"

for exe_path in uv_python_path.glob("*/bin/python"):
interpreter = PathPythonInfo.from_exe(str(exe_path), app_data, cache, raise_on_error=False, env=env)
interpreter = PathPythonInfo.from_exe(str(exe_path), app_data, raise_on_error=False, env=env)
if interpreter is not None:
yield interpreter, True

Expand Down
18 changes: 0 additions & 18 deletions src/virtualenv/discovery/cache.py

This file was deleted.

Loading
Loading