mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2026-09-14 11:06:13 +05:00
stop scoped config from mutating process state
This commit is contained in:
parent
8017245c3f
commit
319763c763
@ -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()
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user