vdb/lib/utils.py
def convert_to_semver(version):
    """
    Convert an incomplete version string into a semver-compatible VersionInfo
    object

    * Tries to detect a "basic" version string (``major.minor.patch``).
    * If not enough components can be found, missing components are
        set to zero to obtain a valid semver version.

    :param str version: the version string to convert
    :return: a tuple with a :class:`VersionInfo` instance (or ``None``
        if it's not a version) and the rest of the string which doesn't
        belong to a basic version.
    :rtype: tuple(:class:`VersionInfo` | None, str)
    """
    match = BASEVERSION.search(version)
    if not match:
        return (None, version)

    ver = {
        key: 0 if value is None else value for key, value in match.groupdict().items()
    }
    # Trim based on known prerelease strings
    if ver.get("prerelease"):
        try:
            prefloat = float(ver.get("prerelease"))
            ver["prerelease"] = int(prefloat)
        except Exception:
            pre_str = ver.get("prerelease", "").lower()
            for s in KNOWN_PRERELEASE_STR:
                if s in pre_str:
                    ver["prerelease"] = 0
                    ver["build"] = 0
                    break

    ver = VersionInfo(**ver)
    rest = match.string[match.end() :]  # noqa:E203
    number_part = convert_to_num(rest)
    date_obj = None
    if "-" in version:
        try:
            date_obj = date.fromisoformat(version)
        except Exception:
            date_obj = None
    # Is this a date as used by go packages
    if date_obj and date_obj.year == ver.major and not ver.minor and not ver.patch:
        ver = VersionInfo(
            major=0,
            minor=0,
            patch=0,
            prerelease=int(f"{version.replace('-', '')[:8]}000000"),
            build=0,
        )
    if not number_part:
        rest = None
    return ver, rest

    Convert an incomplete version string into a semver-compatible VersionInfo
    object

    * Tries to detect a "basic" version string (``major.minor.patch``).
    * If not enough components can be found, missing components are
        set to zero to obtain a valid semver version.

    :param str version: the version string to convert
    :return: a tuple with a :class:`VersionInfo` instance (or ``None``
        if it's not a version) and the rest of the string which doesn't
        belong to a basic version.
    :rtype: tuple(:class:`VersionInfo` | None, str)
    
Convert an incomplete version string into a semver-compatible VersionInfo
object

Tries to detect a "basic" version string (``major.minor.patch``).
If not enough components can be found, missing components are
set to zero to obtain a valid semver version.
Convert an incomplete version string into a semver - compatible VersionInfo object Tries to detect a " basic " version string ( ` ` major . minor . patch ` ` ) . If not enough components can be found missing components are set to zero to obtain a valid semver version .
def convert_to_semver(version):
    match = BASEVERSION.search(version)
    if not match:
        return (None, version)
    ver = {
        key: 0 if value is None else value for key, value in match.groupdict().items()
    }
    if ver.get("prerelease"):
        try:
            prefloat = float(ver.get("prerelease"))
            ver["prerelease"] = int(prefloat)
        except Exception:
            pre_str = ver.get("prerelease", "").lower()
            for s in KNOWN_PRERELEASE_STR:
                if s in pre_str:
                    ver["prerelease"] = 0
                    ver["build"] = 0
                    break
    ver = VersionInfo(**ver)
    rest = match.string[match.end() :]  
    number_part = convert_to_num(rest)
    date_obj = None
    if "-" in version:
        try:
            date_obj = date.fromisoformat(version)
        except Exception:
            date_obj = None
    if date_obj and date_obj.year == ver.major and not ver.minor and not ver.patch:
        ver = VersionInfo(
            major=0,
            minor=0,
            patch=0,
            prerelease=int(f"{version.replace('-', '')[:8]}000000"),
            build=0,
        )
    if not number_part:
        rest = None
    return ver, rest
def convert_to_semver ( version ) : match = BASEVERSION . search ( version ) if not match : return ( None , version ) ver = { key : 0 if value is None else value for key , value in match . groupdict ( ) . items ( ) } if ver . get ( "prerelease" ) : try : prefloat = float ( ver . get ( "prerelease" ) ) ver [ "prerelease" ] = int ( prefloat ) except Exception : pre_str = ver . get ( "prerelease" , "" ) . lower ( ) for s in KNOWN_PRERELEASE_STR : if s in pre_str : ver [ "prerelease" ] = 0 ver [ "build" ] = 0 break ver = VersionInfo ( ** ver ) rest = match . string [ match . end ( ) : ] number_part = convert_to_num ( rest ) date_obj = None if "-" in version : try : date_obj = date . fromisoformat ( version ) except Exception : date_obj = None if date_obj and date_obj . year == ver . major and not ver . minor and not ver . patch : ver = VersionInfo ( major = 0 , minor = 0 , patch = 0 , prerelease = int ( f"{version.replace('-', '')[:8]}000000" ) , build = 0 , ) if not number_part : rest = None return ver , rest
Convert an incomplete version string into a semver-compatible VersionInfo
object
Convert an incomplete version string into a semver - compatible VersionInfo object
"""
    Convert an incomplete version string into a semver-compatible VersionInfo
    object

    * Tries to detect a "basic" version string (``major.minor.patch``).
    * If not enough components can be found, missing components are
        set to zero to obtain a valid semver version.

    :param str version: the version string to convert
    :return: a tuple with a :class:`VersionInfo` instance (or ``None``
        if it's not a version) and the rest of the string which doesn't
        belong to a basic version.
    :rtype: tuple(:class:`VersionInfo` | None, str)
    """ # Trim based on known prerelease strings # noqa:E203 # Is this a date as used by go packages
a tuple with a :class:`VersionInfo` instance (or ``None``
if it's not a version) and the rest of the string which doesn't
belong to a basic version.
a tuple with a : class : ` VersionInfo ` instance ( or ` ` None ` ` if it ' s not a version ) and the rest of the string which doesn ' t belong to a basic version .
tuple(:class:`VersionInfo` | None, str)
version
the version string to convert
the version string to convert