162b0ca
pyproject RPM macros
162b0ca
====================
162b0ca
162b0ca
This is a provisional implementation of pyproject RPM macros for Fedora 30+.
162b0ca
162b0ca
These macros are useful for packaging Python projects that use the [PEP 517] `pyproject.toml` file, which specifies the package's build dependencies (including the build system, such as setuptools, flit or poetry).
162b0ca
162b0ca
162b0ca
Usage
162b0ca
-----
162b0ca
162b0ca
If your upstream sources include `pyproject.toml` and you want to use these macros, BuildRequire them:
162b0ca
162b0ca
    BuildRequires: pyproject-rpm-macros
162b0ca
162b0ca
This will bring in python3-devel, so you don't need to require python3-devel explicitly.
162b0ca
fdf5116
In order to get automatic build dependencies on Fedora 31+, run `%pyproject_buildrequires` in the `%generate_buildrequires` section:
fdf5116
fdf5116
    %generate_buildrequires
fdf5116
    %pyproject_buildrequires
fdf5116
fdf5116
Only build dependencies according to [PEP 517] and [PEP 518] will be added.
fdf5116
All other build dependencies (such as non-Python libraries or test dependencies) still need to be specified manually.
fdf5116
fdf5116
Then, build a wheel in `%build` with `%pyproject_wheel`:
162b0ca
162b0ca
    %build
162b0ca
    %pyproject_wheel
162b0ca
fdf5116
And install the wheel in `%install` with `%pyproject_install`:
162b0ca
162b0ca
    %install
162b0ca
    %pyproject_install
162b0ca
162b0ca
03316d8
Adding run-time and test-time dependencies
03316d8
------------------------------------------
03316d8
03316d8
To run tests in the `%check` section, the package's runtime dependencies
03316d8
often need to also be included as build requirements.
03316d8
If the project's build system supports the [`prepare-metadata-for-build-wheel`
03316d8
hook](https://www.python.org/dev/peps/pep-0517/#prepare-metadata-for-build-wheel),
03316d8
this can be done using the `-r` flag:
03316d8
03316d8
    %generate_buildrequires
03316d8
    %pyproject_buildrequires -r
03316d8
03316d8
For projects that specify test requirements using an [`extra`
03316d8
provide](https://packaging.python.org/specifications/core-metadata/#provides-extra-multiple-use),
03316d8
these can be added using the `-x` flag.
03316d8
For example, if upstream suggests installing test dependencies with
03316d8
`pip install mypackage[testing]`, the test deps would be generated by:
03316d8
03316d8
    %generate_buildrequires
03316d8
    %pyproject_buildrequires -r -x testing
03316d8
8a60635
For projects that specify test requirements in their [tox] configuration,
8a60635
these can be added using the `-t` flag followed by the tox environment.
8a60635
For example, if upstream suggests running the tests on Python 3.7 with `tox -e py37`,
8a60635
the test deps would be generated by:
8a60635
8a60635
    %generate_buildrequires
8a60635
    %pyproject_buildrequires -t py37
8a60635
8a60635
Note that `-t` implies `-r`, because tox normally assumes the package is installed
8a60635
including all the runtime dependencies.
8a60635
8a60635
The `-t` option uses [tox-current-env]'s `--print-deps-only` behind the scenes.
8a60635
8a60635
[tox]: https://tox.readthedocs.io/
8a60635
[tox-current-env]: https://github.com/fedora-python/tox-current-env/
03316d8
162b0ca
Limitations
162b0ca
-----------
162b0ca
48b8e40
`%pyproject_install` currently installs all wheels in `$PWD`. We are working on a more explicit solution.
162b0ca
fdf5116
This macro changes shebang lines of every Python script in `%{buildroot}%{_bindir}` to `#! %{__python3} %{py3_shbang_opt}` (`#! /usr/bin/python3 -s`).
fdf5116
We plan to preserve existing Python flags in shebangs, but the work is not yet finished.
fdf5116
50645e1
Extras are currently ignored.
50645e1
50645e1
Some valid Python version specifiers are not supported.
50645e1
03316d8
The `-x` flag does not yet support multiple (comma-separated) extras.
044c837
8a60635
The `-t` flag does not yet support a reasonable default.
8a60635
fdf5116
[PEP 517]: https://www.python.org/dev/peps/pep-0517/
fdf5116
[PEP 518]: https://www.python.org/dev/peps/pep-0518/