diff --git a/README.md b/README.md index f749bf9..c922f6c 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/macros.pyproject b/macros.pyproject index a3e3da3..57c6d48 100644 --- a/macros.pyproject +++ b/macros.pyproject @@ -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}} diff --git a/pyproject-rpm-macros.spec b/pyproject-rpm-macros.spec index b7579fb..71cfe3a 100644 --- a/pyproject-rpm-macros.spec +++ b/pyproject-rpm-macros.spec @@ -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 - 0-53 +- %%pyproject_buildrequires: Make -r (include runtime) the default, use -R to opt-out + * Sun Dec 19 2021 Gordon Messmer - 0-52 - Handle legacy version specifiers that would previously raise exceptions. diff --git a/pyproject_buildrequires.py b/pyproject_buildrequires.py index ba433b2..5f55b01 100644 --- a/pyproject_buildrequires.py +++ b/pyproject_buildrequires.py @@ -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 diff --git a/pyproject_buildrequires_testcases.yaml b/pyproject_buildrequires_testcases.yaml index e951cdb..307af79 100644 --- a/pyproject_buildrequires_testcases.yaml +++ b/pyproject_buildrequires_testcases.yaml @@ -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 diff --git a/test_pyproject_buildrequires.py b/test_pyproject_buildrequires.py index 9588bba..15075c5 100644 --- a/test_pyproject_buildrequires.py +++ b/test_pyproject_buildrequires.py @@ -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'] diff --git a/tests/double-install.spec b/tests/double-install.spec index 93a9778..56eaa37 100644 --- a/tests/double-install.spec +++ b/tests/double-install.spec @@ -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 .. diff --git a/tests/python-clikit.spec b/tests/python-clikit.spec index dbb0044..0454c28 100644 --- a/tests/python-clikit.spec +++ b/tests/python-clikit.spec @@ -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 diff --git a/tests/python-distroinfo.spec b/tests/python-distroinfo.spec index c2945cc..52f8354 100644 --- a/tests/python-distroinfo.spec +++ b/tests/python-distroinfo.spec @@ -31,7 +31,7 @@ Summary: %{summary} %generate_buildrequires -%pyproject_buildrequires -r +%pyproject_buildrequires %build diff --git a/tests/python-django.spec b/tests/python-django.spec index bb5da10..e6488db 100644 --- a/tests/python-django.spec +++ b/tests/python-django.spec @@ -28,7 +28,7 @@ Summary: %{summary} %generate_buildrequires -%pyproject_buildrequires +%pyproject_buildrequires -R %build diff --git a/tests/python-flit-core.spec b/tests/python-flit-core.spec index d3333d8..d20d2c2 100644 --- a/tests/python-flit-core.spec +++ b/tests/python-flit-core.spec @@ -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 diff --git a/tests/python-isort.spec b/tests/python-isort.spec index 9295f50..2881fa5 100644 --- a/tests/python-isort.spec +++ b/tests/python-isort.spec @@ -29,7 +29,7 @@ Summary: %{summary} %generate_buildrequires -%pyproject_buildrequires -r +%pyproject_buildrequires %build diff --git a/tests/python-markupsafe.spec b/tests/python-markupsafe.spec index 3f4e3bd..b400214 100644 --- a/tests/python-markupsafe.spec +++ b/tests/python-markupsafe.spec @@ -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