From 7d819e0000e77820f5705406660b6e86b56a50e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Fri, 17 Jan 2020 17:27:09 +0100 Subject: [PATCH] Also provide pythonXdist() with PEP 503 normalized names (#1791530) That is, we add new provides that replace dots with a dash. Package that used to provide python3dist(zope.component) and python3.8dist(zope.component) now also provides python3dist(zope-component) and python3.8dist(zope-component). Package that used to provide python3dist(a.-.-.-.a) now provides python3dist(a-a) as well. This is consistent with pip behavior, `pip install zope-component` installs zope.component. Historically, we have always used dist.key (safe_name) from setuptools, but that is a non-standardized convention -- whether or not it replaces dots with dashes is not even documented. We say we use "canonical name" or "normalized name" everywhere, yet we didn't. We really need to follow the standard (PEP 503): https://www.python.org/dev/peps/pep-0503/#normalized-names The proper function here would be packaging.utils.canonicalize_name https://packaging.pypa.io/en/latest/utils/#packaging.utils.canonicalize_name -- we reimplement it here to avoid an external dependency. This is the first required step needed if we want to change our requirements later. If we decide we don't, for whatever reason, this doesn't break anything. --- python-rpm-generators.spec | 5 ++++- pythondistdeps.py | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/python-rpm-generators.spec b/python-rpm-generators.spec index 2af6e6d..ea6fb97 100644 --- a/python-rpm-generators.spec +++ b/python-rpm-generators.spec @@ -5,7 +5,7 @@ Name: python-rpm-generators Summary: Dependency generators for Python RPMs Version: 10 -Release: 2%{?dist} +Release: 3%{?dist} # Originally all those files were part of RPM, so license is kept here License: GPLv2+ @@ -49,6 +49,9 @@ install -Dpm0755 -t %{buildroot}%{_rpmconfigdir} pythondeps.sh pythondistdeps.py %{_rpmconfigdir}/pythondistdeps.py %changelog +* Fri Jan 17 2020 Miro Hrončok - 10-3 +- Also provide pythonXdist() with PEP 503 normalized names (#1791530) + * Fri Jan 03 2020 Miro Hrončok - 10-2 - Fix more complicated requirement expressions by adding parenthesis diff --git a/pythondistdeps.py b/pythondistdeps.py index da5f1a0..8756fdf 100755 --- a/pythondistdeps.py +++ b/pythondistdeps.py @@ -32,6 +32,11 @@ PyMajorVer_Deps = False legacy_Provides = False legacy = False +def normalize_name(name): + """https://www.python.org/dev/peps/pep-0503/#normalized-names""" + import re + return re.sub(r'[-_.]+', '-', name).lower() + for o, a in opts: if o in ('-h', '--help'): print('-h, --help\tPrint help') @@ -127,6 +132,12 @@ for f in files: import platform platform.python_version = lambda: dist.py_version + # This is the PEP 503 normalized name. + # It does also convert dots to dashes, unlike dist.key. + # In the current code, we only add additional provides with this. + # Later, we can start requiring them. + # See https://bugzilla.redhat.com/show_bug.cgi?id=1791530 + normalized_name = normalize_name(dist.project_name) if Provides_PyMajorVer_Variant or PyMajorVer_Deps or legacy_Provides or legacy: # Get the Python major version @@ -142,10 +153,16 @@ for f in files: name = 'python{}dist({})'.format(dist.py_version, dist.key) if name not in py_deps: py_deps[name] = [] + name_ = 'python{}dist({})'.format(dist.py_version, normalized_name) + if name_ not in py_deps: + py_deps[name_] = [] if Provides_PyMajorVer_Variant or PyMajorVer_Deps: pymajor_name = 'python{}dist({})'.format(pyver_major, dist.key) if pymajor_name not in py_deps: py_deps[pymajor_name] = [] + pymajor_name_ = 'python{}dist({})'.format(pyver_major, normalized_name) + if pymajor_name_ not in py_deps: + py_deps[pymajor_name_] = [] if legacy or legacy_Provides: legacy_name = 'pythonegg({})({})'.format(pyver_major, dist.key) if legacy_name not in py_deps: @@ -158,8 +175,12 @@ for f in files: if spec not in py_deps[name]: if not legacy: py_deps[name].append(spec) + if name != name_: + py_deps[name_].append(spec) if Provides_PyMajorVer_Variant: py_deps[pymajor_name].append(spec) + if pymajor_name != pymajor_name_: + py_deps[pymajor_name_].append(spec) if legacy or legacy_Provides: py_deps[legacy_name].append(spec) if Requires or (Recommends and dist.extras):