Skip to content

Commit cedd574

Browse files
committed
Remove auto-install support from PluginLoader
1 parent 7c866ab commit cedd574

File tree

6 files changed

+18
-111
lines changed

6 files changed

+18
-111
lines changed

tests/plugins/test_loader.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ def test_load_plugin_invalid_arg() -> None:
446446
],
447447
)
448448
def test_load_plugins_from_variant_info(variant_info: VariantInfo) -> None:
449-
with PluginLoader(variant_info, use_auto_install=False) as loader:
449+
with PluginLoader(variant_info) as loader:
450450
assert set(loader.namespaces) == {"test_namespace", "second_namespace"}
451451

452452

@@ -474,9 +474,7 @@ def test_plugin_in_venv(test_plugin_package_req: str) -> None:
474474

475475
with DefaultIsolatedEnv() as venv:
476476
venv.install([test_plugin_package_req])
477-
with PluginLoader(
478-
variant_info, use_auto_install=False, venv_path=Path(venv.path)
479-
) as loader:
477+
with PluginLoader(variant_info, venv_path=Path(venv.path)) as loader:
480478
assert set(loader.namespaces) == {"installable_plugin"}
481479

482480

@@ -496,7 +494,7 @@ def test_no_plugin_api(
496494
},
497495
)
498496

499-
with PluginLoader(variant_info, use_auto_install=False) as loader:
497+
with PluginLoader(variant_info) as loader:
500498
assert set(loader.namespaces) == {"installable_plugin"}
501499

502500

@@ -532,16 +530,14 @@ def test_optional_plugins(value: bool | list[VariantNamespace], expected: bool)
532530
expected_namespaces = {"test_namespace"}
533531
if expected:
534532
expected_namespaces.add("second_namespace")
535-
with PluginLoader(
536-
variant_info, use_auto_install=False, enable_optional_plugins=value
537-
) as loader:
533+
with PluginLoader(variant_info, enable_optional_plugins=value) as loader:
538534
assert set(loader.namespaces) == expected_namespaces
539535

540536

541537
@pytest.mark.parametrize(
542538
"loader_call",
543539
[
544-
partial(PluginLoader, VariantInfo(), use_auto_install=False),
540+
partial(PluginLoader, VariantInfo()),
545541
partial(ListPluginLoader, []),
546542
],
547543
)
@@ -582,7 +578,5 @@ def test_filter_plugins(value: list[VariantNamespace]) -> None:
582578

583579
expected_namespaces = set(value)
584580
expected_namespaces.discard("frobnicate")
585-
with PluginLoader(
586-
variant_info, use_auto_install=False, filter_plugins=value
587-
) as loader:
581+
with PluginLoader(variant_info, filter_plugins=value) as loader:
588582
assert set(loader.namespaces) == expected_namespaces

tests/test_api.py

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ def test_get_variant_hashes_by_priority_roundtrip(
119119

120120
# variants_json = VariantsJson(typed_variants_json)
121121

122-
assert get_variant_hashes_by_priority(
123-
variants_json=typed_variants_json, use_auto_install=False, venv_path=None
124-
) == [vdesc.hexdigest for vdesc in combinations]
122+
assert get_variant_hashes_by_priority(variants_json=typed_variants_json) == [
123+
vdesc.hexdigest for vdesc in combinations
124+
]
125125

126126

127127
@settings(deadline=None, suppress_health_check=[HealthCheck.function_scoped_fixture])
@@ -210,9 +210,9 @@ def get_or_skip_combinations() -> Generator[VariantDescription]:
210210
"variantlib.plugins.loader.BasePluginLoader.get_supported_configs"
211211
).return_value = {provider_cfg.namespace: provider_cfg for provider_cfg in configs}
212212

213-
assert get_variant_hashes_by_priority(
214-
variants_json=typed_variants_json, use_auto_install=False, venv_path=None
215-
) == [vdesc.hexdigest for vdesc in combinations]
213+
assert get_variant_hashes_by_priority(variants_json=typed_variants_json) == [
214+
vdesc.hexdigest for vdesc in combinations
215+
]
216216

217217

218218
@pytest.mark.parametrize(
@@ -306,7 +306,6 @@ def test_validate_variant(mocked_plugin_apis: list[str], optional: bool) -> None
306306
]
307307
),
308308
variant_info=variant_info,
309-
use_auto_install=False,
310309
)
311310

312311
assert res == VariantValidationResult(
@@ -452,12 +451,7 @@ def test_check_variant_supported_dist(
452451
) -> None:
453452
variant_json = VariantsJson(common_variant_info)
454453
variant_json.variants[vdesc.hexdigest] = vdesc
455-
assert (
456-
check_variant_supported(
457-
variant_info=variant_json, use_auto_install=False, venv_path=None
458-
)
459-
is expected
460-
)
454+
assert check_variant_supported(variant_info=variant_json) is expected
461455

462456

463457
def test_check_variant_supported_generic() -> None:
@@ -478,8 +472,6 @@ def test_check_variant_supported_generic() -> None:
478472
assert check_variant_supported(
479473
vdesc=VariantDescription(),
480474
variant_info=variant_info,
481-
use_auto_install=False,
482-
venv_path=None,
483475
)
484476

485477
# test a supported variant
@@ -491,16 +483,12 @@ def test_check_variant_supported_generic() -> None:
491483
]
492484
),
493485
variant_info=variant_info,
494-
use_auto_install=False,
495-
venv_path=None,
496486
)
497487

498488
# test an usupported variant
499489
assert not check_variant_supported(
500490
vdesc=VariantDescription([VariantProperty("test_namespace", "name1", "val1c")]),
501491
variant_info=variant_info,
502-
use_auto_install=False,
503-
venv_path=None,
504492
)
505493

506494

variantlib/api.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@
4747
def get_variant_hashes_by_priority(
4848
*,
4949
variants_json: VariantsJsonDict | VariantsJson,
50-
use_auto_install: bool = True,
51-
isolated: bool = True,
5250
venv_path: str | pathlib.Path | None = None,
5351
enable_optional_plugins: bool | list[VariantNamespace] = False,
5452
) -> list[str]:
@@ -60,8 +58,6 @@ def get_variant_hashes_by_priority(
6058

6159
with PluginLoader(
6260
variant_info=variants_json,
63-
use_auto_install=use_auto_install,
64-
isolated=isolated,
6561
venv_path=venv_path,
6662
enable_optional_plugins=enable_optional_plugins,
6763
) as plugin_loader:
@@ -98,8 +94,6 @@ def get_variant_hashes_by_priority(
9894
def validate_variant(
9995
variant_desc: VariantDescription,
10096
variant_info: VariantInfo,
101-
use_auto_install: bool = True,
102-
isolated: bool = True,
10397
venv_path: str | pathlib.Path | None = None,
10498
) -> VariantValidationResult:
10599
"""
@@ -116,8 +110,6 @@ def validate_variant(
116110

117111
with PluginLoader(
118112
variant_info=variant_info,
119-
use_auto_install=use_auto_install,
120-
isolated=isolated,
121113
venv_path=venv_path,
122114
enable_optional_plugins=True,
123115
filter_plugins=list({vprop.namespace for vprop in variant_desc.properties}),
@@ -158,8 +150,6 @@ def check_variant_supported(
158150
*,
159151
vdesc: VariantDescription | None = None,
160152
variant_info: VariantInfo,
161-
use_auto_install: bool = True,
162-
isolated: bool = True,
163153
venv_path: str | pathlib.Path | None = None,
164154
enable_optional_plugins: bool | list[VariantNamespace] = False,
165155
) -> bool:
@@ -184,8 +174,6 @@ def check_variant_supported(
184174

185175
with PluginLoader(
186176
variant_info=variant_info,
187-
use_auto_install=use_auto_install,
188-
isolated=isolated,
189177
venv_path=venv_path,
190178
enable_optional_plugins=enable_optional_plugins,
191179
) as plugin_loader:

variantlib/commands/make_variant.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ def _make_variant(
188188
vdesc_valid = validate_variant(
189189
vdesc,
190190
variant_info=variant_info,
191-
use_auto_install=False,
192191
venv_path=venv.path if venv is not None else None,
193192
)
194193
if vdesc_valid.invalid_properties:

variantlib/plugins/loader.py

Lines changed: 4 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
from packaging.markers import Marker
2020
from packaging.markers import default_environment
21-
from packaging.requirements import Requirement
2221
from variantlib.constants import VALIDATION_PROVIDER_PLUGIN_API_REGEX
2322
from variantlib.errors import NoPluginFoundError
2423
from variantlib.errors import PluginError
@@ -62,16 +61,9 @@ class BasePluginLoader:
6261

6362
def __init__(
6463
self,
65-
use_auto_install: bool,
66-
isolated: bool = True,
6764
venv_path: Path | None = None,
6865
) -> None:
69-
self._use_auto_install = use_auto_install
70-
# isolated=True is effective only with use_auto_install=True
71-
# (otherwise we'd be using empty venv)
72-
self._python_ctx_factory = partial(
73-
python_env, isolated=isolated and use_auto_install, venv_path=venv_path
74-
)
66+
self._python_ctx_factory = partial(python_env, venv_path=venv_path)
7567

7668
def __enter__(self) -> Self:
7769
if self._python_ctx is not None:
@@ -80,8 +72,6 @@ def __enter__(self) -> Self:
8072
self._python_ctx_manager = self._python_ctx_factory()
8173
self._python_ctx = self._python_ctx_manager.__enter__()
8274
try:
83-
if self._use_auto_install:
84-
self._install_all_plugins()
8575
self._load_all_plugins()
8676
except Exception:
8777
self._python_ctx_manager.__exit__(*sys.exc_info())
@@ -105,16 +95,6 @@ def __exit__(
10595
self._python_ctx = None
10696
self._python_ctx_manager.__exit__(exc_type, exc_value, traceback)
10797

108-
def _install_all_plugins(self) -> None:
109-
pass
110-
111-
def _install_all_plugins_from_reqs(self, reqs: list[str]) -> None:
112-
if self._python_ctx is None:
113-
raise RuntimeError("Context manager not entered!")
114-
115-
# Actual plugin installation
116-
self._python_ctx.install(reqs)
117-
11898
def _call_subprocess(
11999
self, plugin_apis: list[str], commands: dict[str, Any]
120100
) -> dict[str, dict[str, Any]]:
@@ -305,8 +285,6 @@ class PluginLoader(BasePluginLoader):
305285
def __init__(
306286
self,
307287
variant_info: VariantInfo,
308-
use_auto_install: bool,
309-
isolated: bool = True,
310288
venv_path: Path | None = None,
311289
enable_optional_plugins: bool | list[VariantNamespace] = False,
312290
filter_plugins: list[VariantNamespace] | None = None,
@@ -315,9 +293,7 @@ def __init__(
315293
self._enable_optional_plugins = enable_optional_plugins
316294
self._filter_plugins = filter_plugins
317295
self._environment = cast("dict[str, str]", default_environment())
318-
super().__init__(
319-
use_auto_install=use_auto_install, isolated=isolated, venv_path=venv_path
320-
)
296+
super().__init__(venv_path=venv_path)
321297

322298
def _optional_provider_enabled(self, namespace: str) -> bool:
323299
# if enable_optional_plugins is a bool, it controls all plugins
@@ -352,44 +328,6 @@ def _provider_enabled(self, namespace: str, provider_data: ProviderInfo) -> bool
352328

353329
return True
354330

355-
def _install_all_plugins(self) -> None:
356-
# Installing the plugins
357-
reqs = []
358-
for namespace, provider_data in self._variant_info.providers.items():
359-
if not self._provider_enabled(namespace, provider_data):
360-
continue
361-
362-
if not (list_req_str := provider_data.requires):
363-
logger.error(
364-
"Impossible to install the variant provider plugin corresponding "
365-
"to namespace `%(ns)s`. Missing provider requirement, "
366-
"received: %(data)s.",
367-
{"ns": namespace, "data": provider_data},
368-
)
369-
continue
370-
371-
for req_str in list_req_str:
372-
pyreq = Requirement(req_str)
373-
if not (
374-
pyreq.marker.evaluate(self._environment) if pyreq.marker else True
375-
):
376-
continue
377-
378-
# If there's at least one requirement compatible - break
379-
break
380-
else:
381-
logger.debug(
382-
"The variant provider plugin corresponding "
383-
"to namespace `%(ns)s` has been skipped - Not compatible with the "
384-
"environmment. Details: %(data)s.",
385-
{"ns": namespace, "data": provider_data},
386-
)
387-
continue
388-
389-
reqs.extend(list_req_str)
390-
391-
self._install_all_plugins_from_reqs(reqs)
392-
393331
def _load_all_plugins(self) -> None:
394332
if self._namespace_map is not None:
395333
raise RuntimeError(
@@ -412,7 +350,7 @@ def __init__(
412350
self,
413351
venv_path: Path | None = None,
414352
) -> None:
415-
super().__init__(use_auto_install=False, isolated=False, venv_path=venv_path)
353+
super().__init__(venv_path=venv_path)
416354

417355
def _load_all_plugins(self) -> None:
418356
if self._namespace_map is not None:
@@ -461,7 +399,7 @@ def __init__(
461399
venv_path: Path | None = None,
462400
) -> None:
463401
self._plugin_apis = list(plugin_apis)
464-
super().__init__(use_auto_install=False, isolated=False, venv_path=venv_path)
402+
super().__init__(venv_path=venv_path)
465403

466404
def _load_all_plugins(self) -> None:
467405
if self._namespace_map is not None:

variantlib/plugins/py_envs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def python_executable(self) -> pathlib.Path:
135135

136136
@contextmanager
137137
def python_env(
138-
isolated: bool = True, venv_path: pathlib.Path | None = None
138+
isolated: bool = False, venv_path: pathlib.Path | None = None
139139
) -> Generator[PythonEnv]:
140140
if venv_path is None and isolated:
141141
import venv

0 commit comments

Comments
 (0)