Versions

Utility functions for handling version compatibility.

This module contains functions that help managing the versions of different Fed-BioMed components.

See https://fedbiomed.org/latest/user-guide/deployment/versions or ./doc/user-guide/deployment/versions.md for more information

Attributes

FBM_Component_Version module-attribute

FBM_Component_Version = Version

The Type of objects representing version numbers in Fed-BioMed

Classes

Functions

raise_for_version_compatibility

raise_for_version_compatibility(their_version, our_version, error_msg=None)

Check version compatibility and behave accordingly.

Raises an exception if the versions are incompatible, otherwise outputs a warning or info message.

Parameters:

Name Type Description Default
their_version Union[FBM_Component_Version, str]

the version that we detected in the component

required
our_version Union[FBM_Component_Version, str]

the version of the component within the current runtime

required
error_msg Optional[str]

an optional error message. It may contain two %s placeholders which will be substituted with the values of their_version and our_version.

None

Raises:

Type Description
FedbiomedVersionError

if the versions are incompatible

Source code in fedbiomed/common/utils/_versions.py
def raise_for_version_compatibility(their_version: Union[FBM_Component_Version, str],
                                    our_version: Union[FBM_Component_Version, str],
                                    error_msg: Optional[str] = None) -> None:
    """Check version compatibility and behave accordingly.

    Raises an exception if the versions are incompatible, otherwise outputs a warning or info message.

    Args:
        their_version: the version that we detected in the component
        our_version: the version of the component within the current runtime
        error_msg: an optional error message. It may contain two %s placeholders which will be substituted with
            the values of their_version and our_version.

    Raises:
        FedbiomedVersionError: if the versions are incompatible
    """
    if isinstance(our_version, str):
        our_version = FBM_Component_Version(our_version)
    if isinstance(their_version, str):
        their_version = FBM_Component_Version(their_version)
    if not isinstance(our_version, FBM_Component_Version):
        msg = f"{ErrorNumbers.FB625.value}: Component version has incorrect type `our_version` type={str(type(our_version))} value={our_version}"
        logger.critical(msg)
        raise FedbiomedVersionError(msg)
    if not isinstance(their_version, FBM_Component_Version):
        msg = f"{ErrorNumbers.FB625.value}: Component version has incorrect type `their_version` type={str(type(their_version))} value={their_version}"
        logger.critical(msg)
        raise FedbiomedVersionError(msg)
    if our_version != their_version:
        # note: the checks below rely on the short-circuiting behaviour of the or operator
        # (e.g. when checking our_version.minor < their_version.minor we have the guarantee that
        # our_version.major == their_version.major
        if our_version.major != their_version.major or \
                our_version.minor < their_version.minor or \
                (our_version.minor == their_version.minor and our_version.micro < their_version.micro):
            msg = _create_msg_for_version_check(
                f"{ErrorNumbers.FB625.value}: Found incompatible version %s, expected version %s" if error_msg is None else error_msg,
                their_version,
                our_version
            )
            logger.critical(msg)
            raise FedbiomedVersionError(msg)
        else:
            msg = _create_msg_for_version_check(
                "Found version %s, expected version %s",
                their_version,
                our_version
            )
            logger.warning(msg)