mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2025-05-21 18:35:23 -04:00
rename pkgs app to pkg
Some checks failed
Build Docker image / buildx (push) Has been cancelled
Build Homebrew package / build (push) Has been cancelled
Run linters / lint (push) Has been cancelled
Build Debian package / build (push) Has been cancelled
Build Pip package / build (push) Has been cancelled
Run tests / python_tests (ubuntu-22.04, 3.11) (push) Has been cancelled
Run tests / docker_tests (push) Has been cancelled
Some checks failed
Build Docker image / buildx (push) Has been cancelled
Build Homebrew package / build (push) Has been cancelled
Run linters / lint (push) Has been cancelled
Build Debian package / build (push) Has been cancelled
Build Pip package / build (push) Has been cancelled
Run tests / python_tests (ubuntu-22.04, 3.11) (push) Has been cancelled
Run tests / docker_tests (push) Has been cancelled
This commit is contained in:
parent
6e13cd4820
commit
da76a84c45
13 changed files with 80 additions and 5 deletions
0
archivebox/pkg/__init__.py
Normal file
0
archivebox/pkg/__init__.py
Normal file
3
archivebox/pkg/admin.py
Normal file
3
archivebox/pkg/admin.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
14
archivebox/pkg/apps.py
Normal file
14
archivebox/pkg/apps.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
__package__ = 'archivebox.pkg'
|
||||
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class PkgsConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'pkg'
|
||||
|
||||
def ready(self):
|
||||
from .settings import LOADED_DEPENDENCIES
|
||||
|
||||
# print(LOADED_DEPENDENCIES)
|
||||
|
0
archivebox/pkg/management/__init__.py
Normal file
0
archivebox/pkg/management/__init__.py
Normal file
0
archivebox/pkg/management/commands/__init__.py
Normal file
0
archivebox/pkg/management/commands/__init__.py
Normal file
75
archivebox/pkg/management/commands/pkg.py
Normal file
75
archivebox/pkg/management/commands/pkg.py
Normal file
|
@ -0,0 +1,75 @@
|
|||
__package__ = 'archivebox.pkg.management.commands'
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.conf import settings
|
||||
|
||||
from pydantic_pkgr import Binary, BinProvider, BrewProvider, EnvProvider, SemVer
|
||||
from pydantic_pkgr.binprovider import bin_abspath
|
||||
|
||||
from ....config import NODE_BIN_PATH, bin_path
|
||||
|
||||
from plugantic.plugins import LOADED_PLUGINS
|
||||
|
||||
from pkg.settings import env
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
def handle(self, *args, method, **options):
|
||||
method(*args, **options)
|
||||
|
||||
def add_arguments(self, parser):
|
||||
subparsers = parser.add_subparsers(title="sub-commands", required=True)
|
||||
|
||||
list_parser = subparsers.add_parser("list", help="List archivebox runtime dependencies.")
|
||||
list_parser.set_defaults(method=self.list)
|
||||
|
||||
install_parser = subparsers.add_parser("install", help="Install archivebox runtime dependencies.")
|
||||
install_parser.add_argument("--update", action="store_true", help="Update dependencies to latest versions.")
|
||||
install_parser.add_argument("package_names", nargs="+", type=str)
|
||||
install_parser.set_defaults(method=self.install)
|
||||
|
||||
def list(self, *args, **options):
|
||||
self.stdout.write('################# PLUGINS ####################')
|
||||
for plugin in LOADED_PLUGINS:
|
||||
self.stdout.write(f'{plugin.name}:')
|
||||
for binary in plugin.binaries:
|
||||
try:
|
||||
binary = binary.install()
|
||||
except Exception as e:
|
||||
# import ipdb; ipdb.set_trace()
|
||||
raise
|
||||
self.stdout.write(f' {binary.name.ljust(14)} {str(binary.version).ljust(11)} {binary.binprovider.INSTALLER_BIN.ljust(5)} {binary.abspath}')
|
||||
|
||||
self.stdout.write('\n################# LEGACY ####################')
|
||||
for bin_key, dependency in settings.CONFIG.DEPENDENCIES.items():
|
||||
bin_name = settings.CONFIG[bin_key]
|
||||
|
||||
self.stdout.write(f'{bin_key}: {bin_name}')
|
||||
|
||||
# binary = Binary(name=package_name, providers=[env])
|
||||
# print(binary)
|
||||
|
||||
# try:
|
||||
# loaded_bin = binary.load()
|
||||
# self.stdout.write(
|
||||
# self.style.SUCCESS(f'Successfully loaded {package_name}:') + str(loaded_bin)
|
||||
# )
|
||||
# except Exception as e:
|
||||
# self.stderr.write(
|
||||
# self.style.ERROR(f"Error loading {package_name}: {e}")
|
||||
# )
|
||||
|
||||
def install(self, *args, bright, **options):
|
||||
for package_name in options["package_names"]:
|
||||
binary = Binary(name=package_name, providers=[env])
|
||||
print(binary)
|
||||
|
||||
try:
|
||||
loaded_bin = binary.load()
|
||||
self.stdout.write(
|
||||
self.style.SUCCESS(f'Successfully loaded {package_name}:') + str(loaded_bin)
|
||||
)
|
||||
except Exception as e:
|
||||
self.stderr.write(
|
||||
self.style.ERROR(f"Error loading {package_name}: {e}")
|
||||
)
|
0
archivebox/pkg/migrations/__init__.py
Normal file
0
archivebox/pkg/migrations/__init__.py
Normal file
3
archivebox/pkg/models.py
Normal file
3
archivebox/pkg/models.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.db import models
|
||||
|
||||
# Create your models here.
|
86
archivebox/pkg/settings.py
Normal file
86
archivebox/pkg/settings.py
Normal file
|
@ -0,0 +1,86 @@
|
|||
__package__ = 'archivebox.pkg'
|
||||
|
||||
import os
|
||||
import sys
|
||||
import shutil
|
||||
import inspect
|
||||
from pathlib import Path
|
||||
|
||||
import django
|
||||
from django.conf import settings
|
||||
from django.db.backends.sqlite3.base import Database as sqlite3
|
||||
|
||||
from pydantic_pkgr import Binary, BinProvider, BrewProvider, EnvProvider, SemVer
|
||||
from pydantic_pkgr.binprovider import bin_abspath
|
||||
|
||||
from ..config import NODE_BIN_PATH, bin_path
|
||||
|
||||
env = EnvProvider(PATH=NODE_BIN_PATH + ':' + os.environ.get('PATH', '/bin'))
|
||||
|
||||
|
||||
LOADED_DEPENDENCIES = {}
|
||||
|
||||
for bin_key, dependency in settings.CONFIG.DEPENDENCIES.items():
|
||||
# 'PYTHON_BINARY': {
|
||||
# 'path': bin_path(config['PYTHON_BINARY']),
|
||||
# 'version': config['PYTHON_VERSION'],
|
||||
# 'hash': bin_hash(config['PYTHON_BINARY']),
|
||||
# 'enabled': True,
|
||||
# 'is_valid': bool(config['PYTHON_VERSION']),
|
||||
# },
|
||||
|
||||
|
||||
bin_name = settings.CONFIG[bin_key]
|
||||
|
||||
if bin_name.endswith('django/__init__.py'):
|
||||
binary_spec = Binary(name='django', providers=[env], provider_overrides={
|
||||
'env': {
|
||||
'abspath': lambda: Path(inspect.getfile(django)),
|
||||
'version': lambda: SemVer('{}.{}.{} {} ({})'.format(*django.VERSION)),
|
||||
}
|
||||
})
|
||||
elif bin_name.endswith('sqlite3/dbapi2.py'):
|
||||
binary_spec = Binary(name='sqlite3', providers=[env], provider_overrides={
|
||||
'env': {
|
||||
'abspath': lambda: Path(inspect.getfile(sqlite3)),
|
||||
'version': lambda: SemVer(sqlite3.version),
|
||||
}
|
||||
})
|
||||
elif bin_name.endswith('archivebox'):
|
||||
binary_spec = Binary(name='archivebox', providers=[env], provider_overrides={
|
||||
'env': {
|
||||
'abspath': lambda: shutil.which(str(Path('archivebox').expanduser())),
|
||||
'version': lambda: settings.CONFIG.VERSION,
|
||||
}
|
||||
})
|
||||
elif bin_name.endswith('postlight/parser/cli.js'):
|
||||
binary_spec = Binary(name='postlight-parser', providers=[env], provider_overrides={
|
||||
'env': {
|
||||
'abspath': lambda: bin_path('postlight-parser'),
|
||||
'version': lambda: SemVer('1.0.0'),
|
||||
}
|
||||
})
|
||||
else:
|
||||
binary_spec = Binary(name=bin_name, providers=[env])
|
||||
|
||||
try:
|
||||
binary = binary_spec.load()
|
||||
except Exception as e:
|
||||
# print(f"- ❌ Binary {bin_name} failed to load with error: {e}")
|
||||
continue
|
||||
|
||||
assert isinstance(binary.loaded_version, SemVer)
|
||||
|
||||
try:
|
||||
assert str(binary.loaded_version) == dependency['version'], f"Expected {bin_name} version {dependency['version']}, got {binary.loaded_version}"
|
||||
assert str(binary.loaded_respath) == str(bin_abspath(dependency['path']).resolve()), f"Expected {bin_name} abspath {bin_abspath(dependency['path']).resolve()}, got {binary.loaded_respath}"
|
||||
assert binary.is_valid == dependency['is_valid'], f"Expected {bin_name} is_valid={dependency['is_valid']}, got {binary.is_valid}"
|
||||
except Exception as e:
|
||||
pass
|
||||
# print(f"WARNING: Error loading {bin_name}: {e}")
|
||||
# import ipdb; ipdb.set_trace()
|
||||
|
||||
# print(f"- ✅ Binary {bin_name} loaded successfully")
|
||||
LOADED_DEPENDENCIES[bin_key] = binary
|
||||
|
||||
|
3
archivebox/pkg/tests.py
Normal file
3
archivebox/pkg/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
3
archivebox/pkg/views.py
Normal file
3
archivebox/pkg/views.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
Loading…
Add table
Add a link
Reference in a new issue