Package: dh-python
Version: 6.20240603
Severity: wishlist
File: /usr/share/dh-python/pybuild
X-Debbugs-Cc: debian-pyt...@lists.debian.org, cru...@debian.org

Dear Maintainers,

Please enhance pybuild (when using setuptools via the default plugin, or when 
using the pyproject plugin and the build backend is also setuptools) to build 
Python extensions in parallel when DEB_BUILD_OPTIONS contains the 'parallel=N' 
directive.

This can be accomplished by making a temporary file using the following template and 
setting the environment variable DIST_EXTRA_CONFIG [0] to the path of the temporary file. 
This is similar to the ".pydistutils.cfg" trick used in the pybuild distutils 
plugin [1].

cat > extra-setup.cfg <<EOF
[build_ext]
parallel=N
EOF

Where N is the value of "parallel" set in DEB_BUILD_OPTIONS.

One presume that dh-python will also respect the common "--parallel", "--no-parallel", 
and "--max-parallel" debhelper flags when setting up the pybuild invocation.

Doing this technique directly, I measured a speed up of 32% for the mypy 
package [2] when in multi-file mode on a server with a large core count.

I would send a merge request, or attach a patch, but it is unclear where the 
authors and maintainers of dh-python would like this logic to go. Feel free to 
give advice.

This technique is an adaptation of this Gentoo blog post. Many thanks to the 
author, Michał Górny, for it: 
https://blogs.gentoo.org/mgorny/2024/03/15/optimizing-parallel-extension-builds-in-pep517-builds/

[0] Historically undocumented, but now is documented at 
https://setuptools.pypa.io/en/latest/deprecated/distutils/configfile.html#writing-the-setup-configuration-file
[1] 
https://salsa.debian.org/python-team/tools/dh-python/-/blob/b0fd6c5391a232374cdb2371139bbbbc61aad890/dhpython/build/plugin_distutils.py#L32-60
[2] 
https://salsa.debian.org/python-team/packages/mypy/-/commit/dc6fcce96341163fba81ed46a3990e28fe27bbe5

Cheers,

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

Reply via email to