Skip to content

Newest version from pypi should respect pattern restrictions

Problem description

I have situation where in one project I need autoupdater to check twice for the same package from pypi, one in version 2.9.X and one in version 2.10.X. Now only the newest package from pypi is returned.

Proposal

In autoupdater/software/update.py file change definition of _get_pypi_package_newest_tag function as follows:

Old version:

def _get_pypi_package_newest_tag(package_source_configuration: autoupdater.gitlab.packages.PackageSourceConfiguration) -> str:
    pypi_url = f'{BASE_PYPI_URL}{package_source_configuration.source}/json'
    version = _match_version(
        package_source_configuration.version_pattern,
        requests.get(pypi_url).json()['info']['version']
    )
    if not version:
        raise VersionPatternError(f'Pattern: {package_source_configuration.version_pattern} do not match the newest version ({version}) of package {package_source_configuration.source}')
    return version

New version:

def _get_pypi_package_newest_tag(package_source_configuration: autoupdater.gitlab.packages.PackageSourceConfiguration) -> str:
    pypi_url = f'{BASE_PYPI_URL}{package_source_configuration.source}/json'
    pypi_json = requests.get(pypi_url).json()
    version = _match_version(
        package_source_configuration.version_pattern,
        pypi_json['info']['version']
    )
    if not version:
        versions = list(pypi_json['releases'].keys())
        newest_matching_version = _get_the_newest_tag(versions, package_source_configuration.version_pattern)
        if not newest_matching_version:
            raise VersionPatternError(f'Pattern: {package_source_configuration.version_pattern} do not match the newest version ({version}) of package {package_source_configuration.source}')
        version = newest_matching_version
    return version