Skip to content

Commit

Permalink
fix: catch ETL module import errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jsstevenson committed Nov 3, 2023
1 parent af0ff13 commit c7591c8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 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
18 changes: 16 additions & 2 deletions src/disease/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
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
Expand Down Expand Up @@ -176,6 +174,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 +224,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 c7591c8

Please sign in to comment.