%pyproject_buildrequires: Make -r (include runtime) the default, use -R to opt-out

See the proposal:
https://lists.fedoraproject.org/archives/list/python-devel@lists.fedoraproject.org/thread/2R6NKELTHAWE6PI3CCZBVW5PMGO5VPDG/

 - -N now implies -R
 - the macro still guards against -Nr and now also against -Rr
This commit is contained in:
Miro Hrončok 2022-01-14 16:26:40 +01:00
parent 832e19f5ab
commit 8c8afba774
13 changed files with 43 additions and 22 deletions

View File

@ -42,7 +42,8 @@ the macros themselves) by running `%pyproject_buildrequires` in the
%pyproject_buildrequires
This will add build dependencies according to [PEP 517] and [PEP 518].
To also add run-time and test-time dependencies, see the section below.
This also adds run-time dependencies by default and
can add test-time dependencies, see the section below.
If you need more dependencies, such as non-Python libraries, BuildRequire
them manually.
@ -68,17 +69,22 @@ And install the wheel in `%install` with `%pyproject_install`:
Adding run-time and test-time dependencies
------------------------------------------
To run tests in the `%check` section, the package's runtime dependencies
often need to also be included as build requirements.
This can be done using the `-r` flag:
To run tests or import checks in the `%check` section,
the package's runtime dependencies need to also be included as build requirements.
%generate_buildrequires
%pyproject_buildrequires -r
Hence, `%pyproject_buildrequires` also generates runtime dependencies by default.
For this to work, the project's build system must support the
[`prepare-metadata-for-build-wheel` hook](https://www.python.org/dev/peps/pep-0517/#prepare-metadata-for-build-wheel).
The popular buildsystems (setuptools, flit, poetry) do support it.
This behavior can be disabled
(e.g. when the project's build system does not support it)
using the `-R` flag:
%generate_buildrequires
%pyproject_buildrequires -R
For projects that specify test requirements using an [`extra`
provide](https://packaging.python.org/specifications/core-metadata/#provides-extra-multiple-use),
these can be added using the `-x` flag.

View File

@ -115,7 +115,8 @@ fi
%toxenv %{default_toxenv}
%pyproject_buildrequires(rxtNe:) %{expand:\\\
%pyproject_buildrequires(rRxtNe:) %{expand:\\\
%{-R:%{-r:%{error:The -R and -r options are mutually exclusive}}}
%{-N:
%{-r:%{error:The -N and -r options are mutually exclusive}}
%{-x:%{error:The -N and -x options are mutually exclusive}}

View File

@ -6,7 +6,7 @@ License: MIT
# Keep the version at zero and increment only release
Version: 0
Release: 52%{?dist}
Release: 53%{?dist}
# Macro files
Source001: macros.pyproject
@ -116,6 +116,9 @@ export HOSTNAME="rpmbuild" # to speedup tox in network-less mock, see rhbz#1856
%license LICENSE
%changelog
* Fri Jan 14 2022 Miro Hrončok <mhroncok@redhat.com> - 0-53
- %%pyproject_buildrequires: Make -r (include runtime) the default, use -R to opt-out
* Sun Dec 19 2021 Gordon Messmer <gordon.messmer@gmail.com> - 0-52
- Handle legacy version specifiers that would previously raise exceptions.

View File

@ -367,8 +367,12 @@ def main(argv):
description='Generate BuildRequires for a Python project.'
)
parser.add_argument(
'-r', '--runtime', action='store_true',
help='Generate run-time requirements',
'-r', '--runtime', action='store_true', default=True,
help='Generate run-time requirements (default, disable with -R)',
)
parser.add_argument(
'-R', '--no-runtime', action='store_false', dest='runtime',
help="Don't generate run-time requirements (implied by -N)",
)
parser.add_argument(
'-e', '--toxenv', metavar='TOXENVS', action='append',
@ -405,6 +409,9 @@ def main(argv):
args = parser.parse_args(argv)
if not args.use_build_system:
args.runtime = False
if args.toxenv:
args.tox = True

View File

@ -30,6 +30,7 @@ No pyproject.toml, empty setup.py:
installed:
setuptools: 50
wheel: 1
include_runtime: false
setup.py: |
expected: |
python3dist(setuptools) >= 40.8
@ -42,6 +43,7 @@ Default build system, empty setup.py:
setuptools: 50
wheel: 1
toml: 1
include_runtime: false
pyproject.toml: |
# empty
setup.py: |
@ -201,6 +203,7 @@ Default build system, build dependencies in setup.py:
installed:
setuptools: 50
wheel: 1
include_runtime: false
setup.py: |
from setuptools import setup
setup(
@ -223,7 +226,6 @@ Default build system, run dependencies in setup.py:
setuptools: 50
wheel: 1
pyyaml: 1
include_runtime: true
setup.py: |
from setuptools import setup
setup(
@ -246,7 +248,6 @@ Run dependencies with extras (not selected):
setuptools: 50
wheel: 1
pyyaml: 1
include_runtime: true
setup.py: &pytest_setup_py |
# slightly abriged copy of pytest's setup.py
from setuptools import setup

View File

@ -40,15 +40,16 @@ def test_data(case_name, capsys, tmp_path, monkeypatch):
)
requirement_files = case.get('requirement_files', [])
requirement_files = [open(f) for f in requirement_files]
use_build_system = case.get('use_build_system', True)
try:
generate_requires(
get_installed_version=get_installed_version,
include_runtime=case.get('include_runtime', False),
include_runtime=case.get('include_runtime', use_build_system),
extras=case.get('extras', []),
toxenv=case.get('toxenv', None),
generate_extras=case.get('generate_extras', False),
requirement_files=requirement_files,
use_build_system=case.get('use_build_system', True),
use_build_system=use_build_system,
)
except SystemExit as e:
assert e.code == case['result']

View File

@ -24,9 +24,9 @@ tar xf %{SOURCE2}
%generate_buildrequires
cd markupsafe-%{markupsafe_version}
%pyproject_buildrequires
%pyproject_buildrequires -R
cd ../tldr-%{tldr_version}
%pyproject_buildrequires
%pyproject_buildrequires -R
cd ..

View File

@ -28,7 +28,8 @@ Summary: %{summary}
%generate_buildrequires
%pyproject_buildrequires
# this runtime-requires pastel<0.2 which is no longer available in Fedora
%pyproject_buildrequires -R
%build

View File

@ -31,7 +31,7 @@ Summary: %{summary}
%generate_buildrequires
%pyproject_buildrequires -r
%pyproject_buildrequires
%build

View File

@ -28,7 +28,7 @@ Summary: %{summary}
%generate_buildrequires
%pyproject_buildrequires
%pyproject_buildrequires -R
%build

View File

@ -30,7 +30,8 @@ Summary: %{summary}
%generate_buildrequires
cd flit_core
%pyproject_buildrequires
# this runtime-requires pytoml which is no longer available in Fedora
%pyproject_buildrequires -R
cd ..
%build

View File

@ -29,7 +29,7 @@ Summary: %{summary}
%generate_buildrequires
%pyproject_buildrequires -r
%pyproject_buildrequires
%build

View File

@ -36,7 +36,7 @@ sed -Ei 's/sphinx\.git@([0-9a-f]+)/sphinx.git@\1#egg=sphinx/' requirements/docs.
# requirements/dev.in recursively includes tests.in and docs.in
# we also list tests.in manually to verify we can pass multiple arguments,
# but it should be redundant if this was a real package
%pyproject_buildrequires -r requirements/dev.in requirements/tests.in
%pyproject_buildrequires requirements/dev.in requirements/tests.in
%build