How to use the distlib.version.NormalizedVersion function in distlib

To help you get started, we’ve selected a few distlib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SNH48Live / KVM48 / src / kvm48 / update.py View on Github external
def check_update_or_print_whats_new(force: bool = False) -> None:
    last_check_date, last_check_version = load_last_check_info()
    write_last_check_info()

    # Only print what's new when the program has checked for updates in
    # the past, and the version that last checked for updates is older
    # than the current running version, and the current running version
    # is not a dev version. Filters out new installations.
    print_whats_new = True
    if not last_check_date:
        print_whats_new = False
    if "dev" in __version__:
        print_whats_new = False
    try:
        if NormalizedVersion(last_check_version) >= NormalizedVersion(__version__):
            print_whats_new = False
    except UnsupportedVersionError:
        pass

    if print_whats_new:
        sys.stderr.write("WHAT'S NEW IN KVM48 v%s:\n\n" % __version__)
        sys.stderr.write(WHATS_NEW)
        sys.stderr.write(
            "\nPress any key to continue (the program will auto-resume in 15 seconds)...\n\n"
        )
        read_keypress_with_timeout(15)

    if not force and datetime.date.today() == last_check_date:
        return
    sys.stderr.write("Checking for updates for KVM48...\n")
    try:
github SNH48Live / KVM48 / src / kvm48 / caterpillar.py View on Github external
)
            .decode("utf-8")
            .strip()
        )
    except FileNotFoundError:
        if warn:
            sys.stderr.write(
                "\n[ERROR] caterpillar(1) not found; see https://github.com/zmwangx/caterpillar\n"
            )
        return False
    except subprocess.CalledProcessError:
        if warn:
            sys.stderr.write("\n[ERROR] caterpillar --version failed\n")
        return False
    try:
        version = NormalizedVersion(pep440ify(raw_version))
    except UnsupportedVersionError:
        if warn:
            sys.stderr.write(
                "\n[WARNING] failed to recognize caterpillar version %s; "
                "upgrade to at least v%s if you run into problems\n"
                % (repr(raw_version), MINIMUM_CATERPILLAR_VERSION)
            )
        # Fingers crossed
        return True
    if version < NormalizedVersion(MINIMUM_CATERPILLAR_VERSION):
        if warn:
            sys.stderr.write(
                "\n[ERROR] caterpillar version %s is too low; "
                "please upgrade to at least v%s\n"
                % (raw_version, MINIMUM_CATERPILLAR_VERSION)
            )
github jlesquembre / autopilot / src / autopilot / utils.py View on Github external
def get_next_version(version, dev=False, release_type='patch'):

    norm_version = NormalizedVersion(version)
    version = norm_version._release_clause # returns a tuple without the suffix.
                                           # e.g. 1.0.0 and 1.0.0.dev0 both returns (1, 0, 0)

    if release_type == 'patch':
        if not norm_version.is_prerelease:  # if pre-release and patch, just remove the suffix
            version = version[:2] + (version[-1] + 1,)
    elif release_type == 'minor':
        version = (version[0], version[1] + 1, 0)
    elif release_type == 'major':
        version = (version[0] + 1, 0, 0)

    version = '.'.join(map(str, version))

    if dev:
        version = '{}.dev0'.format(version)
    return version
github colcon / colcon-core / colcon_core / package_identification / python.py View on Github external
def _next_incompatible_version(version):
    """
    Find the next non-compatible version.

    This is for use with the ~= compatible syntax. It will provide
    the first version that this version must be less than in order
    to be compatible.

    :param str version: PEP 440 compliant version number
    :return: The first version after this version that is not compatible
    :rtype: str
    """
    normalized = NormalizedVersion(version)
    parse_tuple = normalized.parse(version)
    version_tuple = parse_tuple[1]

    *unchanged, increment, dropped = version_tuple
    incremented = increment + 1

    version = unchanged
    version.append(incremented)
    # versions have a minimum length of 2
    if len(version) == 1:
        version.append(0)
    return '.'.join(map(str, version))
github SNH48Live / KVM48 / src / kvm48 / caterpillar.py View on Github external
except subprocess.CalledProcessError:
        if warn:
            sys.stderr.write("\n[ERROR] caterpillar --version failed\n")
        return False
    try:
        version = NormalizedVersion(pep440ify(raw_version))
    except UnsupportedVersionError:
        if warn:
            sys.stderr.write(
                "\n[WARNING] failed to recognize caterpillar version %s; "
                "upgrade to at least v%s if you run into problems\n"
                % (repr(raw_version), MINIMUM_CATERPILLAR_VERSION)
            )
        # Fingers crossed
        return True
    if version < NormalizedVersion(MINIMUM_CATERPILLAR_VERSION):
        if warn:
            sys.stderr.write(
                "\n[ERROR] caterpillar version %s is too low; "
                "please upgrade to at least v%s\n"
                % (raw_version, MINIMUM_CATERPILLAR_VERSION)
            )
        return False
    return True