From c6c9a70b0cf063951a44044867fb6222bfaed6d6 Mon Sep 17 00:00:00 2001 From: James Stevenson Date: Fri, 15 Sep 2023 11:23:45 -0700 Subject: [PATCH] fix: catch ETL module import errors (#249) --- gene/cli.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/gene/cli.py b/gene/cli.py index 4c78666d..8fe852f5 100644 --- a/gene/cli.py +++ b/gene/cli.py @@ -15,9 +15,6 @@ create_db, ) from gene.database.database import DatabaseException -from gene.etl import HGNC, NCBI, Ensembl # noqa: F401 -from gene.etl.exceptions import GeneNormalizerEtlError -from gene.etl.merge import Merge from gene.schemas import SourceName logger = logging.getLogger("gene") @@ -176,6 +173,14 @@ def _load_source( start_load = timer() # used to get source class name from string + try: + from gene.etl import HGNC, NCBI, Ensembl # noqa: F401 + from gene.etl.exceptions import GeneNormalizerEtlError + 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) @@ -221,6 +226,15 @@ def _load_merge(db: AbstractDatabase, processed_ids: Set[str]) -> None: _delete_normalized_data(db) if not processed_ids: processed_ids = db.get_all_concept_ids() + + try: + from gene.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)