Don't accidentally treat "~= X.0" requirement as "~= X"

Don't canonicalize the version twice.

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1977060

Related: rhbz#1950291
This commit is contained in:
Miro Hrončok 2021-06-29 10:43:13 +00:00
parent 9c60342738
commit dd25ce59a6
3 changed files with 14 additions and 5 deletions

View File

@ -12,7 +12,7 @@ License: MIT
# In other cases, such as backports, increment the point
# release.
Version: 0
Release: 41%{?dist}
Release: 42%{?dist}
# Macro files
Source001: macros.pyproject
@ -110,6 +110,10 @@ export HOSTNAME="rpmbuild" # to speedup tox in network-less mock, see rhbz#1856
%license LICENSE
%changelog
* Tue Jun 29 2021 Miro Hrončok <mhroncok@redhat.com> - 0-42
- Don't accidentally treat "~= X.0" requirement as "~= X"
- Fixes rhzb#1977060
* Mon Jun 28 2021 Miro Hrončok <mhroncok@redhat.com> - 0-41
- Don't leak %%{_pyproject_builddir} to pytest collection

View File

@ -25,7 +25,7 @@ class EndPass(Exception):
try:
from packaging.requirements import Requirement, InvalidRequirement
from packaging.utils import canonicalize_name, canonicalize_version
from packaging.utils import canonicalize_name
except ImportError as e:
print_err('Import error:', e)
# already echoed by the %pyproject_buildrequires macro
@ -119,14 +119,13 @@ class Requirements:
requirement.specifier,
key=lambda s: (s.operator, s.version),
):
version = canonicalize_version(specifier.version)
if not VERSION_RE.fullmatch(str(specifier.version)):
raise ValueError(
f'Unknown character in version: {specifier.version}. '
+ '(This is probably a bug in pyproject-rpm-macros.)',
)
together.append(convert(python3dist(name, python3_pkgversion=self.python3_pkgversion),
specifier.operator, version))
specifier.operator, specifier.version))
if len(together) == 0:
print(python3dist(name,
python3_pkgversion=self.python3_pkgversion))

View File

@ -81,10 +81,13 @@ Build system dependencies in pyproject.toml with extras:
"foo",
"bar[bAz] > 5",
"ne!=1",
"ge>=1.2",
"ge>=1.2.0",
"le <= 1.2.3",
"lt < 1.2.3.4 ",
" gt > 1.2.3.4.5",
"compatible ~= 0.4.0",
"equal == 0.5.0",
"arbitrary_equal === 0.6.0",
"multi[Extras1,Extras2] == 6.0",
"combo >2, <5, != 3.0.0",
"invalid!!ignored",
@ -100,6 +103,9 @@ Build system dependencies in pyproject.toml with extras:
python3dist(le) <= 1.2.3
python3dist(lt) < 1.2.3.4
python3dist(gt) > 1.2.3.4.5
(python3dist(compatible) >= 0.4 with python3dist(compatible) < 0.5)
python3dist(equal) = 0.5
python3dist(arbitrary-equal) = 0.6
python3dist(multi) = 6
python3dist(multi[extras1]) = 6
python3dist(multi[extras2]) = 6