Skip to content

Commit 4549d9d

Browse files
authored
CU-8699qzfdk Improve optional part checks (#113)
* CU-8699qzfdk: Fix issue with MetaCAT local imports happening before ensurance of optional parts having been installed * CU-8699qzfdk: Fix issue with dcti-based NER - avoid doing local imports before knowing they are available
1 parent e142203 commit 4549d9d

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

medcat-v2/medcat/components/addons/meta_cat/__init__.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
from medcat.utils.import_utils import ensure_optional_extras_installed
22
import medcat
33

4-
from .meta_cat import (MetaCAT, MetaCATAddon,
4+
_EXTRA_NAME = "meta-cat"
5+
ensure_optional_extras_installed(medcat.__name__, _EXTRA_NAME)
6+
7+
# NOTE: need to check above before local imports, otherwise there's no
8+
# point since the imports below will have already failed
9+
10+
from .meta_cat import (MetaCAT, MetaCATAddon, # noqa
511
get_meta_annotations, MetaAnnotationValue)
612

713

814
__all__ = ["MetaCAT", "MetaCATAddon",
915
"get_meta_annotations", "MetaAnnotationValue"]
1016

1117
# NOTE: the _ is converted to - automatically
12-
_EXTRA_NAME = "meta-cat"
13-
14-
15-
ensure_optional_extras_installed(medcat.__name__, _EXTRA_NAME)

medcat-v2/medcat/components/ner/dict_based_ner.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@
99
from medcat.vocab import Vocab
1010
from medcat.cdb import CDB
1111
from medcat.config.config import ComponentConfig
12-
13-
from ahocorasick import Automaton
1412
import medcat
1513

1614

1715
# NOTE: the _ is converted to - automatically
1816
_EXTRA_NAME = "dict-ner"
1917

20-
18+
# NOTE: need to do this before below import for more useful error
2119
ensure_optional_extras_installed(medcat.__name__, _EXTRA_NAME)
2220

21+
from ahocorasick import Automaton # noqa
22+
2323

2424
logger = logging.getLogger(__name__)
2525

0 commit comments

Comments
 (0)