%pyproject_buildrequires: Fallback to setuptools.build_meta:__legacy__ only if setup.py exists

Fixes: rhbz#1976459

Related: rhbz#1950291
This commit is contained in:
Tomas Hrnciar 2021-07-16 22:36:57 +00:00 committed by Miro Hrončok
parent a4b3946fbf
commit d74e61b485
4 changed files with 37 additions and 13 deletions

View File

@ -97,10 +97,13 @@ echo 'python%{python3_pkgversion}dist(pip) >= 19'
echo 'python%{python3_pkgversion}dist(packaging)'
%{!-N:if [ -f pyproject.toml ]; then
echo 'python%{python3_pkgversion}dist(toml)'
else
elif [ -f setup.py ]; then
# Note: If the default requirements change, also change them in the script!
echo 'python%{python3_pkgversion}dist(setuptools) >= 40.8'
echo 'python%{python3_pkgversion}dist(wheel)'
else
echo 'ERROR: Neither pyproject.toml nor setup.py found, consider using %%%%pyproject_buildrequires -N <requirements-file> if this is not a Python package.' >&2
exit 1
fi}
# Check if we can generate dependencies on Python extras
if [ "%{py_dist_name []}" == "[]" ]; then

View File

@ -110,9 +110,10 @@ export HOSTNAME="rpmbuild" # to speedup tox in network-less mock, see rhbz#1856
%license LICENSE
%changelog
* Fri Jul 09 2021 Miro Hrončok <miro@hroncok.cz> - 0-44
* Fri Jul 09 2021 Python Maint <python-maint@redhat.com> - 0-44
- Escape weird paths generated by %%pyproject_save_files
- Support x.* versions in %%pyproject_buildrequires
- %%pyproject_buildrequires fallbacks to setuptools only if setup.py exists
- Rebuilt for IMA sigs, glibc 2.34, aarch64 flags
Related: rhbz#1991688

View File

@ -181,6 +181,10 @@ def get_backend(requirements):
# missing, the source tree is not using this specification, and tools
# should revert to the legacy behaviour of running setup.py
# (either directly, or by implicitly invoking the [following] backend).
# If setup.py is also not present program will mimick pip's behavior
# and end with an error.
if not os.path.exists('setup.py'):
raise FileNotFoundError('File "setup.py" not found for legacy project.')
backend_name = 'setuptools.build_meta:__legacy__'
# Note: For projects without pyproject.toml, this was already echoed

View File

@ -1,10 +1,7 @@
No pyproject.toml, nothing installed:
installed:
# empty
expected: |
python3dist(setuptools) >= 40.8
python3dist(wheel)
result: 0
except: FileNotFoundError
Nothing installed yet:
installed:
@ -14,7 +11,7 @@ Nothing installed yet:
expected: |
python3dist(setuptools) >= 40.8
python3dist(wheel)
result: 0
except: FileNotFoundError
Insufficient version of setuptools:
installed:
@ -23,6 +20,7 @@ Insufficient version of setuptools:
toml: 1
pyproject.toml: |
# empty
setup.py: |
expected: |
python3dist(setuptools) >= 40.8
python3dist(wheel)
@ -53,6 +51,24 @@ Default build system, empty setup.py:
python3dist(wheel)
result: 0
pyproject.toml with build-backend and setup.py:
generate_extras: true
installed:
setuptools: 50
wheel: 1
toml: 1
setup.py: |
# empty
pyproject.toml: |
[build-system]
requires = [
"foo",
]
build-backend = "foo.build"
expected: |
python3dist(foo)
result: 0
Erroring setup.py:
installed:
setuptools: 50
@ -74,7 +90,8 @@ Single value version with unsupported compatible operator:
toml: 1
pyproject.toml: |
[build-system]
requires = ["pkg ~= 42"]
requires = ["pkg ~= 42", "foo"]
build-backend = "foo.build"
stderr_contains: "WARNING: Skipping invalid requirement: pkg ~= 42"
result: 0
@ -83,7 +100,8 @@ Asterisk in version with unsupported compatible operator:
toml: 1
pyproject.toml: |
[build-system]
requires = ["pkg ~= 0.1.*"]
requires = ["pkg ~= 0.1.*", "foo"]
build-backend = "foo.build"
stderr_contains: "WARNING: Skipping invalid requirement: pkg ~= 0.1.*"
result: 0
@ -113,6 +131,7 @@ Build system dependencies in pyproject.toml with extras:
"py2 ; python_version < '2.7'",
"py3 ; python_version > '3.0'",
]
build-backend = "foo.build"
expected: |
python3dist(foo)
python3dist(bar) > 5
@ -131,8 +150,6 @@ Build system dependencies in pyproject.toml with extras:
python3dist(multi[extras2]) = 6
((python3dist(combo) < 3 or python3dist(combo) > 3) with python3dist(combo) < 5 with python3dist(combo) > 2)
python3dist(py3)
python3dist(setuptools) >= 40.8
python3dist(wheel)
result: 0
Build system dependencies in pyproject.toml without extras:
@ -147,11 +164,10 @@ Build system dependencies in pyproject.toml without extras:
"bar[Baz] > 5",
"multi[extras1,extras2] == 6.0",
]
build-backend = "foo.build"
expected: |
python3dist(bar) > 5
python3dist(multi) = 6
python3dist(setuptools) >= 40.8
python3dist(wheel)
result: 0
Default build system, build dependencies in setup.py: