Skip to content
This repository was archived by the owner on Jun 30, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion medcat/storage/serialisers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
from medcat.storage.serialisables import get_all_serialisable_members
from medcat.storage.schema import load_schema, save_schema
from medcat.storage.schema import DEFAULT_SCHEMA_FILE, IllegalSchemaException
from medcat.utils.legacy.v2_beta import (
fix_module_and_cls_name, RemappingUnpickler)


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -146,6 +148,7 @@ def deserialise_manually(cls, folder_path: str, man_cls_path: str,
**init_kwargs) -> Serialisable:
logger.info("Deserialising manually based on %s", man_cls_path)
module_name, cls_name = man_cls_path.rsplit(".", 1)
module_name, cls_name = fix_module_and_cls_name(module_name, cls_name)
rel_module = importlib.import_module(module_name)
man_cls = getattr(rel_module, cls_name)
if not issubclass(man_cls, ManualSerialisable):
Expand Down Expand Up @@ -253,7 +256,7 @@ def serialise(self, raw_parts: dict[str, Any], target_file: str) -> None:

def deserialise(self, target_file: str) -> dict[str, Any]:
with open(target_file, 'rb') as f:
return _dill.load(f)
return RemappingUnpickler(f).load()


_DEF_SER = AvailableSerialisers.dill
Expand Down
16 changes: 16 additions & 0 deletions medcat/utils/legacy/v2_beta.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import dill


class RemappingUnpickler(dill.Unpickler):
# TODO: remove at some point - this only serves to load beta models
def find_class(self, module: str, name: str):
# Remap old module path to new one
module, name = fix_module_and_cls_name(module, name)
return super().find_class(module, name)


def fix_module_and_cls_name(module_name: str, cls_name: str
) -> tuple[str, str]:
if module_name.startswith("medcat2"):
module_name = module_name.replace("medcat2", "medcat", 1)
return module_name, cls_name
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# fail upon individual failure
set -euo pipefail
# CONSTANTs/ shouldn't change
REGRESSION_MODULE="medcat.utils.regression.regression_checker"
REGRESSION_OPTIONS="--strictness STRICTEST --require-fully-correct"
Expand Down