Python byte-compiled files

tlaronde at kergis.com tlaronde at kergis.com
Sat Mar 23 16:24:39 UTC 2024


The byte-compiled (version depending) files for *.py should be
generated at install time, on the target, because:

1) Python files have only sense on nodes where a python interpreter
is installed; and the byte-compilation is generated by an interpreter;

2) byte-compiled versions are not portable.

So this is almost impossible to get right when doing cross-compilation
and, since a node needs a python interpreter, there is no supplementary
"compiler" that would be requested on the target.

The problems are multiple:

1) With autotools, the python version is decided on the matrix (the
building node) at configure time. But it is not there that the target
python version(s) have to be decided;

2) The pkgconfig file registers the python version, and this is
decided at compile time too. Finding the correct paths, for the
target, would mean post-processing the pkgconfig file on installation.
Or we could follow:

	 https://peps.python.org/pep-3147/

that is put the sources (.py) in a common python subdir (with no
version), and letting python version dependent byte-compiled file being
placed under __pycache_.

Furthermore, for example for xcb-proto, the python interface is one
interface, but it is not mandatory (there is the primary C interface).

I'm trying to write the meson files, providing what is provided by the
autotools framework, but I'd like to not hamper meson with autotools
infelicities.

So a proposal:

- When python is not require, change in configure.ac:

AM_PATH_PYTHON([2.5])

to

AM_PATH_PYTHON([2.5],, [:])

i.e. take python as optional and omit whatever processing is python
dependent.

- Provide POSIX.2 shell scripts (already written for my risk_comp
own framework) to find whatever version of python
is present if PYTHON is not defined in the environment, and
byte-compile for all the versions matching the requirements (>=2.5 for
example). These scripts will be called from meson.build but could be
used in whatever framework to provide the facilities.

A question: is there a way in pkgconfig to put a "variable" that can
be expanded according to the environment i.e. write a path depending
on some ${python} string expanding to a versioned string depending on
the interpreter present on the system, so that a .pc file can be
generic and not hard-linked to some python version?
-- 
        Thierry Laronde <tlaronde +AT+ kergis +dot+ com>
                     http://www.kergis.com/
                    http://kertex.kergis.com/
Key fingerprint = 0FF7 E906 FBAF FE95 FD89  250D 52B1 AE95 6006 F40C


More information about the xorg-devel mailing list