From 2f45cc8279e7f610f89cc1f9b7aab2365ad1d7f8 Mon Sep 17 00:00:00 2001 From: Hannah Eslinger Date: Wed, 24 May 2023 17:11:16 -0600 Subject: [PATCH 1/5] Remove configs.py --- .gitignore | 1 - buildingmotif/api/Dockerfile | 1 - buildingmotif/api/app.py | 5 ----- buildingmotif/bin/cli.py | 12 +----------- configs.py.dist | 1 - docs/reference/cli_tool.md | 3 +-- docs/reference/developer_documentation.md | 7 ++----- migrations/env.py | 10 ++-------- 8 files changed, 6 insertions(+), 34 deletions(-) delete mode 100644 configs.py.dist diff --git a/.gitignore b/.gitignore index 06e8ba4a0..9d5c1fd1f 100644 --- a/.gitignore +++ b/.gitignore @@ -39,7 +39,6 @@ docs/reference/apidoc/_autosummary # project -configs.py buildingmotif-app/node_modules/ **/BuildingMOTIF.log *.db diff --git a/buildingmotif/api/Dockerfile b/buildingmotif/api/Dockerfile index 4b32bba5e..00a7e4364 100644 --- a/buildingmotif/api/Dockerfile +++ b/buildingmotif/api/Dockerfile @@ -3,7 +3,6 @@ FROM python:3.8 # Copy project ADD buildingmotif /opt/buildingmotif ADD libraries /opt/libraries -COPY configs.py /opt/ ADD migrations /opt/migrations COPY alembic.ini /opt/ COPY pyproject.toml /opt/ diff --git a/buildingmotif/api/app.py b/buildingmotif/api/app.py index 3ae580343..dca141abc 100644 --- a/buildingmotif/api/app.py +++ b/buildingmotif/api/app.py @@ -69,11 +69,6 @@ def create_app(DB_URI): if __name__ == "__main__": """Run API.""" db_uri = os.getenv("DB_URI") - if db_uri is None: - # If config doesn't exist, this is considered a third party import and module cant be found. - import configs as building_motif_configs # type: ignore # isort:skip - - db_uri = building_motif_configs.DB_URI app = create_app(db_uri) app.run(debug=True, host="0.0.0.0", threaded=False) diff --git a/buildingmotif/bin/cli.py b/buildingmotif/bin/cli.py index 642c64527..ef8d093df 100644 --- a/buildingmotif/bin/cli.py +++ b/buildingmotif/bin/cli.py @@ -47,16 +47,6 @@ def get_db_uri(args) -> str: if db_uri is not None: return db_uri db_uri = getenv("DB_URI") - if db_uri is not None: - return db_uri - try: - import configs as building_motif_configs - except ImportError: - print("No DB URI could be found") - print("No configs.py file found") - subcommands[args.func].print_help() - sys.exit(1) - db_uri = building_motif_configs.DB_URI if db_uri is not None: return db_uri print("No DB URI could be found") @@ -97,7 +87,7 @@ def load(args): Loads libraries from (1) local directories (--dir), (2) local or remote ontology files (--ont) (3) library spec file (--libraries): the provided YML file into the - BuildingMOTIF instance at $DB_URI or whatever is in 'configs.py'. + BuildingMOTIF instance at $DB_URI. Use 'get_default_libraries_yml' for the format of the expected libraries.yml file """ db_uri = get_db_uri(args) diff --git a/configs.py.dist b/configs.py.dist deleted file mode 100644 index f7cfd8877..000000000 --- a/configs.py.dist +++ /dev/null @@ -1 +0,0 @@ -DB_URI = "" \ No newline at end of file diff --git a/docs/reference/cli_tool.md b/docs/reference/cli_tool.md index 423055411..903406166 100644 --- a/docs/reference/cli_tool.md +++ b/docs/reference/cli_tool.md @@ -23,8 +23,7 @@ Recall that a `Library` is a unit of distribution for shapes (for validation of ```bash usage: buildingmotif load [-h] [-d DB] [--dir DIR [DIR ...]] [-o ONT [ONT ...]] [-l LIBRARY_MANIFEST_FILE [LIBRARY_MANIFEST_FILE ...]] -Loads libraries from (1) local directories (--dir), (2) local or remote ontology files (--ont) (3) library spec file (--libraries): the provided YML file into the BuildingMOTIF instance at $DB_URI or whatever -is in 'configs.py'. Use 'get_default_libraries_yml' for the format of the expected libraries.yml file +Loads libraries from (1) local directories (--dir), (2) local or remote ontology files (--ont) (3) library spec file (--libraries): the provided YML file into the BuildingMOTIF instance at $DB_URI optional arguments: -h, --help show this help message and exit diff --git a/docs/reference/developer_documentation.md b/docs/reference/developer_documentation.md index b8d9a0b06..c5299050b 100644 --- a/docs/reference/developer_documentation.md +++ b/docs/reference/developer_documentation.md @@ -21,12 +21,9 @@ ## Developing -To initialize your database, create your local configs file, enter your db uri, and run the migrations. +To initialize your database, init $DB_URI (set in `.env`) and run the migrations. ``` -cp configs.py.dist configs.py - -echo "DB_URI = 'sqlite:////path/to/db.db'" > configs.py - +set -o allexport; source .env; set +o allexport poetry run alembic upgrade head ``` diff --git a/migrations/env.py b/migrations/env.py index bed498fc7..0a6040f15 100644 --- a/migrations/env.py +++ b/migrations/env.py @@ -10,19 +10,13 @@ _custom_json_serializer, ) -# If config doesn't exist, this is considered a third party import and module cant be found. -import configs as building_motif_configs # type: ignore # isort:skip - # this is the Alembic Config object, which provides # access to the values within the .ini file in use. config = context.config -# custom url from configs. Prioritize OS environment variable +# custom url from environment variable db_uri = os.getenv("DB_URI") -if db_uri is not None: - config.set_main_option("sqlalchemy.url", db_uri) -else: - config.set_main_option("sqlalchemy.url", building_motif_configs.DB_URI) +config.set_main_option("sqlalchemy.url", db_uri) # Interpret the config file for Python logging. # This line sets up loggers basically. From a672a6fc3cabd9870d847f86da8bb4e1d3f8d0e7 Mon Sep 17 00:00:00 2001 From: Hannah Eslinger Date: Fri, 26 May 2023 10:52:50 -0600 Subject: [PATCH 2/5] Update docs/reference/cli_tool.md Co-authored-by: Matt Steen --- docs/reference/cli_tool.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reference/cli_tool.md b/docs/reference/cli_tool.md index 903406166..b56f87cd5 100644 --- a/docs/reference/cli_tool.md +++ b/docs/reference/cli_tool.md @@ -23,7 +23,7 @@ Recall that a `Library` is a unit of distribution for shapes (for validation of ```bash usage: buildingmotif load [-h] [-d DB] [--dir DIR [DIR ...]] [-o ONT [ONT ...]] [-l LIBRARY_MANIFEST_FILE [LIBRARY_MANIFEST_FILE ...]] -Loads libraries from (1) local directories (--dir), (2) local or remote ontology files (--ont) (3) library spec file (--libraries): the provided YML file into the BuildingMOTIF instance at $DB_URI +Loads libraries from (1) local directories (--dir), (2) local or remote ontology files (--ont), or (3) library spec file (--libraries): the provided YML file into the BuildingMOTIF instance at $DB_URI optional arguments: -h, --help show this help message and exit From e1fde848e792f53135e51f705798e14fc7354b17 Mon Sep 17 00:00:00 2001 From: Hannah Eslinger Date: Tue, 30 May 2023 12:06:58 -0600 Subject: [PATCH 3/5] Fix linter --- migrations/env.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/migrations/env.py b/migrations/env.py index 0a6040f15..937c65e51 100644 --- a/migrations/env.py +++ b/migrations/env.py @@ -16,6 +16,8 @@ # custom url from environment variable db_uri = os.getenv("DB_URI") +if db_uri is None: + raise ValueError("envvar DB_URI not set.") config.set_main_option("sqlalchemy.url", db_uri) # Interpret the config file for Python logging. From e268f27091099db7000edc8bbd77a7cd67d40aa2 Mon Sep 17 00:00:00 2001 From: Hannah Eslinger Date: Fri, 2 Jun 2023 15:17:37 -0600 Subject: [PATCH 4/5] Raise error when DB_URI is not set --- buildingmotif/api/app.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/buildingmotif/api/app.py b/buildingmotif/api/app.py index dca141abc..00659a0d2 100644 --- a/buildingmotif/api/app.py +++ b/buildingmotif/api/app.py @@ -69,6 +69,8 @@ def create_app(DB_URI): if __name__ == "__main__": """Run API.""" db_uri = os.getenv("DB_URI") + if db_uri is None: + raise ValueError("Environment variable DB_URI not set.") app = create_app(db_uri) app.run(debug=True, host="0.0.0.0", threaded=False) From a5ed13704e1edf6e98a85f2742ae2bd76f50bb4d Mon Sep 17 00:00:00 2001 From: Matt Steen Date: Mon, 14 Aug 2023 14:18:37 -0700 Subject: [PATCH 5/5] add note for windows users to dev docs --- docs/reference/developer_documentation.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/reference/developer_documentation.md b/docs/reference/developer_documentation.md index c5299050b..440266182 100644 --- a/docs/reference/developer_documentation.md +++ b/docs/reference/developer_documentation.md @@ -21,7 +21,8 @@ ## Developing -To initialize your database, init $DB_URI (set in `.env`) and run the migrations. +### Database +Initialize a database by setting it in the `.env` file, then run the migrations. Note for Windows users, the following commands require a Unix shell, e.g. Bash. ``` set -o allexport; source .env; set +o allexport poetry run alembic upgrade head