mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2026-04-05 15:27:53 +10:00
remove huey
This commit is contained in:
@@ -11,21 +11,53 @@ __package__ = "archivebox.config"
|
||||
import os
|
||||
import json
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, Optional, List, Type, TYPE_CHECKING, cast
|
||||
from typing import Any, Dict, Optional, List, Type, Tuple, TYPE_CHECKING, cast
|
||||
from configparser import ConfigParser
|
||||
|
||||
from pydantic import Field
|
||||
from pydantic_settings import BaseSettings
|
||||
from pydantic_settings import BaseSettings, PydanticBaseSettingsSource
|
||||
|
||||
|
||||
class IniConfigSettingsSource(PydanticBaseSettingsSource):
|
||||
"""
|
||||
Custom settings source that reads from ArchiveBox.conf (INI format).
|
||||
Flattens all sections into a single namespace.
|
||||
"""
|
||||
|
||||
def get_field_value(self, field: Any, field_name: str) -> Tuple[Any, str, bool]:
|
||||
config_vals = self._load_config_file()
|
||||
field_value = config_vals.get(field_name.upper())
|
||||
return field_value, field_name, False
|
||||
|
||||
def __call__(self) -> Dict[str, Any]:
|
||||
return self._load_config_file()
|
||||
|
||||
def _load_config_file(self) -> Dict[str, Any]:
|
||||
try:
|
||||
from archivebox.config.constants import CONSTANTS
|
||||
config_path = CONSTANTS.CONFIG_FILE
|
||||
except ImportError:
|
||||
return {}
|
||||
|
||||
if not config_path.exists():
|
||||
return {}
|
||||
|
||||
parser = ConfigParser()
|
||||
parser.optionxform = lambda x: x # preserve case
|
||||
parser.read(config_path)
|
||||
|
||||
# Flatten all sections into single namespace (ignore section headers)
|
||||
return {key.upper(): value for section in parser.sections() for key, value in parser.items(section)}
|
||||
|
||||
|
||||
class BaseConfigSet(BaseSettings):
|
||||
"""
|
||||
Base class for config sections.
|
||||
|
||||
Automatically loads values from:
|
||||
1. Environment variables (highest priority)
|
||||
2. ArchiveBox.conf file (if exists)
|
||||
3. Default values (lowest priority)
|
||||
Automatically loads values from (highest to lowest priority):
|
||||
1. Environment variables
|
||||
2. ArchiveBox.conf file (INI format, flattened)
|
||||
3. Default values
|
||||
|
||||
Subclasses define fields with defaults and types:
|
||||
|
||||
@@ -35,11 +67,30 @@ class BaseConfigSet(BaseSettings):
|
||||
"""
|
||||
|
||||
class Config:
|
||||
# Use env vars with ARCHIVEBOX_ prefix or raw name
|
||||
env_prefix = ""
|
||||
extra = "ignore"
|
||||
validate_default = True
|
||||
|
||||
@classmethod
|
||||
def settings_customise_sources(
|
||||
cls,
|
||||
settings_cls: Type[BaseSettings],
|
||||
init_settings: PydanticBaseSettingsSource,
|
||||
env_settings: PydanticBaseSettingsSource,
|
||||
dotenv_settings: PydanticBaseSettingsSource,
|
||||
file_secret_settings: PydanticBaseSettingsSource,
|
||||
) -> Tuple[PydanticBaseSettingsSource, ...]:
|
||||
"""
|
||||
Define the order of settings sources (first = highest priority).
|
||||
"""
|
||||
return (
|
||||
init_settings, # 1. Passed to __init__
|
||||
env_settings, # 2. Environment variables
|
||||
IniConfigSettingsSource(settings_cls), # 3. ArchiveBox.conf file
|
||||
# dotenv_settings, # Skip .env files
|
||||
# file_secret_settings, # Skip secrets files
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def load_from_file(cls, config_path: Path) -> Dict[str, str]:
|
||||
"""Load config values from INI file."""
|
||||
@@ -47,7 +98,7 @@ class BaseConfigSet(BaseSettings):
|
||||
return {}
|
||||
|
||||
parser = ConfigParser()
|
||||
parser.optionxform = lambda x: x # type: ignore # preserve case
|
||||
parser.optionxform = lambda x: x # preserve case
|
||||
parser.read(config_path)
|
||||
|
||||
# Flatten all sections into single namespace
|
||||
|
||||
@@ -256,7 +256,7 @@ def plugins_list_view(request: HttpRequest, **kwargs) -> TableContext:
|
||||
# Show a helpful message when no plugins found
|
||||
rows['Name'].append('(no plugins found)')
|
||||
rows['Source'].append('-')
|
||||
rows['Path'].append(format_html('<code>archivebox/plugins/</code> or <code>data/plugins/</code>'))
|
||||
rows['Path'].append(mark_safe('<code>archivebox/plugins/</code> or <code>data/plugins/</code>'))
|
||||
rows['Hooks'].append('-')
|
||||
|
||||
return TableContext(
|
||||
|
||||
Reference in New Issue
Block a user