Fix bindep on Arch with packaging>=22.0

packaging 22.0 removed the LegacyVersion object which was the fallback
when an invalid version was found. Now when an invalid version is found
packaging raises and exception. This appears to be a problem for rolling
release distros like Arch and Manjaro as they don't have versions.

To fix this we catch the exception and set our object value to None.
This will cause us to error later should we actually need the version
for some reason. When we don't need it as with Arch/Manjaro we continue
along just fine.

Change-Id: Ic9ec6a3a492a7f95cf9d2865f88d79c6c5de796c
This commit is contained in:
Clark Boylan 2022-12-16 11:53:54 -08:00
parent 697af0b17a
commit b10c2f4003
2 changed files with 9 additions and 3 deletions

View File

@ -22,7 +22,7 @@ from parsley import makeGrammar
import platform
import subprocess
import sys
from packaging.version import parse as as_ver
from packaging.version import InvalidVersion, parse as as_ver
import distro
@ -327,7 +327,13 @@ class Depends(object):
# NOTE(toabctl): distro can be more than one string (i.e. "SUSE LINUX")
codename = distro.codename().lower()
release = distro.version().lower()
release_version = as_ver(release)
try:
release_version = as_ver(release)
except InvalidVersion:
# Rolling releases like Arch and Manjaro have no
# version. Ignore it and fail later if we actually need
# to check versions
release_version = None
# NOTE(toabctl): space is a delimiter for bindep, so remove the spaces
distro_id = "".join(distro_id.split()).lower()
atoms = set([distro_id])

View File

@ -2,5 +2,5 @@ distro<1.7.0 ; python_version < '3.6'
distro>=1.7.0 ; python_version >= '3.6'
pbr>=2.0.0 # Apache-2.0
Parsley
packaging<22.0 ; python_version >= '3.6'
packaging ; python_version >= '3.6'
packaging<21.0 ; python_version < '3.6'