diff --git a/archivebox/config/common.py b/archivebox/config/common.py index 991f0655..4dbc4627 100644 --- a/archivebox/config/common.py +++ b/archivebox/config/common.py @@ -1253,7 +1253,6 @@ def get_config( value = config[key] if is_sensitive_config_key(key) and value not in (None, ""): setattr(config, key, SENSITIVE_CONFIG_VALUE_REDACTED) - os.environ["ABXPKG_LIB_DIR"] = str(config.ABXPKG_LIB_DIR) archiving_warning_key = (config.TIMEOUT, config.USE_COLOR) if archiving_warning_key not in _WARNED_ARCHIVING_CONFIGS: config.warn_if_invalid() diff --git a/archivebox/config/django.py b/archivebox/config/django.py index 3b4daec1..c349cdda 100644 --- a/archivebox/config/django.py +++ b/archivebox/config/django.py @@ -15,6 +15,7 @@ from .common import get_config from .constants import CONSTANTS CONFIG = get_config() +os.environ.setdefault("ABXPKG_LIB_DIR", str(CONFIG.ABXPKG_LIB_DIR)) if not CONFIG.USE_COLOR: os.environ["NO_COLOR"] = "1" diff --git a/archivebox/tests/test_core_config.py b/archivebox/tests/test_core_config.py index 292ade80..0593f27c 100644 --- a/archivebox/tests/test_core_config.py +++ b/archivebox/tests/test_core_config.py @@ -74,3 +74,24 @@ def test_string_config_values_are_decoded_at_one_boundary(): assert decoded["CHROME_ARGS"] == ["--headless", "--no-sandbox"] assert decoded["UNKNOWN_COMPLEX"] == {"source": "plugin"} + + +def test_resolving_scoped_config_does_not_mutate_process_environment(tmp_path): + from archivebox.config.common import ArchiveBoxConfig, get_config + + active_lib_dir = tmp_path / "active-lib" + stale_lib_dir = tmp_path / "stale-lib" + previous_lib_dir = os.environ.get("ABXPKG_LIB_DIR") + try: + os.environ["ABXPKG_LIB_DIR"] = str(active_lib_dir) + stale_process_config = ArchiveBoxConfig(ABXPKG_LIB_DIR=stale_lib_dir) + + resolved = get_config(base_config=stale_process_config, include_machine=False, resolve_plugins=False) + + assert resolved.ABXPKG_LIB_DIR == stale_lib_dir + assert os.environ["ABXPKG_LIB_DIR"] == str(active_lib_dir) + finally: + if previous_lib_dir is None: + os.environ.pop("ABXPKG_LIB_DIR", None) + else: + os.environ["ABXPKG_LIB_DIR"] = previous_lib_dir