From 876e6eadd90d2371a9dc075d41d07f77a3a8c199 Mon Sep 17 00:00:00 2001 From: Yangeng Liu Date: Mon, 24 Nov 2025 13:51:14 +0800 Subject: [PATCH] Update the version to 14 Signed-off-by: Yangeng Liu --- python-rpm-generators.spec | 24 ++++++++++++++++++++---- python.attr | 14 +++++++++----- pythonbundles.py | 19 +++++++++++-------- pythondist.attr | 4 ++-- pythondistdeps.py | 31 ++++++++++++++++++++++++++++--- pythonname.attr | 14 ++++---------- 6 files changed, 74 insertions(+), 32 deletions(-) diff --git a/python-rpm-generators.spec b/python-rpm-generators.spec index 68ab841..ef32f00 100644 --- a/python-rpm-generators.spec +++ b/python-rpm-generators.spec @@ -1,20 +1,29 @@ %define anolis_release 1 Name: python-rpm-generators Summary: Dependency generators for Python RPMs -Version: 12 +Version: 14 Release: %{anolis_release}%{?dist} -# Originally all those files were part of RPM, so license is kept here -License: GPLv2+ Url: https://src.fedoraproject.org/python-rpm-generators -# Commit is the last change in following files + +# Originally all those files were part of RPM, so license is kept here +# The COPYING file is grabbed from the last commit that changed the files Source0: https://raw.githubusercontent.com/rpm-software-management/rpm/102eab50b3d0d6546dfe082eac0ade21e6b3dbf1/COPYING Source1: python.attr Source2: pythondist.attr +# This was crafted in-place as a fork of python.attr, hence also GPL-2.0-or-later Source3: pythonname.attr +# This one is also originally from RPM, but it has its own license declaration: LGPL-2.1-or-later Source4: pythondistdeps.py +# This was crafted in-place with the following license declaration: +# LicenseRef-Fedora-Public-Domain OR CC0-1.0 OR LGPL-2.1-or-later OR GPL-2.0-or-later +# Note that CC0-1.0 is not allowed for code in Fedora, so we skip it in the package License tag Source5: pythonbundles.py +# See individual licenses above Source declarations +# Originally, this was simplified to GPL-2.0-or-later, but "effective license" analysis is no longer allowed +License: GPL-2.0-or-later AND LGPL-2.1-or-later AND (LicenseRef-Fedora-Public-Domain OR LGPL-2.1-or-later OR GPL-2.0-or-later) + BuildArch: noarch %description @@ -48,5 +57,12 @@ install -Dpm0755 -t %{buildroot}%{_rpmconfigdir} *.py %{_rpmconfigdir}/pythonbundles.py %changelog +* Mon Nov 24 2025 Yangeng Liu - 14-1 +- Update the version to 14. +- Avoid needless pkg_resources import in pythonbundles.py +- Ignore environment markers in pythonbundles.py +- Declare the license via a complex SPDX expression rather than "effective license" +- Avoid DeprecationWarning: Implicit None on return values is deprecated and will raise KeyErrors + * Mon Mar 07 2022 Chunmei Xu - 12-1 - init package diff --git a/python.attr b/python.attr index 1793d3c..cf5ae39 100644 --- a/python.attr +++ b/python.attr @@ -5,8 +5,10 @@ -- python(abi) = MAJOR.MINOR -- (Don't match against -config tools e.g. /usr/bin/python2.6-config) local path = rpm.expand('%1') - if path:match('/usr/bin/python%d+%.%d+$') then - local provides = path:gsub('.*/usr/bin/python(%d+%.%d+)', 'python(abi) = %1') + -- Use /usr prefix by default, and /app for flatpak builds + local prefix = rpm.expand('%{?!flatpak:/usr}%{?flatpak:/app}') + if path:match(prefix .. '/bin/python%d+%.%d+$') then + local provides = path:gsub('.*' .. prefix .. '/bin/python(%d+%.%d+)', 'python(abi) = %1') print(provides) end } @@ -18,10 +20,12 @@ -- generating a line of the form: -- python(abi) = MAJOR.MINOR local path = rpm.expand('%1') - if path:match('/usr/lib%d*/python%d+%.%d+/.*') then - local requires = path:gsub('.*/usr/lib%d*/python(%d+%.%d+)/.*', 'python(abi) = %1') + -- Use /usr prefix by default, and /app for flatpak builds + local prefix = rpm.expand('%{?!flatpak:/usr}%{?flatpak:/app}') + if path:match(prefix .. '/lib%d*/python%d+%.%d+/.*') then + local requires = path:gsub('.*' .. prefix .. '/lib%d*/python(%d+%.%d+)/.*', 'python(abi) = %1') print(requires) end } -%__python_path ^((%{_prefix}/lib(64)?/python[[:digit:]]+\\.[[:digit:]]+/.*\\.(py[oc]?|so))|(%{_bindir}/python[[:digit:]]+\\.[[:digit:]]+))$ +%__python_path ^((%{?!flatpak:/usr}%{?flatpak:/app}/lib(64)?/python[[:digit:]]+\\.[[:digit:]]+/.*\\.(py[oc]?|so))|(%{_bindir}/python[[:digit:]]+\\.[[:digit:]]+))$ diff --git a/pythonbundles.py b/pythonbundles.py index 6242e20..b0e5ecf 100755 --- a/pythonbundles.py +++ b/pythonbundles.py @@ -4,7 +4,7 @@ # This program is free software. # # It is placed in the public domain or under the CC0-1.0-Universal license, -# whichever is more permissive. +# whichever you choose. # # Alternatively, it may be redistributed and/or modified under the terms of # the LGPL version 2.1 (or later) or GPL version 2 (or later). @@ -15,12 +15,9 @@ import pathlib import sys -# inject parse_version import to pythondistdeps -# not the nicest API, but :/ -from pkg_resources import parse_version -import pythondistdeps -pythondistdeps.parse_version = parse_version +from packaging import requirements +import pythondistdeps def generate_bundled_provides(paths, namespace): provides = set() @@ -38,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/pythondist.attr b/pythondist.attr index 747cc32..ede3a51 100644 --- a/pythondist.attr +++ b/pythondist.attr @@ -1,3 +1,3 @@ -%__pythondist_provides %{_rpmconfigdir}/pythondistdeps.py --provides --normalized-names-format pep503 --package-name %{name} --normalized-names-provide-both --majorver-provides-versions %{__default_python3_version} +%__pythondist_provides %{_rpmconfigdir}/pythondistdeps.py --provides --normalized-names-format pep503 --package-name %{name} --majorver-provides-versions %{__default_python3_version} %{?!_python_dist_allow_version_zero:--fail-if-zero} %__pythondist_requires %{_rpmconfigdir}/pythondistdeps.py --requires --normalized-names-format pep503 --package-name %{name} %{?!_python_no_extras_requires:--require-extras-subpackages} --console-scripts-nodep-setuptools-since 3.10 -%__pythondist_path ^/usr/lib(64)?/python[3-9]\\.[[:digit:]]+/site-packages/[^/]+\\.(dist-info|egg-info|egg-link)$ +%__pythondist_path ^%{?!flatpak:/usr}%{?flatpak:/app}/lib(64)?/python[3-9]\\.[[:digit:]]+/site-packages/[^/]+\\.(dist-info|egg-info|egg-link)$ diff --git a/pythondistdeps.py b/pythondistdeps.py index 92be3a5..b43ed39 100755 --- a/pythondistdeps.py +++ b/pythondistdeps.py @@ -94,8 +94,8 @@ class Distribution(PathDistribution): # that it works also on previous Python/importlib_metadata versions. @property def name(self): - """Return the 'Name' metadata for the distribution package.""" - return self.metadata['Name'] + """Return the 'Name' metadata for the distribution package or None.""" + return self.metadata.get('Name') def _parse_py_version(self, path): # Try to parse the Python version from the path the metadata @@ -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 @@ -148,6 +155,9 @@ class RpmVersion(): self.post = None return self + def is_zero(self): + return self.__str__() == '0' + def __str__(self): if self.is_legacy(): return self.version @@ -327,9 +337,13 @@ def main(): help="If there is a dependency on a package with extras functionality, require the extras subpackage") parser.add_argument('--package-name', action='store', help="Name of the RPM package that's being inspected. Required for extras requires/provides to work.") parser.add_argument('--namespace', action='store', help="Namespace for the printed Requires, Provides, Recommends and Conflicts") + parser.add_argument('--fail-if-zero', action='store_true', help='Fail the script if the automatically generated Provides version was 0, which usually indicates a packaging error.') parser.add_argument('files', nargs=argparse.REMAINDER, help="Files from the RPM package that are to be inspected, can also be supplied on stdin") args = parser.parse_args() + if args.fail_if_zero and not args.provides: + raise parser.error('--fail-if-zero only works with --provides') + py_abi = args.requires py_deps = {} @@ -463,6 +477,17 @@ def main(): if dist.version: version = dist.version spec = ('==', version) + if args.fail_if_zero: + if RpmVersion(version).is_zero(): + print('*** PYTHON_PROVIDED_VERSION_NORMALIZES_TO_ZERO___SEE_STDERR ***') + print(f'\nError: The version in the Python package metadata {version} normalizes to zero.\n' + 'It\'s likely a packaging error caused by missing version information\n' + '(e.g. when using a version control system snapshot as a source).\n' + 'Try providing the version information manually when building the Python package,\n' + 'for example by setting the SETUPTOOLS_SCM_PRETEND_VERSION environment variable if the package uses setuptools_scm.\n' + 'If you are confident that the version of the Python package is intentionally zero,\n' + 'you may %define the _python_dist_allow_version_zero macro in the spec file to disable this check.\n', file=stderr) + exit(65) # os.EX_DATAERR if normalized_names_provide_legacy: if spec not in py_deps[name]: diff --git a/pythonname.attr b/pythonname.attr index 8366965..205570a 100644 --- a/pythonname.attr +++ b/pythonname.attr @@ -1,9 +1,6 @@ %__pythonname_provides() %{lua: - local python = require 'anolis.srpm.python' - -- this macro is called for each file in a package, the path being in %1 - -- but we don't need to know the path, so we would get for each file: Macro %1 defined but not used within scope - -- in here, we expand %name conditionally on %1 to suppress the warning - local name = rpm.expand('%{?1:%{name}}') + local python = require 'fedora.srpm.python' + local name = rpm.expand('%{name}') local evr = rpm.expand('%{?epoch:%{epoch}:}%{version}-%{release}') local provides = python.python_altprovides_once(name, evr) -- provides is either an array/table or nil @@ -22,11 +19,8 @@ -- This provides a clean upgrade path between major versions of CentOS/RHEL. -- In Fedora this is not needed as we don't ship ecosystem packages -- for alternative Python interpreters. - local python = require 'anolis.srpm.python' - -- this macro is called for each file in a package, the path being in %1 - -- but we don't need to know the path, so we would get for each file: Macro %1 defined but not used within scope - -- in here, we expand %name conditionally on %1 to suppress the warning - local name = rpm.expand('%{?1:%{name}}') + local python = require 'fedora.srpm.python' + local name = rpm.expand('%{name}') local evr = rpm.expand('%{?epoch:%{epoch}:}%{version}-%{release}') local obsoletes = python.python_altobsoletes_once(name, evr) -- obsoletes is either an array/table or nil -- Gitee