Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove configs.py #256

Merged
merged 6 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ docs/reference/apidoc/_autosummary


# project
configs.py
buildingmotif-app/node_modules/
**/BuildingMOTIF.log
*.db
1 change: 0 additions & 1 deletion buildingmotif/api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
5 changes: 1 addition & 4 deletions buildingmotif/api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,7 @@ def create_app(DB_URI):
"""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
raise ValueError("Environment variable DB_URI not set.")

app = create_app(db_uri)
haneslinger marked this conversation as resolved.
Show resolved Hide resolved
app.run(debug=True, host="0.0.0.0", threaded=False)
12 changes: 1 addition & 11 deletions buildingmotif/bin/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion configs.py.dist

This file was deleted.

3 changes: 1 addition & 2 deletions docs/reference/cli_tool.md
Original file line number Diff line number Diff line change
Expand Up @@ -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), 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
Expand Down
8 changes: 3 additions & 5 deletions docs/reference/developer_documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@

## Developing

To initialize your database, create your local configs file, enter your db uri, 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.
```
cp configs.py.dist configs.py

echo "DB_URI = 'sqlite:////path/to/db.db'" > configs.py

set -o allexport; source .env; set +o allexport
MatthewSteen marked this conversation as resolved.
Show resolved Hide resolved
poetry run alembic upgrade head
```

Expand Down
12 changes: 4 additions & 8 deletions migrations/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,15 @@
_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)
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.
# This line sets up loggers basically.
Expand Down