never attempt to create system venv, install ldap in lib automatically, and setup binproviders before bins

This commit is contained in:
Nick Sweeting 2024-10-08 18:52:02 -07:00
parent 3e4a846488
commit 584abe8548
No known key found for this signature in database
6 changed files with 30 additions and 8 deletions

View file

@ -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('[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(f' DATA_DIR, LIB_DIR, and TMP_DIR will be owned by [blue]{ARCHIVEBOX_USER}:{ARCHIVEBOX_GROUP}[/blue].')
print() 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())): for binary in reversed(list(settings.BINARIES.values())):
providers = ' [grey53]or[/grey53] '.join(provider.name for provider in binary.binproviders_supported) 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]...') print(f'[+] Locating / Installing [yellow]{binary.name}[/yellow] using [red]{providers}[/red]...')

View file

@ -12,7 +12,7 @@ from abx.archivebox.base_plugin import BasePlugin
from abx.archivebox.base_hook import BaseHook from abx.archivebox.base_hook import BaseHook
from abx.archivebox.base_binary import BaseBinary, BaseBinProvider 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 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): class LdapBinary(BaseBinary):
name: str = 'ldap' name: str = 'ldap'
description: str = 'LDAP Authentication' 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] = { provider_overrides: Dict[BinProviderName, ProviderLookupDict] = {
VENV_PIP_BINPROVIDER.name: { VENV_PIP_BINPROVIDER.name: {

View file

@ -2,6 +2,8 @@ __package__ = 'archivebox.plugins_auth.ldap'
import sys import sys
from functools import cache
from typing import Dict, List, Optional from typing import Dict, List, Optional
from pydantic import Field, model_validator, computed_field from pydantic import Field, model_validator, computed_field
@ -10,7 +12,8 @@ from abx.archivebox.base_configset import BaseConfigSet
LDAP_LIB = None LDAP_LIB = None
LDAP_SEARCH = None LDAP_SEARCH = None
def get_ldap_lib(): @cache
def get_ldap_lib():
global LDAP_LIB, LDAP_SEARCH global LDAP_LIB, LDAP_SEARCH
if LDAP_LIB and LDAP_SEARCH: if LDAP_LIB and LDAP_SEARCH:
return LDAP_LIB, LDAP_SEARCH return LDAP_LIB, LDAP_SEARCH

View file

@ -59,6 +59,10 @@ class VenvPipBinProvider(PipProvider, BaseBinProvider):
INSTALLER_BIN: BinName = "pip" INSTALLER_BIN: BinName = "pip"
pip_venv: Optional[Path] = Path(os.environ.get("VIRTUAL_ENV", None) or '/tmp/NotInsideAVenv') 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): 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) # 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]) 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)) sys.path.append(str(LIB_PIP_BINPROVIDER.pip_venv / site_packages_dir))

@ -1 +1 @@
Subproject commit e198bfc7eabb1f68f14df8731081a5c83c5825de Subproject commit fa47402471ccb1f2e5ed33806e3fd3e2dee590c8

View file

@ -1,6 +1,6 @@
[project] [project]
name = "archivebox" name = "archivebox"
version = "0.8.5rc14" version = "0.8.5rc18"
requires-python = ">=3.10" requires-python = ">=3.10"
description = "Self-hosted internet archiving solution." description = "Self-hosted internet archiving solution."
authors = [{name = "Nick Sweeting", email = "pyproject.toml@archivebox.io"}] authors = [{name = "Nick Sweeting", email = "pyproject.toml@archivebox.io"}]
@ -79,7 +79,7 @@ dependencies = [
"base32-crockford==0.3.0", "base32-crockford==0.3.0",
"platformdirs>=4.3.6", "platformdirs>=4.3.6",
# "pocket@git+https://github.com/tapanpandita/pocket.git@v0.3.7", # "pocket@git+https://github.com/tapanpandita/pocket.git@v0.3.7",
"pydantic-pkgr>=0.4.9", "pydantic-pkgr>=0.4.13",
############# Plugin Dependencies ################ ############# Plugin Dependencies ################
"sonic-client>=1.0.0", "sonic-client>=1.0.0",
"yt-dlp>=2024.8.6", # for: media" "yt-dlp>=2024.8.6", # for: media"