nip.utils.version.compare_versions

nip.utils.version.compare_versions#

nip.utils.version.compare_versions(version_1: str | tuple[int, int, int] | tuple[int, int] | tuple[int] | None, version_2: str | tuple[int, int, int] | tuple[int, int] | tuple[int] | None) tuple[Literal['less', 'greater', 'match'], Literal['major', 'minor', 'patch', 'none']][source]#

Compare two version strings, checking major, minor, and patch numbers.

Less specific versions are treated a specifying a range of versions. E.g. “1.5” is treated as “1.5.x” and “1” is treated as “1.x.x”. This means that “1.5” is less than “1.6.3” but matches “1.5.3”.

Versions can be specified as strings, tuples of integers or None. If None is passed, it is treated as older than any other version.

Parameters:
  • version_1 (str | VersionTupleType | None) – The first version to compare. Can be a version string, a tuple of integers or None.

  • version_2 (str | VersionTupleType | None) – The second version to compare. Can be a version string, a tuple of integers or None.

Returns:

  • comparison (Literal[“less”, “greater”, “match”]) – The result of the comparison. If version_1 < version_2, returns “less”. If version_1 > version_2, returns “greater”. If the two versions compatible (i.e. they are the same up to the level of detail in both), returns “match”.

  • difference (Literal[“major”, “minor”, “patch”, “none”]) – The level of difference between the two versions. If the major version is different, returns “major”. If the minor version is different, returns “minor”. If the patch version is different, returns “patch”. If all versions are the same, returns “none”.