From 0bd051d51473d62519bc6e03cafdf323c5345e7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Fri, 27 May 2022 12:49:09 +0200 Subject: [PATCH] Don't include all requirements with True-evaluating markers in extras subpackages The idea is that the extra subpackage only has requirements specific to that extra. The logic however only excluded requirements without markers, but requirements with *a* marker that was correct leaked to all extras subpackages. E.g. with the following requirements: Requires-Dist: base-dependency Requires-Dist: base-dependency-with-matching-marker ; python_version < "3.15" Requires-Dist: base-dependency-with-unmatching-marker ; python_version < "3.8" Provides-Extra: an-extra Requires-Dist: extra-only-dependency-with-matching-marker ; extra == 'an-extra' and python_version < "3.15" Requires-Dist: extra-only-dependency-with-unmatching-marker ; extra == 'an-extra' and python_version < "3.8" On Python 3.10, the base package generated the following requirements: python3.10dist(base-dependency) python3.10dist(base-dependency-with-matching-marker) And for the [an-extra] extra: python3.10dist(base-dependency-with-matching-marker) <--- REDUNDANT, WRONG python3.10dist(extra-only-dependency-with-matching-marker) Now we no longer just check if the marker evaluates to True, but we also check that the same marker evaluates to False when the extra is not given. A real package with this issue is build[virtualenv] 0.8.0, which we use for tests. The package has: Requires-Dist: tomli (>=1.0.0) ; python_version < "3.11" And on Python 3.10, it generated the following dependency for python3-build+virtualenv-0.8.0-2.fc37.noarch.rpm: python3.10dist(tomli) >= 1 Now it no longer does. This is asserted in tests. Fixes https://bugzilla.redhat.com/show_bug.cgi?id=2090186 Upstream PR: https://github.com/rpm-software-management/python-rpm-packaging/pull/16 --- python-rpm-generators.spec | 6 +++++- pythondistdeps.py | 9 ++++++++- tests/data/scripts_pythondistdeps/test-data.yaml | 9 +++++++++ tests/data/scripts_pythondistdeps/test-requires.yaml | 3 +++ 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/python-rpm-generators.spec b/python-rpm-generators.spec index fbaff88..933683f 100644 --- a/python-rpm-generators.spec +++ b/python-rpm-generators.spec @@ -1,7 +1,7 @@ Name: python-rpm-generators Summary: Dependency generators for Python RPMs Version: 12 -Release: 14%{?dist} +Release: 15%{?dist} # Originally all those files were part of RPM, so license is kept here License: GPLv2+ @@ -47,6 +47,10 @@ install -Dpm0755 -t %{buildroot}%{_rpmconfigdir} *.py %{_rpmconfigdir}/pythonbundles.py %changelog +* Fri May 27 2022 Miro HronĨok - 12-15 +- Don't include all requirements with True-evaluating markers in extras subpackages +- Fixes: rhbz#2090186 + * Thu Feb 10 2022 Sandro Mani - 12-14 - Add namespace option to pythodistdeps.py to allow mingw-python generatros diff --git a/pythondistdeps.py b/pythondistdeps.py index 92be3a5..b825c35 100755 --- a/pythondistdeps.py +++ b/pythondistdeps.py @@ -112,10 +112,17 @@ class Distribution(PathDistribution): def requirements_for_extra(self, extra): extra_deps = [] + # we are only interested in dependencies with extra == 'our_extra' marker for req in self.requirements: + # no marker at all, nothing to evaluate if not req.marker: continue - if req.marker.evaluate(get_marker_env(self, extra)): + # does the marker include extra == 'our_extra'? + # we can only evaluate the marker as a whole, + # so we evaluate it twice (using 2 different marker_envs) + # and see if it only evaluates to True with our extra + if (req.marker.evaluate(get_marker_env(self, extra)) and + not req.marker.evaluate(get_marker_env(self, None))): extra_deps.append(req) return extra_deps diff --git a/tests/data/scripts_pythondistdeps/test-data.yaml b/tests/data/scripts_pythondistdeps/test-data.yaml index 54e5b66..6a8152d 100644 --- a/tests/data/scripts_pythondistdeps/test-data.yaml +++ b/tests/data/scripts_pythondistdeps/test-data.yaml @@ -1353,4 +1353,13 @@ python3.9dist(zope-component[security]) python3.9dist(zope-component[zcml]) python3.9dist(zope-testing) +--requires --normalized-names-format pep503 --require-extras-subpackages --package-name python3-build+virtualenv: + --provides --majorver-provides --normalized-names-format pep503 --package-name python3-build+virtualenv: + usr/lib/python3.10/site-packages/build-0.8.0.dist-info: + provides: |- + python3.10dist(build[virtualenv]) = 0.8 + python3dist(build[virtualenv]) = 0.8 + requires: |- + python(abi) = 3.10 + python3.10dist(virtualenv) >= 20.0.35 diff --git a/tests/data/scripts_pythondistdeps/test-requires.yaml b/tests/data/scripts_pythondistdeps/test-requires.yaml index d876674..ade5043 100644 --- a/tests/data/scripts_pythondistdeps/test-requires.yaml +++ b/tests/data/scripts_pythondistdeps/test-requires.yaml @@ -100,3 +100,6 @@ dnspython: '2.1.0': ['3.9'] wheel: '2.1.0': ['3.9'] +build: + wheel: + '0.8.0': ['3.10']