Skip to content

Commit

Permalink
fix: catch ETL module import errors (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsstevenson authored Nov 7, 2023
1 parent 5b30228 commit 8eb2bfb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ export DISEASE_NORM_DB_URL="postgresql://postgres@localhost:5432/disease_normali

Use the `disease_norm_update` command in a shell to update the database.

If you encounter an error message like the following, refer to the installation instructions above:

```shell
"Encountered ModuleNotFoundError attempting to import Mondo. Are ETL dependencies installed?"
```

#### Update source(s)

The Disease Normalizer currently uses data from the following sources:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Source = "https://github.com/cancervariants/disease-normalization"
"Bug Tracker" = "https://github.com/cancervariants/disease-normalization/issues"

[project.scripts]
disease_norm_update = "disease.cli:update_normalizer_db"
disease_norm_update = "disease.cli:update_db"
disease_norm_update_remote = "disease.cli:update_from_remote"
disease_norm_dump = "disease.cli:dump_database"
disease_norm_check_db = "disease.cli:check_db"
Expand Down
24 changes: 16 additions & 8 deletions src/disease/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,8 @@
DatabaseWriteException,
create_db,
)
from disease.etl import DO, OMIM, Mondo, NCIt, OncoTree # noqa: F401
from disease.etl.merge import Merge
from disease.schemas import SourceName

# Use to lookup class object from source name. Should be one key-value pair
# for every functioning ETL class.
SOURCES_CLASS_LOOKUP = {
s.value.lower(): eval(s.value) for s in SourceName.__members__.values()
}


@click.command()
@click.option("--db_url", help="URL endpoint for the application database.")
Expand Down Expand Up @@ -176,6 +168,13 @@ def _load_source(
start_load = timer()

# used to get source class name from string
try:
from disease.etl import DO, OMIM, Mondo, NCIt, OncoTree # noqa: F401
except ModuleNotFoundError as e:
click.echo(
f"Encountered ModuleNotFoundError attempting to import {e.name}. Are ETL dependencies installed?"
)
click.get_current_context().exit()
SourceClass = eval(n.value) # noqa: N806

source = SourceClass(database=db)
Expand Down Expand Up @@ -219,6 +218,15 @@ def _load_merge(db: AbstractDatabase, processed_ids: Set[str]) -> None:
processed_ids = set()
for source in SOURCES_FOR_MERGE:
processed_ids |= db.get_all_concept_ids(source)

try:
from disease.etl.merge import Merge
except ModuleNotFoundError as e:
click.echo(
f"Encountered ModuleNotFoundError attempting to import {e.name}. Are ETL dependencies installed?"
)
click.get_current_context().exit()

merge = Merge(database=db)
click.echo("Constructing normalized records...")
merge.create_merged_concepts(processed_ids)
Expand Down

0 comments on commit 8eb2bfb

Please sign in to comment.