Summary
_resolve_config_path() raises FileNotFoundError at import time whenever OA_CONFIG_PATH is set to a path that doesn't exist yet. This defeats the entire purpose of init, which is supposed to create that file.
Reproduction
export OA_CONFIG_PATH=/tmp/scratch/config.toml
omop-config init
Actual behaviour
Crashes immediately with FileNotFoundError, before init's own command logic gets a chance to run at all. Root cause is in loader.py:
def _resolve_config_path() -> Path:
raw = os.environ.get(ENV_CONFIG_PATH)
if raw:
p = _normalize_path(raw)
if not p.exists():
raise FileNotFoundError(f"{ENV_CONFIG_PATH} points to a non-existent file: {raw!r}")
...
return p
return DEFAULT_CONFIG_PATH
CONFIG_PATH: Path = _resolve_config_path() # runs at module import
The existence check only applies on the explicit-OA_CONFIG_PATH branch. The default-path branch skips it entirely, and init there happily creates both the file and its parent directories.
Expected behaviour
omop-config init should create the file (and parent directories) at OA_CONFIG_PATH the same way it does for the default path. The existence check shouldn't apply before init has had a chance to run.
Error output
Traceback (most recent call last):
File "/home/vscode/venv/bin/omop-config", line 4, in <module>
from oa_configurator.cli import app
File "/workspace/OA_Configurator/src/oa_configurator/__init__.py", line 20, in <module>
from .io import ConfigSaveError, FLAT_ENV_PATH, save_stack_config, write_env_file
File "/workspace/OA_Configurator/src/oa_configurator/io.py", line 14, in <module>
from .loader import CONFIG_PATH, _normalize_path, invalidate_cache
File "/workspace/OA_Configurator/src/oa_configurator/loader.py", line 86, in <module>
CONFIG_PATH: Path = _resolve_config_path()
^^^^^^^^^^^^^^^^^^^^^^
File "/workspace/OA_Configurator/src/oa_configurator/loader.py", line 77, in _resolve_config_path
raise FileNotFoundError(f"{ENV_CONFIG_PATH} points to a non-existent file: {raw!r}")
FileNotFoundError: OA_CONFIG_PATH points to a non-existent file: '/tmp/scratch/config.toml'
Summary
_resolve_config_path()raisesFileNotFoundErrorat import time wheneverOA_CONFIG_PATHis set to a path that doesn't exist yet. This defeats the entire purpose ofinit, which is supposed to create that file.Reproduction
export OA_CONFIG_PATH=/tmp/scratch/config.toml omop-config initActual behaviour
Crashes immediately with
FileNotFoundError, beforeinit's own command logic gets a chance to run at all. Root cause is inloader.py:The existence check only applies on the explicit-
OA_CONFIG_PATHbranch. The default-path branch skips it entirely, andinitthere happily creates both the file and its parent directories.Expected behaviour
omop-config initshould create the file (and parent directories) atOA_CONFIG_PATHthe same way it does for the default path. The existence check shouldn't apply beforeinithas had a chance to run.Error output