Skip to content

Commit 05e466f

Browse files
committed
Normalize provider install roots and fix prek
1 parent ae69581 commit 05e466f

60 files changed

Lines changed: 2537 additions & 3575 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

PLAN.md

Lines changed: 0 additions & 27 deletions
This file was deleted.

README.md

Lines changed: 41 additions & 34 deletions
Large diffs are not rendered by default.

abx_pkg/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
BinaryOperationError,
2828
BinaryInstallError,
2929
BinaryLoadError,
30-
BinaryLoadOrInstallError,
3130
BinaryUpdateError,
3231
BinaryUninstallError,
3332
)
@@ -138,7 +137,6 @@ def __getattr__(name: str):
138137
"BinaryOperationError",
139138
"BinaryInstallError",
140139
"BinaryLoadError",
141-
"BinaryLoadOrInstallError",
142140
"BinaryUpdateError",
143141
"BinaryUninstallError",
144142
# Helper Types

abx_pkg/base_types.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
from pydantic import TypeAdapter, AfterValidator, BeforeValidator, ValidationError
1414

1515

16-
# Read once at import time. When set, every provider with an
17-
# ``INSTALL_ROOT_FIELD`` defaults its install root to
18-
# ``ABX_PKG_LIB_DIR / <provider name>`` (e.g. ``<lib>/npm``,
19-
# ``<lib>/pip``, ``<lib>/gem``). Per-provider ``ABX_PKG_<NAME>_ROOT``
20-
# env vars override this for their own provider; explicit constructor
21-
# kwargs override both.
16+
# Read once at import time. When set, providers that opt into
17+
# ``abx_pkg_install_root_default("<provider>")`` default their
18+
# ``install_root`` to ``ABX_PKG_LIB_DIR / <provider name>`` (e.g.
19+
# ``<lib>/npm``, ``<lib>/pip``, ``<lib>/gem``). Per-provider
20+
# ``ABX_PKG_<NAME>_ROOT`` env vars override this for their own
21+
# provider; explicit constructor kwargs override both.
2222
DEFAULT_LIB_DIR: Path = user_config_path("abx") / "lib"
2323

2424
_lib_dir_env = os.environ.get("ABX_PKG_LIB_DIR", "").strip()

abx_pkg/binary.py

Lines changed: 20 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
from .exceptions import (
2222
BinaryInstallError,
2323
BinaryLoadError,
24-
BinaryLoadOrInstallError,
2524
BinaryUpdateError,
2625
BinaryUninstallError,
2726
)
@@ -244,7 +243,7 @@ def _validated_loaded_copy(
244243
245244
Providers can legitimately resolve a binary that still fails this
246245
Binary's declared version floor. Keeping the final validation here makes
247-
install/load/load_or_install/update all share one consistent check.
246+
install/load/update all share one consistent check.
248247
"""
249248
result = self.model_copy(
250249
deep=True,
@@ -266,21 +265,29 @@ def _validated_loaded_copy(
266265
def install(
267266
self,
268267
binproviders: list[BinProviderName] | None = None,
268+
no_cache: bool = False,
269269
dry_run: bool | None = None,
270270
postinstall_scripts: bool | None = None,
271271
min_release_age: float | None = None,
272272
**extra_overrides,
273273
) -> Self:
274274
assert self.name, f"No binary name was provided! {self}"
275275

276+
if self.is_valid and not no_cache:
277+
logger.debug(
278+
"Skipping install for %s because it is already valid",
279+
self.name,
280+
)
281+
return self
282+
276283
if binproviders is not None and len(list(binproviders)) == 0:
277284
logger.debug(
278285
"Skipping install for %s because binproviders list was empty",
279286
self.name,
280287
)
281288
return self
282289

283-
logger.info("Installing %s binary", self.name)
290+
# logger.info("Installing %s binary", self.name)
284291
inner_exc: Exception | None = None
285292
errors = {}
286293
postinstall_scripts = (
@@ -304,6 +311,7 @@ def install(
304311
)
305312
installed_bin = provider.install(
306313
self.name,
314+
no_cache=no_cache,
307315
dry_run=dry_run,
308316
postinstall_scripts=postinstall_scripts,
309317
min_release_age=min_release_age,
@@ -332,7 +340,7 @@ def install(
332340
def load(
333341
self,
334342
binproviders: list[BinProviderName] | None = None,
335-
nocache=False,
343+
no_cache=False,
336344
**extra_overrides,
337345
) -> Self:
338346
assert self.name, f"No binary name was provided! {self}"
@@ -350,7 +358,7 @@ def load(
350358
)
351359
return self
352360

353-
logger.info("Loading %s binary", self.name)
361+
# logger.info("Loading %s binary", self.name)
354362
inner_exc: Exception | None = None
355363
errors = {}
356364
for binprovider in self.binproviders:
@@ -363,7 +371,7 @@ def load(
363371
binprovider_name=binprovider.name,
364372
**extra_overrides,
365373
)
366-
installed_bin = provider.load(self.name, nocache=nocache)
374+
installed_bin = provider.load(self.name, no_cache=no_cache)
367375
if installed_bin is not None and installed_bin.loaded_abspath:
368376
# print('LOADED', binprovider, self.name, installed_bin)
369377
return self._validated_loaded_copy(
@@ -384,89 +392,12 @@ def load(
384392
)
385393
raise BinaryLoadError(self.name, provider_names, errors) from inner_exc
386394

387-
@validate_call
388-
@log_method_call(include_result=True)
389-
def load_or_install(
390-
self,
391-
binproviders: list[BinProviderName] | None = None,
392-
nocache: bool = False,
393-
dry_run: bool | None = None,
394-
postinstall_scripts: bool | None = None,
395-
min_release_age: float | None = None,
396-
**extra_overrides,
397-
) -> Self:
398-
assert self.name, f"No binary name was provided! {self}"
399-
400-
if self.is_valid:
401-
logger.debug(
402-
"Skipping load_or_install for %s because it is already valid",
403-
self.name,
404-
)
405-
return self
406-
407-
if binproviders is not None and len(list(binproviders)) == 0:
408-
logger.debug(
409-
"Skipping load_or_install for %s because binproviders list was empty",
410-
self.name,
411-
)
412-
return self
413-
414-
logger.info("Loading or installing %s binary", self.name)
415-
inner_exc: Exception | None = None
416-
errors = {}
417-
postinstall_scripts = (
418-
self.postinstall_scripts
419-
if postinstall_scripts is None
420-
else postinstall_scripts
421-
)
422-
min_release_age = (
423-
self.min_release_age if min_release_age is None else min_release_age
424-
)
425-
for binprovider in self.binproviders:
426-
if binproviders and binprovider.name not in binproviders:
427-
continue
428-
429-
provider = binprovider
430-
try:
431-
provider = self.get_binprovider(
432-
binprovider_name=binprovider.name,
433-
dry_run=dry_run,
434-
**extra_overrides,
435-
)
436-
installed_bin = provider.load_or_install(
437-
self.name,
438-
nocache=nocache,
439-
dry_run=dry_run,
440-
postinstall_scripts=postinstall_scripts,
441-
min_release_age=min_release_age,
442-
min_version=self.min_version,
443-
)
444-
if installed_bin is not None and installed_bin.loaded_abspath:
445-
# print('LOADED_OR_INSTALLED', self.name, installed_bin)
446-
return self._validated_loaded_copy(
447-
provider,
448-
abspath=installed_bin.loaded_abspath,
449-
version=installed_bin.loaded_version,
450-
sha256=installed_bin.loaded_sha256,
451-
)
452-
else:
453-
continue
454-
except Exception as err:
455-
inner_exc = err
456-
errors[binprovider.name] = format_exception_with_output(err)
457-
self._debug_provider_failure("load_or_install", provider, err)
458-
continue
459-
460-
provider_names = ", ".join(
461-
binproviders or [p.name for p in self.binproviders],
462-
)
463-
raise BinaryLoadOrInstallError(self.name, provider_names, errors) from inner_exc
464-
465395
@validate_call
466396
@log_method_call(include_result=True)
467397
def update(
468398
self,
469399
binproviders: list[BinProviderName] | None = None,
400+
no_cache: bool = False,
470401
dry_run: bool | None = None,
471402
postinstall_scripts: bool | None = None,
472403
min_release_age: float | None = None,
@@ -481,7 +412,7 @@ def update(
481412
)
482413
return self
483414

484-
logger.info("Updating %s binary", self.name)
415+
# logger.info("Updating %s binary", self.name)
485416
inner_exc: Exception | None = None
486417
errors = {}
487418
postinstall_scripts = (
@@ -505,6 +436,7 @@ def update(
505436
)
506437
updated_bin = provider.update(
507438
self.name,
439+
no_cache=no_cache,
508440
dry_run=dry_run,
509441
postinstall_scripts=postinstall_scripts,
510442
min_release_age=min_release_age,
@@ -532,6 +464,7 @@ def update(
532464
def uninstall(
533465
self,
534466
binproviders: list[BinProviderName] | None = None,
467+
no_cache: bool = False,
535468
dry_run: bool | None = None,
536469
postinstall_scripts: bool | None = None,
537470
min_release_age: float | None = None,
@@ -546,7 +479,7 @@ def uninstall(
546479
)
547480
return self
548481

549-
logger.info("Uninstalling %s binary", self.name)
482+
# logger.info("Uninstalling %s binary", self.name)
550483
inner_exc: Exception | None = None
551484
errors = {}
552485
postinstall_scripts = (
@@ -570,6 +503,7 @@ def uninstall(
570503
)
571504
uninstalled = provider.uninstall(
572505
self.name,
506+
no_cache=no_cache,
573507
dry_run=dry_run,
574508
postinstall_scripts=postinstall_scripts,
575509
min_release_age=min_release_age,

0 commit comments

Comments
 (0)