From 06b21e19762d36c697ba109486c1b2d5dcafdc50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Tue, 2 Feb 2021 23:16:59 +0100 Subject: [PATCH] Generate python3dist(toml) BuildRequires directly from the macro The macro checks if pyproject.toml exists and echoes the dependency early. For projects with pyproject.toml, this saves one installation round. Previously, the installation steps by %generate_buildrequires were: 1. (python3-devel +) pip + packaging 2. toml 3. parsed dependencies from pyproject.toml 4. ... Now they are: 1. (python3-devel +) pip + packaging + toml 2. parsed dependencies from pyproject.toml 3. ... For projects without pyproject.toml, the number of rounds remains the same: 1. (python3-devel +) pip + packaging 2. setuptools + wheel 3. ... This is also more consistent: The Python script now only outputs dependencies of the probed project, it no longer partially outputs dependencies for itself. --- macros.pyproject | 3 +++ pyproject-rpm-macros.spec | 1 + pyproject_buildrequires.py | 11 +++++++---- pyproject_buildrequires_testcases.yaml | 7 ++----- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/macros.pyproject b/macros.pyproject index 66c4912..63f127d 100644 --- a/macros.pyproject +++ b/macros.pyproject @@ -85,6 +85,9 @@ fi echo 'python%{python3_pkgversion}-devel' echo 'python%{python3_pkgversion}dist(pip) >= 19' echo 'python%{python3_pkgversion}dist(packaging)' +if [ -f pyproject.toml ]; then + echo 'python%{python3_pkgversion}dist(toml)' +fi # Check if we can generate dependencies on Python extras if [ "%{py_dist_name []}" == "[]" ]; then extras_flag=%{?!_python_no_extras_requires:--generate-extras} diff --git a/pyproject-rpm-macros.spec b/pyproject-rpm-macros.spec index df86f37..a32c3c8 100644 --- a/pyproject-rpm-macros.spec +++ b/pyproject-rpm-macros.spec @@ -106,6 +106,7 @@ export HOSTNAME="rpmbuild" # to speedup tox in network-less mock, see rhbz#1856 %changelog * Tue Feb 02 2021 Miro HronĨok - 0-37 - Remove support for Python 3.7 from %%pyproject_buildrequires +- Generate python3dist(toml) BR with pyproject.toml earlier to avoid extra install round * Wed Jan 27 2021 Fedora Release Engineering - 0-36 - Rebuilt for https://fedoraproject.org/wiki/Fedora_34_Mass_Rebuild diff --git a/pyproject_buildrequires.py b/pyproject_buildrequires.py index c1e35d4..7038ac4 100644 --- a/pyproject_buildrequires.py +++ b/pyproject_buildrequires.py @@ -152,10 +152,13 @@ def get_backend(requirements): except FileNotFoundError: pyproject_data = {} else: - # lazy import toml here, not needed without pyproject.toml - requirements.add('toml', source='parsing pyproject.toml') - requirements.check(source='parsing pyproject.toml') - import toml + try: + # lazy import toml here, not needed without pyproject.toml + import toml + except ImportError as e: + print_err('Import error:', e) + # already echoed by the %pyproject_buildrequires macro + sys.exit(0) with f: pyproject_data = toml.load(f) diff --git a/pyproject_buildrequires_testcases.yaml b/pyproject_buildrequires_testcases.yaml index fb155ce..d3121e4 100644 --- a/pyproject_buildrequires_testcases.yaml +++ b/pyproject_buildrequires_testcases.yaml @@ -12,7 +12,8 @@ Nothing installed yet: pyproject.toml: | # empty expected: | - python3dist(toml) + python3dist(setuptools) >= 40.8 + python3dist(wheel) result: 0 Insufficient version of setuptools: @@ -23,7 +24,6 @@ Insufficient version of setuptools: pyproject.toml: | # empty expected: | - python3dist(toml) python3dist(setuptools) >= 40.8 python3dist(wheel) result: 0 @@ -48,7 +48,6 @@ Default build system, empty setup.py: # empty setup.py: | expected: | - python3dist(toml) python3dist(setuptools) >= 40.8 python3dist(wheel) python3dist(wheel) @@ -93,7 +92,6 @@ Build system dependencies in pyproject.toml with extras: "py3 ; python_version > '3.0'", ] expected: | - python3dist(toml) python3dist(foo) python3dist(bar) > 5 python3dist(bar[baz]) > 5 @@ -124,7 +122,6 @@ Build system dependencies in pyproject.toml without extras: "multi[extras1,extras2] == 6.0", ] expected: | - python3dist(toml) python3dist(bar) > 5 python3dist(multi) = 6 python3dist(setuptools) >= 40.8