Skip to content

Commit

Permalink
Use default values in lieu of a configuration file
Browse files Browse the repository at this point in the history
Instead of exiting with an error if no configuration file is found, a
warning is raised and default values are assumed.
While a useful feature in and of itself, this is also a short term fix
to make tests importing `egon.data.airflow.dags.pipeline` pass, because
that pulls in code trying to access configuration values. The real fix
for this though is to run the corresponding tests in a correctly set up
environment having a configuration file. Fortunately, this is exactly
how the warning is squelched, so there'll be reminder whenever tests are
run.
  • Loading branch information
gnn committed Nov 26, 2021
1 parent 3e2ad2d commit c78e0ce
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/egon/data/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,28 @@ def settings() -> dict[str, dict[str, str]]:
"""
files = paths(pid="*") + paths()
if not files[0].exists():
# TODO: Fatal errors should be raised as exceptions, so one can figure
# out where they are coming from without having to debug.
logger.error(
f"Unable to determine settings.\nConfiguration file:"
f"\n\n{files[0]}\n\nnot found.\nExiting."
logger.warning(
f"Configuration file:"
f"\n\n{files[0]}\n\nnot found.\nUsing defaults."
)
sys.exit(-1)
return {
"egon-data": {
"--airflow-database-name": "airflow",
"--airflow-port": 8080,
"--compose-project-name": "egon-data",
"--database-host": "127.0.0.1",
"--database-name": "egon-data",
"--database-password": "data",
"--database-port": "59734",
"--database-user": "egon",
"--dataset-boundary": "Everything",
"--docker-container-name":
"egon-data-local-database-container",
"--jobs": 1,
"--random-seed": 42,
"--processes-per-task": 1,
}
}
with open(files[0]) as f:
return yaml.safe_load(f)

Expand Down

0 comments on commit c78e0ce

Please sign in to comment.