medcat.utils.versioning

Module Contents

Classes

ConfigUpgrader

Config updater.

Functions

get_semantic_version(version)

Get the semantiv version from the string.

get_version_from_modelcard(d)

Gets the the major.minor.patch version from a model card.

get_semantic_version_from_model(cat)

Get the semantic version of a CAT model.

get_version_from_cdb_dump(cdb_path)

Get the version from a CDB dump (cdb.dat).

get_version_from_modelpack_zip(zip_path[, cdb_file_name])

Get the semantic version from a MedCAT model pack zip file.

parse_args()

Parse the arguments from the CLI.

setup_logging(args)

Setup logging for the runnable based on CLI arguments.

fix_config(args)

Perform the fix-config action based on the CLI arguments.

main()

Run the CLI associated with this module.

Attributes

logger

SemanticVersion

SEMANTIC_VERSION_REGEX

SEMANTIC_VERSION_PATTERN

CDB_FILE_NAME

UPDATE_VERSION

medcat.utils.versioning.logger
medcat.utils.versioning.SemanticVersion
medcat.utils.versioning.SEMANTIC_VERSION_REGEX = '^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(?:dev)?(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:...'
medcat.utils.versioning.SEMANTIC_VERSION_PATTERN
medcat.utils.versioning.CDB_FILE_NAME = 'cdb.dat'
medcat.utils.versioning.get_semantic_version(version)

Get the semantiv version from the string.

Parameters:

version (str) – The version string.

Raises:

ValueError – If the version string does not match the semantic versioning format.

Returns:

SemanticVersion – The major, minor and patch version

Return type:

SemanticVersion

medcat.utils.versioning.get_version_from_modelcard(d)

Gets the the major.minor.patch version from a model card.

The version needs to be specified at:

model_card[“MedCAT Version”]

The version is expected to be semantic (major.minor.patch).

Parameters:

d (dict) – The model card in dict format.

Returns:

SemanticVersion – The major, minor and patch version

Return type:

SemanticVersion

medcat.utils.versioning.get_semantic_version_from_model(cat)

Get the semantic version of a CAT model.

This uses the get_version_from_modelcard method on the model’s model card.

So it is equivalen to get_version_from_modelcard(cat.get_model_card(as_dict=True)).

Parameters:

cat (CAT) – The CAT model.

Returns:

SemanticVersion – The major, minor and patch version

Return type:

SemanticVersion

medcat.utils.versioning.get_version_from_cdb_dump(cdb_path)

Get the version from a CDB dump (cdb.dat).

The version information is expected in the following location:

cdb[“config”][“version”][“medcat_version”]

Parameters:

cdb_path (str) – The path to cdb.dat

Returns:

SemanticVersion – The major, minor and patch version

Return type:

SemanticVersion

medcat.utils.versioning.get_version_from_modelpack_zip(zip_path, cdb_file_name=CDB_FILE_NAME)

Get the semantic version from a MedCAT model pack zip file.

This involves simply reading the config on file and reading the version information from there.

The zip file is extracted if it has not yet been extracted.

Parameters:
  • zip_path (str) – The zip file path for the model pack.

  • cdb_file_name (str, optional) – The CDB file name to use. Defaults to “cdb.dat”.

Returns:

SemanticVersion – The major, minor and patch version

Return type:

SemanticVersion

medcat.utils.versioning.UPDATE_VERSION = (1, 3, 0)
class medcat.utils.versioning.ConfigUpgrader(zip_path, cdb_file_name=CDB_FILE_NAME)

Config updater.

Attempts to upgrade pre 1.3.0 medcat configs to the newer format.

Parameters:
  • zip_path (str) – The model pack zip path.

  • cdb_file_name (str, optional) – The CDB file name. Defaults to “cdb.dat”.

__init__(zip_path, cdb_file_name=CDB_FILE_NAME)
Parameters:
  • zip_path (str) –

  • cdb_file_name (str) –

Return type:

None

needs_upgrade()

Check if the specified modelpack needs an upgrade.

It needs an upgrade if its version is less than 1.3.0.

Returns:

bool – Whether or not an upgrade is needed.

Return type:

bool

_get_relevant_files(ignore_hidden=True)

Get the list of relevant files with full path names.

By default this will ignore hidden files (those that start with ‘.’).

Parameters:

ignore_hidden (bool) – Whether to ignore hidden files. Defaults to True.

Returns:

List[str] – The list of relevant file names to copy.

Return type:

List[str]

_check_existance(files_to_copy, new_path, overwrite)
Parameters:
  • files_to_copy (List[str]) –

  • new_path (str) –

  • overwrite (bool) –

_copy_files(files_to_copy, new_path)
Parameters:
  • files_to_copy (List[str]) –

  • new_path (str) –

Return type:

None

upgrade(new_path, overwrite=False)

Upgrade the model.

The upgrade copies all the files from the original folder to the new folder.

After copying, it changes the config into the format required by MedCAT after version 1.3.0.

Parameters:
  • new_path (str) – The path for the new model pack folder.

  • overwrite (bool) – Whether to overwrite new path. Defaults to False.

Raises:
  • ValueError – If one of the target files exists and cannot be overwritten.

  • ValueError – If model pack does not need an upgrade

Return type:

None

_fix_cdb(new_path)
Parameters:

new_path (str) –

Return type:

None

_make_archive(new_path)
Parameters:

new_path (str) –

medcat.utils.versioning.parse_args()

Parse the arguments from the CLI.

Returns:

argparse.Namespace – The parsed arguments.

Return type:

argparse.Namespace

medcat.utils.versioning.setup_logging(args)

Setup logging for the runnable based on CLI arguments.

Parameters:

args (argparse.Namespace) – The parsed arguments.

Return type:

None

medcat.utils.versioning.fix_config(args)

Perform the fix-config action based on the CLI arguments.

Parameters:

args (argparse.Namespace) – The parsed arguments.

Return type:

None

medcat.utils.versioning.main()

Run the CLI associated with this module.

Raises:

ValueError – If an unknown action is provided.

Return type:

None