From 5774bd8c3dce5adf70884a22308af3dd7b2a8372 Mon Sep 17 00:00:00 2001 From: Maurits van Rees Date: Fri, 14 Apr 2023 16:04:08 +0200 Subject: [PATCH] Ignore invalid versions. Needed for `setuptools` 66 and higher when checking a package that has invalid versions on PyPI. Fixes https://github.com/plone/plone.versioncheck/issues/52. For example it fails on parsing `collective.recipe.template` because it has a version `1.4dev-r93307`. See https://pypi.org/simple/collective-recipe-template/ --- CHANGES.rst | 5 ++++- src/plone/versioncheck/pypi.py | 8 +++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 0253e00..d165d2d 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,7 +4,10 @@ Changelog 1.7.1 (unreleased) ------------------ -- Nothing changed yet. +- Ignore invalid versions. + Needed for ``setuptools`` 66 and higher when checking a package that has invalid versions on PyPI. + Fixes `issue 52 `_. + [maurits] 1.7.0 (2019-03-08) diff --git a/src/plone/versioncheck/pypi.py b/src/plone/versioncheck/pypi.py index 0602a35..88b3e04 100644 --- a/src/plone/versioncheck/pypi.py +++ b/src/plone/versioncheck/pypi.py @@ -74,7 +74,13 @@ def check(name, version, session): # noqa: C901 releases = sorted(data["releases"]) for release in releases: # major check (overall) - rel_v = parse_version(release) + try: + rel_v = parse_version(release) + except Exception: + # likely pkg_resources.extern.packaging.version.InvalidVersion + # but really any exception can be ignored. + # See https://github.com/plone/plone.versioncheck/issues/52 + continue if rel_v <= version: continue rel_vtuple = mmbp_tuple(rel_v)