Bug 2090186

Summary: Python dependencies with matching markers leak from the base package to the extras subpackage [fedora-all]
Product: [Fedora] Fedora Reporter: Miro Hrončok <mhroncok>
Component: python-rpm-generatorsAssignee: Miro Hrončok <mhroncok>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: low Docs Contact:
Priority: unspecified    
Version: 35CC: cstratak, lbalhar, m.cyprian, mhroncok, ngompa13, pviktori, shcherbina.iryna, torsava
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: python-rpm-generators-12-15.fc37 python-rpm-generators-12-15.fc36 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2022-06-02 10:47:48 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Miro Hrončok 2022-05-25 10:34:51 UTC
Description of problem:
When a Python dependency has a *matching* marker, e.g. a metadata line like this:

    Requires-Dist: base-dependency-with-matching-marker ; python_version < "3.15"

It leaks to the requirements of extra subpackages. This is not a severe problem, because the extra subpackages require the base package anyway, but it's a confusing behavior that was not planned in https://fedoraproject.org/wiki/Changes/PythonExtras



Version-Release number of selected component (both and likely anything in between):
python3-rpm-generators-12-8.fc35.noarch
python3-rpm-generators-12-14.fc37.noarch

How reproducible: Always


Steps to Reproduce:
1. rpmbuild -ba reproducer-extras-base-leaking.spec 
2. rpm -qRp ../RPMS/noarch/reproducer-extras-base-leaking-0-0.noarch.rpm | grep python
3. rpm -qRp ../RPMS/noarch/reproducer-extras-base-leaking+an-extra-0-0.noarch.rpm | grep python

========================
Name:           reproducer-extras-base-leaking
Version:        0
Release:        0
Summary:        ...
License:        MIT
BuildArch:      noarch
BuildRequires:  python3-devel

%description
...

%python_extras_subpkg -n reproducer-extras-base-leaking -i %{python3_sitelib}/reproducer-0.dist-info an-extra

%install
mkdir -p %{buildroot}%{python3_sitelib}/reproducer-0.dist-info/
cat << EOF > %{buildroot}%{python3_sitelib}/reproducer-0.dist-info/METADATA
Metadata-Version: 2.1
Name: reproducer
Version: 0
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"
EOF


%files
%{python3_sitelib}/reproducer-0.dist-info/
========================



Actual results:

$ rpm -qRp ../RPMS/noarch/reproducer-extras-base-leaking-0-0.noarch.rpm | grep python
python(abi) = 3.10
python3.10dist(base-dependency)
python3.10dist(base-dependency-with-matching-marker)

$ rpm -qRp ../RPMS/noarch/reproducer-extras-base-leaking+an-extra-0-0.noarch.rpm | grep python
python(abi) = 3.10
python3.10dist(base-dependency-with-matching-marker)
python3.10dist(extra-only-dependency-with-matching-marker)



Expected results:

$ rpm -qRp ../RPMS/noarch/reproducer-extras-base-leaking-0-0.noarch.rpm | grep python
python(abi) = 3.10
python3.10dist(base-dependency)
python3.10dist(base-dependency-with-matching-marker)

$ rpm -qRp ../RPMS/noarch/reproducer-extras-base-leaking+an-extra-0-0.noarch.rpm | grep python
python(abi) = 3.10
python3.10dist(extra-only-dependency-with-matching-marker)


Additional info:
I believe this is caused by https://github.com/rpm-software-management/python-rpm-packaging/blob/a18ca48959/scripts/pythondistdeps.py#L116-L119

            if not req.marker:
                continue
            if req.marker.evaluate(get_marker_env(self, extra)):
                extra_deps.append(req)

1) All requirements without a marker are skipped by continue
2) Requirements with markers are evaluated in {'python_full_version': '3.10', 'python_version': '3.10', 'extra': 'an-extra'}
3) python_version < "3.15" evaluates to true in that environment

Comment 1 Miro Hrončok 2022-05-25 11:28:58 UTC
I believe this might be fixed by something like:

            if not req.marker:
                continue
            if not req.marker.evaluate(get_marker_env(self, None)) and req.marker.evaluate(get_marker_env(self, extra)):
                extra_deps.append(req)

Comment 2 Miro Hrončok 2022-05-27 10:58:56 UTC
"upstream" PR: https://github.com/rpm-software-management/python-rpm-packaging/pull/16

Comment 4 Fedora Update System 2022-06-02 10:45:39 UTC
FEDORA-2022-af41964158 has been submitted as an update to Fedora 37. https://bodhi.fedoraproject.org/updates/FEDORA-2022-af41964158

Comment 5 Fedora Update System 2022-06-02 10:46:59 UTC
FEDORA-2022-4a6373847b has been submitted as an update to Fedora 36. https://bodhi.fedoraproject.org/updates/FEDORA-2022-4a6373847b

Comment 6 Fedora Update System 2022-06-02 10:47:48 UTC
FEDORA-2022-af41964158 has been pushed to the Fedora 37 stable repository.
If problem still persists, please make note of it in this bug report.

Comment 7 Fedora Update System 2022-06-03 04:17:28 UTC
FEDORA-2022-4a6373847b has been pushed to the Fedora 36 testing repository.
Soon you'll be able to install the update with the following command:
`sudo dnf upgrade --enablerepo=updates-testing --advisory=FEDORA-2022-4a6373847b`
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2022-4a6373847b

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 8 Fedora Update System 2022-06-04 01:16:12 UTC
FEDORA-2022-4a6373847b has been pushed to the Fedora 36 stable repository.
If problem still persists, please make note of it in this bug report.