From 584abe854896493f5e29743a41d34c1f2fa11011 Mon Sep 17 00:00:00 2001 From: Nick Sweeting Date: Tue, 8 Oct 2024 18:52:02 -0700 Subject: [PATCH] never attempt to create system venv, install ldap in lib automatically, and setup binproviders before bins --- archivebox/main.py | 16 +++++++++++++++- archivebox/plugins_auth/ldap/apps.py | 4 ++-- archivebox/plugins_auth/ldap/settings.py | 5 ++++- archivebox/plugins_pkg/pip/apps.py | 7 ++++++- archivebox/vendor/pydantic-pkgr | 2 +- pyproject.toml | 4 ++-- 6 files changed, 30 insertions(+), 8 deletions(-) diff --git a/archivebox/main.py b/archivebox/main.py index 3e679da1..1a059a7c 100755 --- a/archivebox/main.py +++ b/archivebox/main.py @@ -999,7 +999,21 @@ def install(out_dir: Path=DATA_DIR) -> None: print('[yellow]:warning: Using [red]root[/red] privileges only to install dependencies that need it, all other operations should be done as a [blue]non-root[/blue] user.[/yellow]') print(f' DATA_DIR, LIB_DIR, and TMP_DIR will be owned by [blue]{ARCHIVEBOX_USER}:{ARCHIVEBOX_GROUP}[/blue].') print() - + + + package_manager_names = ', '.join(binprovider.name for binprovider in reversed(list(settings.BINPROVIDERS.values()))) + print(f'[+] Setting up package managers [yellow]{package_manager_names}[/yellow]...') + for binprovider in reversed(list(settings.BINPROVIDERS.values())): + try: + binprovider.setup() + except Exception: + # it's ok, installing binaries below will automatically set up package managers as needed + # e.g. if user does not have npm available we cannot set it up here yet, but once npm Binary is installed + # the next package that depends on npm will automatically call binprovider.setup() during its own install + pass + + print() + for binary in reversed(list(settings.BINARIES.values())): providers = ' [grey53]or[/grey53] '.join(provider.name for provider in binary.binproviders_supported) print(f'[+] Locating / Installing [yellow]{binary.name}[/yellow] using [red]{providers}[/red]...') diff --git a/archivebox/plugins_auth/ldap/apps.py b/archivebox/plugins_auth/ldap/apps.py index 02bb505f..b80579f2 100644 --- a/archivebox/plugins_auth/ldap/apps.py +++ b/archivebox/plugins_auth/ldap/apps.py @@ -12,7 +12,7 @@ from abx.archivebox.base_plugin import BasePlugin from abx.archivebox.base_hook import BaseHook from abx.archivebox.base_binary import BaseBinary, BaseBinProvider -from plugins_pkg.pip.apps import SYS_PIP_BINPROVIDER, VENV_PIP_BINPROVIDER +from plugins_pkg.pip.apps import SYS_PIP_BINPROVIDER, VENV_PIP_BINPROVIDER, LIB_PIP_BINPROVIDER from .settings import LDAP_CONFIG, get_ldap_lib @@ -24,7 +24,7 @@ LDAP_LIB = lambda: get_ldap_lib()[0] # lazy load to avoid slow ldap lib import class LdapBinary(BaseBinary): name: str = 'ldap' description: str = 'LDAP Authentication' - binproviders_supported: List[InstanceOf[BaseBinProvider]] = [VENV_PIP_BINPROVIDER, SYS_PIP_BINPROVIDER] + binproviders_supported: List[InstanceOf[BaseBinProvider]] = [VENV_PIP_BINPROVIDER, SYS_PIP_BINPROVIDER, LIB_PIP_BINPROVIDER] provider_overrides: Dict[BinProviderName, ProviderLookupDict] = { VENV_PIP_BINPROVIDER.name: { diff --git a/archivebox/plugins_auth/ldap/settings.py b/archivebox/plugins_auth/ldap/settings.py index 094e1e9b..e93beac1 100644 --- a/archivebox/plugins_auth/ldap/settings.py +++ b/archivebox/plugins_auth/ldap/settings.py @@ -2,6 +2,8 @@ __package__ = 'archivebox.plugins_auth.ldap' import sys +from functools import cache + from typing import Dict, List, Optional from pydantic import Field, model_validator, computed_field @@ -10,7 +12,8 @@ from abx.archivebox.base_configset import BaseConfigSet LDAP_LIB = None LDAP_SEARCH = None -def get_ldap_lib(): +@cache +def get_ldap_lib(): global LDAP_LIB, LDAP_SEARCH if LDAP_LIB and LDAP_SEARCH: return LDAP_LIB, LDAP_SEARCH diff --git a/archivebox/plugins_pkg/pip/apps.py b/archivebox/plugins_pkg/pip/apps.py index cbad35d7..813317dc 100644 --- a/archivebox/plugins_pkg/pip/apps.py +++ b/archivebox/plugins_pkg/pip/apps.py @@ -59,6 +59,10 @@ class VenvPipBinProvider(PipProvider, BaseBinProvider): INSTALLER_BIN: BinName = "pip" pip_venv: Optional[Path] = Path(os.environ.get("VIRTUAL_ENV", None) or '/tmp/NotInsideAVenv') + + def setup(self): + """never attempt to create a venv here, this is just used to detect if we are inside an existing one""" + return None class LibPipBinProvider(PipProvider, BaseBinProvider): @@ -75,7 +79,8 @@ pip = LIB_PIP_BINPROVIDER # ensure python libraries are importable from these locations (if archivebox wasnt executed from one of these then they wont already be in sys.path) site_packages_dir = 'lib/python{}.{}/site-packages'.format(*sys.version_info[:2]) -sys.path.append(str(VENV_PIP_BINPROVIDER.pip_venv / site_packages_dir)) +if os.environ.get("VIRTUAL_ENV", None): + sys.path.append(str(VENV_PIP_BINPROVIDER.pip_venv / site_packages_dir)) sys.path.append(str(LIB_PIP_BINPROVIDER.pip_venv / site_packages_dir)) diff --git a/archivebox/vendor/pydantic-pkgr b/archivebox/vendor/pydantic-pkgr index e198bfc7..fa474024 160000 --- a/archivebox/vendor/pydantic-pkgr +++ b/archivebox/vendor/pydantic-pkgr @@ -1 +1 @@ -Subproject commit e198bfc7eabb1f68f14df8731081a5c83c5825de +Subproject commit fa47402471ccb1f2e5ed33806e3fd3e2dee590c8 diff --git a/pyproject.toml b/pyproject.toml index 53d9a1cd..a1783a38 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "archivebox" -version = "0.8.5rc14" +version = "0.8.5rc18" requires-python = ">=3.10" description = "Self-hosted internet archiving solution." authors = [{name = "Nick Sweeting", email = "pyproject.toml@archivebox.io"}] @@ -79,7 +79,7 @@ dependencies = [ "base32-crockford==0.3.0", "platformdirs>=4.3.6", # "pocket@git+https://github.com/tapanpandita/pocket.git@v0.3.7", - "pydantic-pkgr>=0.4.9", + "pydantic-pkgr>=0.4.13", ############# Plugin Dependencies ################ "sonic-client>=1.0.0", "yt-dlp>=2024.8.6", # for: media"