|
27 | 27 | from medcat.components.types import AbstractCoreComponent, HashableComponet
|
28 | 28 | from medcat.components.addons.addons import AddonComponent
|
29 | 29 | from medcat.utils.legacy.identifier import is_legacy_model_pack
|
30 |
| -from medcat.utils.defaults import AVOID_LEGACY_CONVERSION_ENVIRON |
| 30 | +from medcat.utils.defaults import avoid_legacy_conversion |
| 31 | +from medcat.utils.defaults import doing_legacy_conversion_message |
| 32 | +from medcat.utils.defaults import LegacyConversionDisabledError |
31 | 33 | from medcat.utils.usage_monitoring import UsageMonitor
|
32 | 34 |
|
33 | 35 |
|
@@ -602,22 +604,13 @@ def load_model_pack(cls, model_pack_path: str) -> 'CAT':
|
602 | 604 | logger.info("Attempting to load model from file: %s",
|
603 | 605 | model_pack_path)
|
604 | 606 | is_legacy = is_legacy_model_pack(model_pack_path)
|
605 |
| - should_avoid = os.environ.get( |
606 |
| - AVOID_LEGACY_CONVERSION_ENVIRON, "False").lower() == "true" |
607 |
| - if is_legacy and not should_avoid: |
| 607 | + avoid_legacy = avoid_legacy_conversion() |
| 608 | + if is_legacy and not avoid_legacy: |
608 | 609 | from medcat.utils.legacy.conversion_all import Converter
|
609 |
| - logger.warning( |
610 |
| - "Doing legacy conversion on model pack '%s'. " |
611 |
| - "This will make the model load take significantly longer. " |
612 |
| - "If you wish to avoid this, set the environment variable '%s' " |
613 |
| - "to 'true'", model_pack_path, AVOID_LEGACY_CONVERSION_ENVIRON) |
| 610 | + doing_legacy_conversion_message(logger, 'CAT', model_pack_path) |
614 | 611 | return Converter(model_pack_path, None).convert()
|
615 |
| - elif is_legacy and should_avoid: |
616 |
| - raise ValueError( |
617 |
| - f"The model pack '{model_pack_path}' is a legacy model pack. " |
618 |
| - "Please set the environment variable " |
619 |
| - f"'{AVOID_LEGACY_CONVERSION_ENVIRON}' " |
620 |
| - "to 'true' to allow automatic conversion.") |
| 612 | + elif is_legacy and avoid_legacy: |
| 613 | + raise LegacyConversionDisabledError("CAT") |
621 | 614 | # NOTE: ignoring addons since they will be loaded later / separately
|
622 | 615 | cat = deserialise(model_pack_path, model_load_path=model_pack_path,
|
623 | 616 | ignore_folders_prefix={
|
|
0 commit comments