From 9e46727e3217672d3202dfb0b637bc7b6a5f4dcf Mon Sep 17 00:00:00 2001 From: Miro HronĨok Date: Jun 12 2020 09:26:18 +0000 Subject: Proof of concept: Validate bundled provides in %check We repeatadly forget to update the list of bundled provides. This is a proof of concept of validating the provides in %check with a Python script. If we like he idea, we can make the script more general, package it to python-rpm-macros and reuse it in setuptools, pip, pipenv... --- diff --git a/bundled_provides.py b/bundled_provides.py new file mode 100644 index 0000000..2a648d9 --- /dev/null +++ b/bundled_provides.py @@ -0,0 +1,49 @@ +import pathlib +import sys + +try: + SOURCES = pathlib.Path(sys.argv[1]) +except IndexError: + sys.exit( + "Requires directory with prepped sources as argument, e.g. setuptools-47.1.1" + ) +VENDOR_FILE = SOURCES / "pkg_resources/_vendor/vendored.txt" + + +def convert_version(version): + for pre in "a", "b", "rc", "dev": + if pre in version: + version, rel, relnum = version.partition(pre) + break + else: + rel = relnum = "" + + while version.endswith(".0"): + version = version[:-2] + + if rel == "dev": + return f"{version}~~{rel}{relnum}" + if rel: + return f"{version}~{rel}{relnum}" + return version + + +provides = set() + +for line in VENDOR_FILE.read_text().splitlines(): + line, *_ = line.partition("#") + line = line.strip() + if line: + name, _, version = line.partition("==") + version = convert_version(version) + provides.add(f"Provides: bundled(python3dist({name})) = {version}") + +# When used standalone, we print, when with argument, we assert +if len(sys.argv) == 2: + for provide in sorted(provides): + print(provide) +else: + expected = set(sys.argv[2].splitlines()) + expected.discard("") + if provides != expected: + sys.exit(f"{provides} != {expected}") diff --git a/python-setuptools.spec b/python-setuptools.spec index a714c7a..d2c5b99 100644 --- a/python-setuptools.spec +++ b/python-setuptools.spec @@ -45,6 +45,17 @@ BuildRequires: python3-wheel BuildRequires: python3-rpm-generators %endif # without bootstrap +# Virtual provides for the packages bundled by setuptools. +# You can find the versions in setuptools/setuptools/_vendor/vendored.txt +# Use this source to generate the list: +Source9: bundled_provides.py +%global bundled %{expand: +Provides: bundled(python3dist(appdirs)) = 1.4.3 +Provides: bundled(python3dist(packaging)) = 16.8 +Provides: bundled(python3dist(pyparsing)) = 2.2.1 +Provides: bundled(python3dist(six)) = 1.10 +} + %description Setuptools is a collection of enhancements to the Python distutils that allow you to more easily build and distribute Python packages, especially ones that @@ -53,15 +64,6 @@ have dependencies on other packages. This package also contains the runtime components of setuptools, necessary to execute the software that requires pkg_resources. -# Virtual provides for the packages bundled by setuptools. -# You can find the versions in setuptools/setuptools/_vendor/vendored.txt -%global bundled %{expand: -Provides: bundled(python3dist(packaging)) = 16.8 -Provides: bundled(python3dist(pyparsing)) = 2.2.1 -Provides: bundled(python3dist(six)) = 1.10.0 -Provides: bundled(python3dist(appdirs)) = 1.4.3 -} - %package -n python3-setuptools Summary: Easily build and distribute Python 3 packages Conflicts: python-setuptools < %{version}-%{release} @@ -142,8 +144,11 @@ install -p dist/%{python_wheelname} -t %{buildroot}%{python_wheeldir} %endif -%if %{with tests} %check +# Assert the bundled provides are up to date +%{python3} %{SOURCE9} . '%{bundled}' + +%if %{with tests} # --ignore=pavement.py: # pavement.py is only used by upstream to do releases and vendoring, we don't ship it PYTHONDONTWRITEBYTECODE=1 PYTHONPATH=$(pwd) pytest-%{python3_version} \