🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.debian.maint.python
5 messages
5 total messages Started by Ben Finney Fri, 06 Nov 2026 00:30
Interrogate PyBuild for build directory of *only* the current Python interpreter version
#60
Author: Ben Finney
Date: Fri, 06 Nov 2026 00:30
58 lines
4048 bytes
Howdy,

How can I query PyBuild for the Debian packaging build directory of
*only* the current Python interpreter version?

The assumption here is that PyBuild executes multiple times, once for
each installed Python interpreter version, and each time has a single
answer to “what is the build directory filesystem path”. If that
assumption is incorrect, I have misunderstood the PyBuild manual page,
and I still want to know how to hook into PyBuild and get at that
information.

In ‘debian/rules’ I need to set the ‘PYTHONPATH’ for the Sphinx
documentation build system:

=====
	$(MAKE) \
		PYTHONPATH="${pybuild_computed_build_dir}" \
		${SPHINX_MAKE_OPTS} \
		html man
=====

That ‘pybuild_computed_build_dir’ is set earlier with this assignment:

=====
pybuild_computed_build_dir = $(shell \
	pybuild --print build_dir \
		| cut -d ':' -f 2 \
		| sed -e 's/^[[:space:]]*//' \
	)
=====

Which works fine when PyBuild finds only one Python interpreter. When
there are multiple (normal during a Debian development cycle), PyBuild
reports *all* the build directories, instead of just the current one
during the build:

=====
$ pybuild --print build_dir
python3.15 build_dir: /[…]/.pybuild/cpython3_3.15/build
python3.14 build_dir: /[…]/.pybuild/cpython3_3.14/build
=====

which does not allow me to get just *the one* build directory being used
for the current package. The ‘PYTHONPATH’ variable is naively set as a
concatenation of those two paths, which is invalid.

How can I get just the build directory PyBuild understands for the
current Python interpreter being used to build? Or, if I misunderstand
what PyBuild is doing (the manual page doesn't help me here), how can I
hook into PyBuild the way I need to, to get the single correct build
directory value each time?

-- 
 \           “Most people are other people. Their thoughts are someone |
  `\          else’s opinions, their lives a mimicry, their passions a |
_o__)                   quotation.” —Oscar Wilde, _De Profundis_, 1897 |
Ben Finney
Re: Interrogate PyBuild for build directory of *only* the current Python interpreter version
#61
Author: Stuart Prescott
Date: Fri, 06 Nov 2026 02:50
76 lines
8029 bytes
Hi Ben

> How can I query PyBuild for the Debian packaging build directory of
> *only* the current Python interpreter version?

The trick here is to be careful what you mean by "current".

To answer your last question first, I think your mental model of what is 
going on here is likely back to front. (Using codesearch.d.n to spot 
that this is towncrier so that I can better understand your context..)

dh_auto_build runs pybuild once; pybuild then loops over the set of 
supported interpreters. Outside of the loops being run by pybuild there 
is no "current" interpreter; that means that at the time you are running 
$(MAKE) there, there is no such thing as the current interpreter. At 
that point, there are concepts of "supported" and "default" but not 
"current". Throughout the pybuild manual 'current' is used for 
replaceable parameters that are to be expanded with the 'current' value 
during any loops being run by pybuild.

If you wanted to loop over all supported interpreters (i.e. py3versions 
-s) then you'd set up a command in a PYBUILD_* variable and the literal 
{build_dir} would be expanded by pybuild when it executed the loop; 
something like PYBUILD_AFTER_BUILD could be used.

That sequence of dh_* running pybuild and then pybuild running the loop 
over all supported interpreters occurs multiple times through the 
package build.

However, we don't normally want to rebuild the documentation for each 
supported version of the interpreter - we'd only ship one version of the 
docs. We normally only build the documentation against the default 
interpreter (i.e. py3versions -d).


> That ‘pybuild_computed_build_dir’ is set earlier with this assignment:
> 
> =====
> pybuild_computed_build_dir = $(shell \
> 	pybuild --print build_dir \
> 		| cut -d ':' -f 2 \
> 		| sed -e 's/^[[:space:]]*//' \
> 	)

It's possible to do a dance with `py3versions -d` to extract the 
variable for just the default interpreter, e.g.

     pybuild --print build_dir -p $(py3versions -dv) | awk '{print $3}'

(with an extra $ in the awk command in the makefile, of course).

But even easier, all of the pipeline can be replaced with

     pybuild --print build_dir --interpreter python3

The execution of sphinx is most often run as a 
`execute_after_dh_auto_build` step. (I'd also not do that dh_link dance 
until I was installing things from the staging output into the packages, 
but that's a matter of taste.)


Related - I've wondered if the invocation of sphinx is slowly becoming 
standardised enough that we could start configuring and running it 
through some set of PYBUILD_SPHINX_* environment variables. I feel we 
collectively spend spend more time trying to figure out how to get the 
docs to build than we do the rest of the package (and I wish there was a 
PEP-standardised interface to building docs and running tests).

cheers
Stuart


-- 
Stuart Prescott   http://www.nanonanonano.net/ stuart@nanonanonano.net
Debian Developer  http://www.debian.org/       stuart@debian.org
GPG fingerprint   90E2 D2C1 AD14 6A1B 7EBB 891D BBC1 7EBB 1396 F2F7
Re: Interrogate PyBuild for build directory of *only* the current Python interpreter version
#62
Author: Ben Finney
Date: Fri, 06 Nov 2026 04:10
39 lines
3769 bytes
Stuart Prescott <stuart@debian.org> writes:

> To answer your last question first, I think your mental model of what
> is going on here is likely back to front. (Using codesearch.d.n to
> spot that this is towncrier so that I can better understand your
> context..)

Thank you. In case anyone wants to see my fumbling, I'm attempting to
resolve Debian bug#1152592 <URL: https://bugs.debian.org/1152592>.

> However, we don't normally want to rebuild the documentation for each
> supported version of the interpreter - we'd only ship one version of
> the docs. We normally only build the documentation against the default
> interpreter (i.e. py3versions -d).

That's the key, thank you. I thought DebHelper magic was performing the
loop through the installed Python interpreters. That PyBuild magic does
that loop is something I had not gleaned from its documentation.

Probably by the time I need that again, I will have forgotten, and then
fail again to understand PyBuild's operation from its documentation. But
thank you for this time.

> But even easier, all of the pipeline can be replaced with
>
>     pybuild --print build_dir --interpreter python3
>
> The execution of sphinx is most often run as a
> `execute_after_dh_auto_build` step.

After implementing both of these suggestions, the package builds; thank
you for helping me resolve the bug. I've assigned you as the author in
Git for those commits.

-- 
 \        “The industrial system is profoundly dependent on commercial |
  `\   television and could not exist in its present form without it.” |
_o__)        —John Kenneth Galbraith, _The New Industrial State_, 1967 |
Ben Finney
Standardise Sphinx build invocation (was: Interrogate PyBuild for build directory of *only* the current Python interpreter versi...
#63
Author: Ben Finney
Date: Fri, 06 Nov 2026 04:30
24 lines
3172 bytes
Stuart Prescott <stuart@debian.org> writes:

> I've wondered if the invocation of sphinx is slowly becoming
> standardised enough that we could start configuring and running it
> through some set of PYBUILD_SPHINX_* environment variables.

On numerous occasions, and I believe ‘towncrier’ was one, I have found
the flexibility allowed by an executable configuration (‘conf.py’ in the
documentation source directory) leads to breakage using unmodified build
invocations.

I can't recall the details now. But I suspect that too many Sphinx build
systems have customised ‘conf.py’ such that they still require special
handling.

The motivation is good, though. Probably a lot of Sphinx build systems
in source packages are standard enough that we could get away with some
good defaults.

-- 
 \          “One time a cop pulled me over for running a stop sign. He |
  `\        said, ‘Didn't you see the stop sign?’ I said, ‘Yeah, but I |
_o__)                don't believe everything I read.’” —Steven Wright |
Ben Finney
Standardise running of upstream test suite (was: Interrogate PyBuild for build directory of *only* the current Python interprete...
#64
Author: Ben Finney
Date: Fri, 06 Nov 2026 04:40
35 lines
3778 bytes
Stuart Prescott <stuart@debian.org> writes:

> I wish there was a PEP-standardised interface to building docs and
> running tests.

Here I feel the pain less with documentation build systems, and far more
with test suites.

The popularity of arbitrary ‘environments” in Tox (and I assume this
also applies to Nox) has led many upstream developers to cram endless
dependency-laden development tasks into that, such that “just run the
test suite please” is effectively impossible without installing all the
upstream developer's preferred suite of helpers that have nothing to do
with the test suite.

To the point where developers will only run their test suite with Tox,
and are not inclined to support ‘python3 -m pytest’ or the like; if
they've tweaked their Tox configuration such that plain PyTest or
Unittest doesn't work any more, they don't feel moved to correct that.

Not to mention that many upstream test suites assume they're running
from the source, not on the built and installed package. So they can't
be used unmodified for AutoPkgTest.

I'm neutral on whether it's achieved via a PEP, but certainly I want
more enthusiastic promotion and adherence upstream to the requirements
of reproducible builds and continuous integration. We need it to become
typical to have a test suite that runs *without* any of the development
environment assumptions.

-- 
 \            “I was in the grocery store. I saw a sign that said ‘pet |
  `\      supplies’. So I did. Then I went outside and saw a sign that |
_o__)                             said ‘compact cars’.” —Steven Wright |
Ben Finney
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads