From 197a88bf932fd7f552724a0bb1eecc31c906eb7d Mon Sep 17 00:00:00 2001 From: Karolina Surma Date: Thu, 22 Dec 2022 16:48:53 +0100 Subject: [PATCH] https://fedoraproject.org/wiki/Changes/Prevent-Providing-python3dist(pkg)=0 --- python-rpm-generators.spec | 7 +++- pythondist.attr | 2 +- pythondistdeps.py | 18 +++++++++ .../scripts_pythondistdeps/test-data.yaml | 37 ++++++++++++++++++- .../scripts_pythondistdeps/test-requires.yaml | 4 ++ 5 files changed, 64 insertions(+), 4 deletions(-) diff --git a/python-rpm-generators.spec b/python-rpm-generators.spec index e5dee70..1f42b8e 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: 13 -Release: 2%{?dist} +Version: 14 +Release: 1%{?dist} # Originally all those files were part of RPM, so license is kept here License: GPLv2+ @@ -47,6 +47,9 @@ install -Dpm0755 -t %{buildroot}%{_rpmconfigdir} *.py %{_rpmconfigdir}/pythonbundles.py %changelog +* Thu Dec 22 2022 Karolina Surma - 14-1 +- https://fedoraproject.org/wiki/Changes/Prevent-Providing-python3dist(pkg)=0 + * Fri Jul 22 2022 Fedora Release Engineering - 13-2 - Rebuilt for https://fedoraproject.org/wiki/Fedora_37_Mass_Rebuild diff --git a/pythondist.attr b/pythondist.attr index 7170bdb..42ae7ad 100644 --- a/pythondist.attr +++ b/pythondist.attr @@ -1,3 +1,3 @@ -%__pythondist_provides %{_rpmconfigdir}/pythondistdeps.py --provides --normalized-names-format pep503 --package-name %{name} --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)$ diff --git a/pythondistdeps.py b/pythondistdeps.py index b825c35..ec80125 100755 --- a/pythondistdeps.py +++ b/pythondistdeps.py @@ -155,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 @@ -334,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 = {} @@ -470,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/tests/data/scripts_pythondistdeps/test-data.yaml b/tests/data/scripts_pythondistdeps/test-data.yaml index 6a8152d..f1116a5 100644 --- a/tests/data/scripts_pythondistdeps/test-data.yaml +++ b/tests/data/scripts_pythondistdeps/test-data.yaml @@ -1362,4 +1362,39 @@ requires: |- python(abi) = 3.10 python3.10dist(virtualenv) >= 20.0.35 - +--requires --fail-if-zero: + --provides --majorver-provides --fail-if-zero: + usr/lib/python3.11/site-packages/importlib_metadata-0.0-py3.11.egg-info: + stderr: + provides: |- + Error: The version in the Python package metadata 0.0 normalizes to zero. + It's likely a packaging error caused by missing version information + (e.g. when using a version control system snapshot as a source). + Try providing the version information manually when building the Python package, + for example by setting the SETUPTOOLS_SCM_PRETEND_VERSION environment variable if the package uses setuptools_scm. + If you are confident that the version of the Python package is intentionally zero, + you may %define the _python_dist_allow_version_zero macro in the spec file to disable this check. + requires: '*error: --fail-if-zero only works with --provides*' + stdout: + provides: '*** PYTHON_PROVIDED_VERSION_NORMALIZES_TO_ZERO___SEE_STDERR ***' + requires: '' +--requires: + --provides --majorver-provides: + usr/lib/python3.11/site-packages/importlib_metadata-0.0-py3.11.egg-info: + provides: |- + python3.11dist(importlib-metadata) = 0 + python3dist(importlib-metadata) = 0 + requires: |- + python(abi) = 3.11 + python3.11dist(setuptools) + python3.11dist(wheel) +--requires: + --provides --majorver-provides --fail-if-zero: + usr/lib/python3.11/site-packages/importlib_metadata-0.1-py3.11.egg-info: + provides: |- + python3.11dist(importlib-metadata) = 0.1 + python3dist(importlib-metadata) = 0.1 + requires: |- + python(abi) = 3.11 + python3.11dist(setuptools) + python3.11dist(wheel) diff --git a/tests/data/scripts_pythondistdeps/test-requires.yaml b/tests/data/scripts_pythondistdeps/test-requires.yaml index ade5043..35314a5 100644 --- a/tests/data/scripts_pythondistdeps/test-requires.yaml +++ b/tests/data/scripts_pythondistdeps/test-requires.yaml @@ -103,3 +103,7 @@ dnspython: build: wheel: '0.8.0': ['3.10'] +importlib_metadata: + sdist: + '0.0': ['3.11'] + '0.1': ['3.11']