2019-07-02 10:41:04 +00:00
pyproject RPM macros
====================
This is a provisional implementation of pyproject RPM macros for Fedora 30+.
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).
Usage
-----
If your upstream sources include `pyproject.toml` and you want to use these macros, BuildRequire them:
BuildRequires: pyproject-rpm-macros
This will bring in python3-devel, so you don't need to require python3-devel explicitly.
2019-07-02 14:53:05 +00:00
In order to get automatic build dependencies on Fedora 31+, run `%pyproject_buildrequires` in the `%generate_buildrequires` section:
%generate_buildrequires
%pyproject_buildrequires
Only build dependencies according to [PEP 517] and [PEP 518] will be added.
All other build dependencies (such as non-Python libraries or test dependencies) still need to be specified manually.
Then, build a wheel in `%build` with `%pyproject_wheel` :
2019-07-02 10:41:04 +00:00
%build
%pyproject_wheel
2019-07-02 14:53:05 +00:00
And install the wheel in `%install` with `%pyproject_install` :
2019-07-02 10:41:04 +00:00
%install
%pyproject_install
2019-07-18 09:21:26 +00:00
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.
If the project's build system supports the [`prepare-metadata-for-build-wheel`
hook](https://www.python.org/dev/peps/pep-0517/#prepare-metadata-for-build-wheel),
this can be done 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.
For example, if upstream suggests installing test dependencies with
`pip install mypackage[testing]` , the test deps would be generated by:
%generate_buildrequires
%pyproject_buildrequires -r -x testing
2019-07-26 12:34:21 +00:00
For projects that specify test requirements in their [tox] configuration,
these can be added using the `-t` flag followed by the tox environment.
For example, if upstream suggests running the tests on Python 3.7 with `tox -e py37` ,
the test deps would be generated by:
%generate_buildrequires
%pyproject_buildrequires -t py37
Note that `-t` implies `-r` , because tox normally assumes the package is installed
including all the runtime dependencies.
The `-t` option uses [tox-current-env]'s `--print-deps-only` behind the scenes.
[tox]: https://tox.readthedocs.io/
[tox-current-env]: https://github.com/fedora-python/tox-current-env/
2019-07-18 09:21:26 +00:00
2019-07-02 10:41:04 +00:00
Limitations
-----------
2019-07-02 11:56:49 +00:00
`%pyproject_install` currently installs all wheels in `$PWD` . We are working on a more explicit solution.
2019-07-02 10:41:04 +00:00
2019-07-02 14:53:05 +00:00
This macro changes shebang lines of every Python script in `%{buildroot}%{_bindir}` to `#! %{__python3} %{py3_shbang_opt}` (`#! /usr/bin/python3 -s`).
We plan to preserve existing Python flags in shebangs, but the work is not yet finished.
2019-07-17 13:44:22 +00:00
Extras are currently ignored.
Some valid Python version specifiers are not supported.
2019-07-18 09:21:26 +00:00
The `-x` flag does not yet support multiple (comma-separated) extras.
2019-07-01 15:15:34 +00:00
2019-07-26 12:34:21 +00:00
The `-t` flag does not yet support a reasonable default.
2019-07-02 14:53:05 +00:00
[PEP 517]: https://www.python.org/dev/peps/pep-0517/
[PEP 518]: https://www.python.org/dev/peps/pep-0518/