Update __init__.py

This commit is contained in:
Nick Sweeting 2024-11-03 16:12:29 -05:00 committed by GitHub
parent 5872375a50
commit 1148cadd7a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -7,16 +7,17 @@ PKGS_DIR = Path(__file__).parent
VENDORED_PKGS = [ VENDORED_PKGS = [
'abx', 'abx',
# 'pydantic-pkgr', # 'pydantic-pkgr',
# ... everything else in archivebox/pkgs/* comes after ...
] ]
# scan ./pkgs and add all dirs present to list of available VENDORED_PKGS # VENDORED_PKGS += [ ... ./pkgs/* ... ]
for subdir in reversed(sorted(PKGS_DIR.iterdir())): for subdir in reversed(sorted(PKGS_DIR.iterdir())):
if subdir.is_dir() and subdir.name not in VENDORED_PKGS and not subdir.name.startswith('_'): if subdir.is_dir() and subdir.name not in VENDORED_PKGS and not subdir.name.startswith('_'):
VENDORED_PKGS.append(subdir.name) VENDORED_PKGS.append(subdir.name)
def load_vendored_pkgs(): def load_vendored_pkgs():
"""Add archivebox/vendor to sys.path and import all vendored libraries present within""" """Add archivebox/pkgs to sys.path and import all vendored python packages present within"""
if str(PKGS_DIR) not in sys.path: if str(PKGS_DIR) not in sys.path:
sys.path.append(str(PKGS_DIR)) sys.path.append(str(PKGS_DIR))
@ -28,12 +29,12 @@ def load_vendored_pkgs():
lib = importlib.import_module(pkg_name) lib = importlib.import_module(pkg_name)
# print(f"Successfully imported lib from environment {pkg_name}") # print(f"Successfully imported lib from environment {pkg_name}")
except ImportError: except ImportError:
sys.path.append(str(pkg_dir)) sys.path.append(str(pkg_dir)) # perhaps the pkg is in a subdirectory of the directory
try: try:
lib = importlib.import_module(pkg_name) lib = importlib.import_module(pkg_name)
# print(f"Successfully imported lib from vendored fallback {pkg_name}: {inspect.getfile(lib)}") # print(f"Successfully imported lib from vendored fallback {pkg_name}: {inspect.getfile(lib)}")
except ImportError as e: except ImportError as e:
print(f"Failed to import lib from environment or vendored fallback {pkg_name}: {e}", file=sys.stderr) print(f"Failed to import required pkg from sys.path or archivebox/pkgs dir {pkg_name}: {e}", file=sys.stderr)
sys.exit(1) sys.exit(1)