From 079b71a567cf8d81314e18938b54f521d555cec9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Tue, 7 Mar 2023 17:35:06 +0100 Subject: [PATCH] Ignore environment markers in pythonbundles.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use packaging.requirements instead of a naïve split on ==. --- python-rpm-generators.spec | 1 + pythonbundles.py | 12 ++++++++++-- .../pkg_resources_setuptools.out | 1 + tests/data/scripts_pythonbundles/setuptools.in | 1 + tests/data/scripts_pythonbundles/setuptools.out | 1 + 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/python-rpm-generators.spec b/python-rpm-generators.spec index fc8c7ee..580eb06 100644 --- a/python-rpm-generators.spec +++ b/python-rpm-generators.spec @@ -49,6 +49,7 @@ install -Dpm0755 -t %{buildroot}%{_rpmconfigdir} *.py %changelog * Tue Mar 07 2023 Miro Hrončok - 14-3 - Avoid needless pkg_resources import in pythonbundles.py +- Ignore environment markers in pythonbundles.py * Fri Jan 20 2023 Fedora Release Engineering - 14-2 - Rebuilt for https://fedoraproject.org/wiki/Fedora_38_Mass_Rebuild diff --git a/pythonbundles.py b/pythonbundles.py index 9c58f6c..8adc36f 100755 --- a/pythonbundles.py +++ b/pythonbundles.py @@ -15,6 +15,8 @@ import pathlib import sys +from packaging import requirements + import pythondistdeps def generate_bundled_provides(paths, namespace): @@ -33,8 +35,14 @@ def generate_bundled_provides(paths, namespace): continue line = line.strip() if line: - name, _, version = line.partition('==') - name = pythondistdeps.normalize_name(name) + requirement = requirements.Requirement(line) + for spec in requirement.specifier: + if spec.operator == '==': + version = spec.version + break + else: + raise ValueError('pythonbundles.py only handles exactly one == requirement') + name = pythondistdeps.normalize_name(requirement.name) bundled_name = f"bundled({namespace}({name}))" python_provide = pythondistdeps.convert(bundled_name, '==', version) provides.add(f'Provides: {python_provide}') diff --git a/tests/data/scripts_pythonbundles/pkg_resources_setuptools.out b/tests/data/scripts_pythonbundles/pkg_resources_setuptools.out index cc2d710..0d41629 100644 --- a/tests/data/scripts_pythonbundles/pkg_resources_setuptools.out +++ b/tests/data/scripts_pythonbundles/pkg_resources_setuptools.out @@ -3,3 +3,4 @@ Provides: bundled(python3dist(ordered-set)) = 3.1.1 Provides: bundled(python3dist(packaging)) = 16.8 Provides: bundled(python3dist(pyparsing)) = 2.2.1 Provides: bundled(python3dist(six)) = 1.10 +Provides: bundled(python3dist(tomli)) = 1.2.3 diff --git a/tests/data/scripts_pythonbundles/setuptools.in b/tests/data/scripts_pythonbundles/setuptools.in index d7d2beb..64ee9d3 100644 --- a/tests/data/scripts_pythonbundles/setuptools.in +++ b/tests/data/scripts_pythonbundles/setuptools.in @@ -1,3 +1,4 @@ packaging==16.8 pyparsing==2.2.1 ordered-set==3.1.1 +tomli==1.2.3;python_version<"3.11" diff --git a/tests/data/scripts_pythonbundles/setuptools.out b/tests/data/scripts_pythonbundles/setuptools.out index 0acb887..ec452db 100644 --- a/tests/data/scripts_pythonbundles/setuptools.out +++ b/tests/data/scripts_pythonbundles/setuptools.out @@ -1,3 +1,4 @@ Provides: bundled(python3dist(ordered-set)) = 3.1.1 Provides: bundled(python3dist(packaging)) = 16.8 Provides: bundled(python3dist(pyparsing)) = 2.2.1 +Provides: bundled(python3dist(tomli)) = 1.2.3