from __future__ import annotations import importlib.util import os from pathlib import Path from types import ModuleType def _user_config_path() -> Path | None: explicit = os.environ.get("COPIENATOR_CONFIG", "").strip() if explicit: return Path(explicit).expanduser().resolve() local = Path.cwd() / "config.py" return local.resolve() if local.is_file() else None def _load_user_config(path: Path) -> ModuleType: if not path.is_file(): raise FileNotFoundError(f"Copienator configuration not found: {path}") spec = importlib.util.spec_from_file_location("_copienator_user_config", path) if spec is None or spec.loader is None: raise ImportError(f"Could not load Copienator configuration: {path}") module = importlib.util.module_from_spec(spec) spec.loader.exec_module(module) return module CONFIG_PATH = _user_config_path() if CONFIG_PATH is None: import default_config as _configuration else: _configuration = _load_user_config(CONFIG_PATH) # Keep new optional settings compatible with older personal configuration files. ALWAYS_CROP = False RETURN_JPEG_ENABLED = True RETURN_PDF_ENABLED = True RETURN_ANSWERS_ENABLED = False RETURN_ANSWERS_CONTEXT = False RETURN_ANSWERS_QUESTION = True RETURN_ANSWERS_SOLUTION = False FINAL_SCORE_HISTOGRAM_PATH = Path("histogramme.pdf") for _name in dir(_configuration): if not _name.startswith("_"): globals()[_name] = getattr(_configuration, _name)