RPM macros for PEP 517 Python packages
Go to file
Fedora Release Engineering 6cfe9d4b22 - Rebuilt for https://fedoraproject.org/wiki/Fedora_31_Mass_Rebuild
Signed-off-by: Fedora Release Engineering <releng@fedoraproject.org>
2019-07-26 11:47:03 +00:00
tests Clean up python-entrypoints.spec 2019-07-18 11:54:04 +02:00
.gitignore Refactor and add tests 2019-07-17 15:57:02 +02:00
LICENSE initial import (#1717389) 2019-07-02 12:41:04 +02:00
macros.pyproject Allow specifying extras for build dependencies 2019-07-18 10:50:13 +02:00
pyproject_buildrequires.py Mark multiple extras as not supported yet 2019-07-18 11:00:23 +02:00
pyproject-rpm-macros.rpmlintrc Add rpmlint RC file and URL 2019-07-02 13:06:11 +02:00
pyproject-rpm-macros.spec - Rebuilt for https://fedoraproject.org/wiki/Fedora_31_Mass_Rebuild 2019-07-26 11:47:03 +00:00
README.md Document run-time deps 2019-07-18 11:24:18 +02:00
sources initial import (#1717389) 2019-07-02 12:41:04 +02:00
test_pyproject_buildrequires.py Mark multiple extras as not supported yet 2019-07-18 11:00:23 +02:00
testcases.yaml Mark multiple extras as not supported yet 2019-07-18 11:00:23 +02: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.

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:

%build
%pyproject_wheel

And install the wheel in %install with %pyproject_install:

%install
%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. If the project's build system supports the prepare-metadata-for-build-wheel hook, this can be done using the -r flag:

%generate_buildrequires
%pyproject_buildrequires -r

For projects that specify test requirements using an extra provide, 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

Limitations

%pyproject_install currently installs all wheels in $PWD. We are working on a more explicit solution.

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.

The PEPs don't (yet) define a way to specify test dependencies and test runners. That means you still need to handle test dependencies and %check on your own.

Extras are currently ignored.

Some valid Python version specifiers are not supported.

The -x flag does not yet support multiple (comma-separated) extras.