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/2074c.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Decouple discovery from creator plugins - by :user:`esafak`.
13 changes: 2 additions & 11 deletions src/virtualenv/discovery/py_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def _get_path_extensions():
_CONF_VAR_RE = re.compile(r"\{\w+\}")


class PythonInfo: # noqa: PLR0904
class PythonInfo:
"""Contains information for a Python interpreter."""

def __init__(self) -> None: # noqa: PLR0915
Expand Down Expand Up @@ -135,7 +135,6 @@ def abs_path(v):
self.system_stdlib = self.sysconfig_path("stdlib", confs)
self.system_stdlib_platform = self.sysconfig_path("platstdlib", confs)
self.max_size = getattr(sys, "maxsize", getattr(sys, "maxint", None))
self._creators = None

@staticmethod
def _get_tcl_tk_libs():
Expand Down Expand Up @@ -311,13 +310,6 @@ def sysconfig_path(self, key, config_var=None, sep=os.sep):
config_var = base
return pattern.format(**config_var).replace("/", sep)

def creators(self, refresh=False): # noqa: FBT002
if self._creators is None or refresh is True:
from virtualenv.run.plugin.creators import CreatorSelector # noqa: PLC0415

self._creators = CreatorSelector.for_interpreter(self)
return self._creators

@property
def system_include(self):
path = self.sysconfig_path(
Expand Down Expand Up @@ -467,8 +459,7 @@ def _to_json(self):
return json.dumps(self._to_dict(), indent=2)

def _to_dict(self):
data = {var: (getattr(self, var) if var != "_creators" else None) for var in vars(self)}

data = {var: getattr(self, var) for var in vars(self)}
data["version_info"] = data["version_info"]._asdict() # namedtuple to dictionary
return data

Expand Down
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from virtualenv.discovery.py_info import PythonInfo
from virtualenv.info import IS_GRAALPY, IS_PYPY, IS_WIN, fs_supports_symlink
from virtualenv.report import LOGGER
from virtualenv.run.plugin.creators import CreatorSelector


def pytest_addoption(parser):
Expand Down Expand Up @@ -308,7 +309,7 @@ def special_name_dir(tmp_path, special_char_name):

@pytest.fixture(scope="session")
def current_creators(session_app_data):
return PythonInfo.current_system(session_app_data).creators()
return CreatorSelector.for_interpreter(PythonInfo.current_system(session_app_data))


@pytest.fixture(scope="session")
Expand Down
10 changes: 7 additions & 3 deletions tests/unit/create/test_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from virtualenv.discovery.py_info import PythonInfo
from virtualenv.info import IS_PYPY, IS_WIN, fs_is_case_sensitive
from virtualenv.run import cli_run, session_via_cli
from virtualenv.run.plugin.creators import CreatorSelector

CURRENT = PythonInfo.current_system()

Expand Down Expand Up @@ -93,9 +94,9 @@ def system(session_app_data):
return get_env_debug_info(Path(CURRENT.system_executable), DEBUG_SCRIPT, session_app_data, os.environ)


CURRENT_CREATORS = [i for i in CURRENT.creators().key_to_class if i != "builtin"]
CURRENT_CREATORS = [i for i in CreatorSelector.for_interpreter(CURRENT).key_to_class if i != "builtin"]
CREATE_METHODS = []
for k, v in CURRENT.creators().key_to_meta.items():
for k, v in CreatorSelector.for_interpreter(CURRENT).key_to_meta.items():
if k in CURRENT_CREATORS:
if v.can_copy:
if k == "venv" and CURRENT.implementation == "PyPy" and CURRENT.pypy_version_info >= [7, 3, 13]:
Expand Down Expand Up @@ -400,7 +401,10 @@ def test_create_long_path(tmp_path):


@pytest.mark.slow
@pytest.mark.parametrize("creator", sorted(set(PythonInfo.current_system().creators().key_to_class) - {"builtin"}))
@pytest.mark.parametrize(
"creator",
sorted(set(CreatorSelector.for_interpreter(PythonInfo.current_system()).key_to_class) - {"builtin"}),
)
@pytest.mark.usefixtures("session_app_data")
def test_create_distutils_cfg(creator, tmp_path, monkeypatch):
result = cli_run(
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/create/via_global_ref/test_build_c_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@

from virtualenv.discovery.py_info import PythonInfo
from virtualenv.run import cli_run
from virtualenv.run.plugin.creators import CreatorSelector

CURRENT = PythonInfo.current_system()
CREATOR_CLASSES = CURRENT.creators().key_to_class
CREATOR_CLASSES = CreatorSelector.for_interpreter(CURRENT).key_to_class


def builtin_shows_marker_missing():
Expand Down