openSUSE / python-rpm-macros

Multi-Python, Single-Spec macros generator
Other
22 stars 20 forks source link
macros python python3 rpm

Multi-Python, Single-Spec Macro System

This repository contains a work-in-progress macro system generator for the singlespec Python initiative. The macro system can be used in spec files for building RPM packages.

The purpose of the singlespec system is to take a package for a particular flavor, and autogenerate subpackages for all the other flavors.

Terminology

<flavor> is a kind of python interpreter. At this point, we recognize the following flavors: python2, python3, python38, python39, python310, python311 and pypy3. python3 points to the default of coinstallable flavors python3<M> where <M> is the minor version number. The default is specified not by python-rpm-macros but by the obs project definition in %primary_python.

The flavor is used as a prefix for all flavor-specific macros. Some macros are redefined with "short" flavor for compatibility reasons, such as py3 for python3. All of them have a "long" form too.

For compatibility reasons you see sometimes python. In most places, using python is either a redefinition of python2, or an alternative for "flavor-agnostic". Conditionals are in place to switch python to mean python3 in the future.

The name of the binary in %_bindir (/usr/bin) is the name of the flavor with an addtional . between the major and minor version number, in case the latter is part of the flavor name:

modname is the PyPI name, or, if the package in question is not on PyPI, the moniker that we chose to stand in for it.

Packages adhering to the SUSE Python module naming policy are usually called <flavor>-modname. In some cases, it is only modname though.

pkgname, or subpackage name, is internal to a spec file, and is that thing you put after the %package macro. Pkgname of the package itself is an empty string. Pkgname of a %package -n something is at this point -n something, and denotes that this subpackage should not be handled by the generator. That means, if you want a subpackage to be skipped, rename it from %package foo to %package -n %{name}-foo.

The purpose of the singlespec system is to take a package called <flavor>-modname for a particular flavor, and autogenerate subpackages for all the other flavors.

Alternately, it is to take package python-modname and generate subpackages for all flavors, leaving the top-level package empty.

Additionally it is possible for non-Python packages which define a subpackage %package -n python-modname and corresponding %description -n python-modname etc., to autogenerate all desired flavor subpackages <flavor>-modname.

Build Set

The default build set is listed in the %pythons macro. Every entry in %pythons generates a requirement in %python_module, a subpackage from %python_subpackages (unless the top-level spec file is for that flavor), and an additional run of loops like %python_build, _install, _exec and _expand.

To control the build set, you can either completely redefine %pythons, or exclude particular flavor(s) by defining _`%skip__. For example, if you%define skip_python2 1`, then Python 2 will be excluded from the default build set. (Python 2 is not in the default build set of Tumbleweed and SLE/Leap >= 15.4)

Skip-macros are intended for per-package use only. Never define a skip-macro in prjconf or in any other sort of global config. Instead, redefine %pythons.

Macros

The following macros are considered public API:

Conditionals

These are shortcuts for %if "%python_flavor" == "<flavor>". Due to how RPM evaluates the shortcuts, they will fail when nested with other %if conditions. If you need to nest your conditions, use the full %if "%python_flavor" spelling.

Flavor expansion

The following macros expand to command lists for all flavors and move around the distutils-generated build directory so that you are never running a python39 command with a python310-generated build and vice versa.

General command expansion macros
Install macros
Unit testing

Alternative-related, general:

Alternative-related, for Python:

Each of these has a flavor-specific spelling: %python2_alternative etc.

Libalternatives-related:

Libalternatives provides another way for settings alternative. Instead of symlinks, the preferred executable is executed directly. Which executable is executed depends on the available alternatives installed on the system and the system and/or user configuration files. These configuration files will also be generated by the macros described above AND following settings in the spec file:

Building and testing with flavored alternatives

Flavor-specific macros

In addition, the following flavor-specific macros are known and supported by the configuration:

For reasons of preferred-flavor-agnosticity, aliases python_* are available for all of these.

We recognize %py_ver, %py2_ver and %py3_ver as deprecated spellings of %<flavor>_version. No such shortcut is in place for pypy3. Furthermore, %py2_build, _install and _shbang_opts, as well as py3 variants, are recognized for Fedora compatibility.

%files section

For subpackages of non-python packages with %python_subpackage_onlyand %package -n %{python_flavor}-modname, also use %files %{python_files modname}.

Always use the flavor-agnostic macro versions %python_* inside %python_files marked %files sections.

See also the Filelists section of the openSUSE:Packaging Python guidelines

Files in Repository