Spaces:
Running on Zero
Running on Zero
File size: 960 Bytes
b38d551 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | import json
import os
from functools import lru_cache
from pathlib import Path
DEFAULT_CONFIG_FILES = (
"openalex_config.local.json",
)
@lru_cache(maxsize=1)
def load_local_config():
"""Load local config values without overriding existing environment variables."""
config_file = os.environ.get("OPENALEX_CONFIG_FILE")
candidate_paths = [Path(config_file)] if config_file else [Path(name) for name in DEFAULT_CONFIG_FILES]
loaded = {}
for path in candidate_paths:
if not path.exists():
continue
with path.open("r", encoding="utf-8") as handle:
loaded = json.load(handle)
if not isinstance(loaded, dict):
raise ValueError(f"Config file {path} must contain a JSON object at the top level.")
for key, value in loaded.items():
if key not in os.environ and value is not None:
os.environ[key] = str(value)
break
return loaded
|