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.
This commit is contained in:
Miro Hrončok 2021-02-02 23:16:59 +01:00
parent 390b9713aa
commit 06b21e1976
4 changed files with 13 additions and 9 deletions

View File

@ -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}

View File

@ -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 <mhroncok@redhat.com> - 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 <releng@fedoraproject.org> - 0-36
- Rebuilt for https://fedoraproject.org/wiki/Fedora_34_Mass_Rebuild

View File

@ -152,10 +152,13 @@ def get_backend(requirements):
except FileNotFoundError:
pyproject_data = {}
else:
try:
# lazy import toml here, not needed without pyproject.toml
requirements.add('toml', source='parsing pyproject.toml')
requirements.check(source='parsing 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)

View File

@ -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