:py:mod:`medcat.utils.versioning` ================================= .. py:module:: medcat.utils.versioning Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: medcat.utils.versioning.ConfigUpgrader Functions ~~~~~~~~~ .. autoapisummary:: medcat.utils.versioning.get_semantic_version medcat.utils.versioning.get_version_from_modelcard medcat.utils.versioning.get_semantic_version_from_model medcat.utils.versioning.get_version_from_cdb_dump medcat.utils.versioning.get_version_from_modelpack_zip medcat.utils.versioning.parse_args medcat.utils.versioning.setup_logging medcat.utils.versioning.fix_config medcat.utils.versioning.main Attributes ~~~~~~~~~~ .. autoapisummary:: medcat.utils.versioning.logger medcat.utils.versioning.SemanticVersion medcat.utils.versioning.SEMANTIC_VERSION_REGEX medcat.utils.versioning.SEMANTIC_VERSION_PATTERN medcat.utils.versioning.CDB_FILE_NAME medcat.utils.versioning.UPDATE_VERSION .. py:data:: logger .. py:data:: SemanticVersion .. py:data:: SEMANTIC_VERSION_REGEX :value: '^(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-]*)(?:...' .. py:data:: SEMANTIC_VERSION_PATTERN .. py:data:: CDB_FILE_NAME :value: 'cdb.dat' .. py:function:: get_semantic_version(version) Get the semantiv version from the string. :param version: The version string. :type version: str :raises ValueError: If the version string does not match the semantic versioning format. :Returns: **SemanticVersion** -- The major, minor and patch version .. py:function:: 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). :param d: The model card in dict format. :type d: dict :Returns: **SemanticVersion** -- The major, minor and patch version .. py:function:: 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))`. :param cat: The CAT model. :type cat: CAT :Returns: **SemanticVersion** -- The major, minor and patch version .. py:function:: 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"] :param cdb_path: The path to cdb.dat :type cdb_path: str :Returns: **SemanticVersion** -- The major, minor and patch version .. py:function:: 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. :param zip_path: The zip file path for the model pack. :type zip_path: str :param cdb_file_name: The CDB file name to use. Defaults to "cdb.dat". :type cdb_file_name: str, optional :Returns: **SemanticVersion** -- The major, minor and patch version .. py:data:: UPDATE_VERSION :value: (1, 3, 0) .. py:class:: ConfigUpgrader(zip_path, cdb_file_name = CDB_FILE_NAME) Config updater. Attempts to upgrade pre 1.3.0 medcat configs to the newer format. :param zip_path: The model pack zip path. :type zip_path: str :param cdb_file_name: The CDB file name. Defaults to "cdb.dat". :type cdb_file_name: str, optional .. py:method:: __init__(zip_path, cdb_file_name = CDB_FILE_NAME) .. py:method:: 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. .. py:method:: _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 '.'). :param ignore_hidden: Whether to ignore hidden files. Defaults to True. :type ignore_hidden: bool :Returns: **List[str]** -- The list of relevant file names to copy. .. py:method:: _check_existance(files_to_copy, new_path, overwrite) .. py:method:: _copy_files(files_to_copy, new_path) .. py:method:: 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. :param new_path: The path for the new model pack folder. :type new_path: str :param overwrite: Whether to overwrite new path. Defaults to False. :type overwrite: bool :raises ValueError: If one of the target files exists and cannot be overwritten. :raises ValueError: If model pack does not need an upgrade .. py:method:: _fix_cdb(new_path) .. py:method:: _make_archive(new_path) .. py:function:: parse_args() Parse the arguments from the CLI. :Returns: **argparse.Namespace** -- The parsed arguments. .. py:function:: setup_logging(args) Setup logging for the runnable based on CLI arguments. :param args: The parsed arguments. :type args: argparse.Namespace .. py:function:: fix_config(args) Perform the fix-config action based on the CLI arguments. :param args: The parsed arguments. :type args: argparse.Namespace .. py:function:: main() Run the CLI associated with this module. :raises ValueError: If an unknown action is provided.