Python#

Topics of interest#

  • new python features (syntax, type system, new APIs, …)

  • packaging, especially with setuptools for building wheels

  • cpython both C API and internals

  • C/C++, Cython

  • Rust with PyO3 / Maturin

  • Some distribution specifics about python (especially debian).

Packaging#

Base resources about packaging for the Python ecosystem. To read often.

Debian bookworm with Py 3.12#

Debian bookworm is the current stable (year of writing: 2024).

Python 3.12 adds new syntaxical constructs regarding the type systems (type definition, generic parameters directly in class/function definitions instead of add hoc type variables).

debian do not officially provide backport for this python version.

A third-party build deb package: github.com/pascallj/python3.12-backport.

The package works fine but neither pip nor ensurepip is provided by the package.

In order to get it, you have to git-clone the cpython repo, set the PYTHONPATH correctly (cpython/Lib should provide ensurepip). Before that, you should disable the usage of the sysconfig variable WHEEL_PKG_DIR by setting it directly to None. That way the wheel files that are in the cpython repo are used instead of the ones provided by Debian bookworm.

Maturin#

To build a maturin package with cross-compiling in mind:

  • install the right GCC toolchain using your distrib package manager, beware of the version of GLIBC or any libc that has versionned symbols.

  • rustup: add the target you need.

  • in my case, cargo was not able to naturally use the right linker. Setting explicitly the linker in ~/.cargo/config.toml helped

[target.<target-triple>]
linker = "<target-triple>gcc"

Also, sometime cleaning the project with cargo clean should be done when changing toolchain. In my case, it helped when changing the glibc version to not have object files refering faulty symbols.

You could check the symbols of wheel to ensure the compatibility with a given glibc using autowheel show.