Project:Python/python-exec

python-exec is the tool used to wrap Python scripts for multiple implementations. In the process of wrapping, the original Python script is replaced by a special wrapper executable that invokes a proper version of the original script depending on which Python interpreter is used/requested.

Configuration files
Starting with python-exec-2.3, python-exec is configured by one or more files located in /etc/python-exec. The main system configuration is specified in python-exec.conf, and this configuration can be overrode for specific scripts by creating .conf files.

Each of the configuration files specifies zero or more preferred implementations, one per line, in descending preference order (i.e. the most preferred first). Additionally, implementations can be disabled from fallback use by listing their names prefixed by a hyphen (-). The implementations neither listed as preferences, nor disabled, are considered fallback implementations.

When running a script with no forced implementation (EPYTHON unset and not spawned via Python interpreter), python-exec will first try to find the script variant for preferred implementations, in order. If none of the preferred implementations are supported, python-exec falls back to trying the remaining implementations that are supported yet not disabled, in wrapper-defined order.

eselect-python
eselect-python provides an easy way to configure preferred/active Python interpreters. Since python-exec-2.3 / eselect-python-20160207, eselect-python alters altering python-exec.conf. Previous versions use old configuration format that was used by python.eclass wrappers, python-wrapper and older versions of python-exec.

For new versions, the preferred method of altering configuration is to use the edit mode that opens python-exec.conf in an editor:

In order to list all supported interpreters, in preference order:

In order to set a new preferred interpreter, you can use:

Note that this will set the specified interpreter as the most preferred one, moving existing preferences lower.

Use in ebuilds
It is recommended to assume that the details of script wrapping are a private implementation detail and avoid relying on any specifics in ebuilds. Most of the time, the implicit wrapper support in the eclasses suffice. In particular:


 * distutils-r1 sets setup.py up to install wrapped scripts into appropriate directories and creates the wrapper symlinks afterwards,
 * python_doexe and remaining install helpers install scripts into appropriate directories and create the wrapper symlinks.