#942720 dh-python generates too tight dependencies for python3-dbus-tests

#942720#5
Date:
2019-10-20 14:45:03 UTC
From:
To:
seen when building the package with more than one supported Python3 version, the
package has the uppder dependency: python3 (<< 3.8)


python3-dbus-tests_1.2.12-1build1_amd64.deb
-------------------------------------------

  new debian package, version 2.0.
  size 31684 bytes: control archive=2524 bytes.
      993 bytes,    19 lines      control
     5800 bytes,    51 lines      md5sums
      787 bytes,    22 lines   *  postinst             #!/bin/sh
      411 bytes,    12 lines   *  prerm                #!/bin/sh
  Package: python3-dbus-tests
  Source: dbus-python
  Version: 1.2.12-1build1
  Architecture: amd64
  Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
  Original-Maintainer: Utopia Maintenance Team
<pkg-utopia-maintainers@lists.alioth.debian.org>
  Installed-Size: 387
  Depends: dbus, python3-dbus, python3 (<< 3.8), python3 (>= 3.7~), python3.8,
python3.8:any, python3:any, python3.7, python3.7:any, libc6 (>= 2.4),
libpython3.7 (>= 3.7.0), libpython3.8 (>= 3.8.0~a1)
  Recommends: gnome-desktop-testing, python3-gi

drwxr-xr-x root/root         0 2019-10-18 18:30 ./usr/lib/
drwxr-xr-x root/root         0 2019-10-18 18:30 ./usr/lib/x86_64-linux-gnu/
drwxr-xr-x root/root         0 2019-10-18 18:30
./usr/lib/x86_64-linux-gnu/installed-tests/
drwxr-xr-x root/root         0 2019-10-18 18:30
./usr/lib/x86_64-linux-gnu/installed-tests/dbus-python/
drwxr-xr-x root/root         0 2019-10-18 18:30
./usr/lib/x86_64-linux-gnu/installed-tests/dbus-python/python3.7/
drwxr-xr-x root/root         0 2019-10-18 18:30
./usr/lib/x86_64-linux-gnu/installed-tests/dbus-python/python3.7/test/
-rw-r--r-- root/root       189 2019-10-18 18:30 
./usr/lib/x86_64-linux-gnu/installed-tests/dbus-python/python3.7/test/TestSuitePythonService.service
-rwxr-xr-x root/root     20846 2019-10-18 18:30 
./usr/lib/x86_64-linux-gnu/installed-tests/dbus-python/python3.7/test/cross-test-client.py
-rwxr-xr-x root/root     12602 2019-10-18 18:30 
./usr/lib/x86_64-linux-gnu/installed-tests/dbus-python/python3.7/test/cross-test-server.py
-rw-r--r-- root/root      1881 2019-10-18 18:30 
./usr/lib/x86_64-linux-gnu/installed-tests/dbus-python/python3.7/test/crosstest.py
-rw-r--r-- root/root     14576 2019-10-18 18:30 
./usr/lib/x86_64-linux-gnu/installed-tests/dbus-python/python3.7/test/dbus_py_test.so
-rwxr-xr-x root/root      4547 2019-10-18 18:30 
./usr/lib/x86_64-linux-gnu/installed-tests/dbus-python/python3.7/test/run-test.sh
-rwxr-xr-x root/root     30351 2019-10-18 18:30 
./usr/lib/x86_64-linux-gnu/installed-tests/dbus-python/python3.7/test/test-client.py
-rwxr-xr-x root/root      1084 2019-10-18 18:30 
./usr/lib/x86_64-linux-gnu/installed-tests/dbus-python/python3.7/test/test-exception-py3.py
-rwxr-xr-x root/root     14488 2019-10-18 18:30 
./usr/lib/x86_64-linux-gnu/installed-tests/dbus-python/python3.7/test/test-import-repeatedly
-rwxr-xr-x root/root      4926 2019-10-18 18:30 
./usr/lib/x86_64-linux-gnu/installed-tests/dbus-python/python3.7/test/test-p2p.py
-rwxr-xr-x root/root     15330 2019-10-18 18:30 
./usr/lib/x86_64-linux-gnu/installed-tests/dbus-python/python3.7/test/test-service.py
-rwxr-xr-x root/root      6591 2019-10-18 18:30 
./usr/lib/x86_64-linux-gnu/installed-tests/dbus-python/python3.7/test/test-signals.py
-rwxr-xr-x root/root     22852 2019-10-18 18:30 
./usr/lib/x86_64-linux-gnu/installed-tests/dbus-python/python3.7/test/test-standalone.py
-rwxr-xr-x root/root      1743 2019-10-18 18:30 
./usr/lib/x86_64-linux-gnu/installed-tests/dbus-python/python3.7/test/test-unusable-main-loop.py
-rw-r--r-- root/root       804 2019-10-18 18:30 
./usr/lib/x86_64-linux-gnu/installed-tests/dbus-python/python3.7/test/tmp-session-bus.conf
-rwxr-xr-x root/root      1761 2019-10-18 18:30 
./usr/lib/x86_64-linux-gnu/installed-tests/dbus-python/python3.7/test/wait-for-name.py
drwxr-xr-x root/root         0 2019-10-18 18:30
./usr/lib/x86_64-linux-gnu/installed-tests/dbus-python/python3.8/
drwxr-xr-x root/root         0 2019-10-18 18:30
./usr/lib/x86_64-linux-gnu/installed-tests/dbus-python/python3.8/test/
-rw-r--r-- root/root       189 2019-10-18 18:30 
./usr/lib/x86_64-linux-gnu/installed-tests/dbus-python/python3.8/test/TestSuitePythonService.service
-rwxr-xr-x root/root     20846 2019-10-18 18:30 
./usr/lib/x86_64-linux-gnu/installed-tests/dbus-python/python3.8/test/cross-test-client.py
-rwxr-xr-x root/root     12602 2019-10-18 18:30 
./usr/lib/x86_64-linux-gnu/installed-tests/dbus-python/python3.8/test/cross-test-server.py
-rw-r--r-- root/root      1881 2019-10-18 18:30 
./usr/lib/x86_64-linux-gnu/installed-tests/dbus-python/python3.8/test/crosstest.py
-rw-r--r-- root/root     14576 2019-10-18 18:30 
./usr/lib/x86_64-linux-gnu/installed-tests/dbus-python/python3.8/test/dbus_py_test.so
-rwxr-xr-x root/root      4547 2019-10-18 18:30 
./usr/lib/x86_64-linux-gnu/installed-tests/dbus-python/python3.8/test/run-test.sh
-rwxr-xr-x root/root     30351 2019-10-18 18:30 
./usr/lib/x86_64-linux-gnu/installed-tests/dbus-python/python3.8/test/test-client.py
-rwxr-xr-x root/root      1084 2019-10-18 18:30 
./usr/lib/x86_64-linux-gnu/installed-tests/dbus-python/python3.8/test/test-exception-py3.py
-rwxr-xr-x root/root     14488 2019-10-18 18:30 
./usr/lib/x86_64-linux-gnu/installed-tests/dbus-python/python3.8/test/test-import-repeatedly
-rwxr-xr-x root/root      4926 2019-10-18 18:30 
./usr/lib/x86_64-linux-gnu/installed-tests/dbus-python/python3.8/test/test-p2p.py
-rwxr-xr-x root/root     15330 2019-10-18 18:30 
./usr/lib/x86_64-linux-gnu/installed-tests/dbus-python/python3.8/test/test-service.py
-rwxr-xr-x root/root      6591 2019-10-18 18:30 
./usr/lib/x86_64-linux-gnu/installed-tests/dbus-python/python3.8/test/test-signals.py
-rwxr-xr-x root/root     22852 2019-10-18 18:30 
./usr/lib/x86_64-linux-gnu/installed-tests/dbus-python/python3.8/test/test-standalone.py
-rwxr-xr-x root/root      1743 2019-10-18 18:30 
./usr/lib/x86_64-linux-gnu/installed-tests/dbus-python/python3.8/test/test-unusable-main-loop.py
-rw-r--r-- root/root       804 2019-10-18 18:30 
./usr/lib/x86_64-linux-gnu/installed-tests/dbus-python/python3.8/test/tmp-session-bus.conf
-rwxr-xr-x root/root      1761 2019-10-18 18:30 
./usr/lib/x86_64-linux-gnu/installed-tests/dbus-python/python3.8/test/wait-for-name.py


https://launchpadlibrarian.net/447501906/buildlog_ubuntu-focal-amd64.dbus-python_1.2.12-1build1_BUILDING.txt.gz

#942720#10
Date:
2019-11-18 13:34:19 UTC
From:
To:
I'm reassigning this to (only) dh-python because been able to work around
it in dbus-python, but I think dh-python could probably make this easier.

Firstly, please note that this bug is only reproducible when there are
at least two supported versions of python3, currently 3.7 and 3.8.
..

This is because python3-dbus-tests contains one private directory per
supported Python 3 version, with names like
/usr/lib/x86_64-linux-gnu/installed-tests/dbus-python/python3.7/test. They
are GNOME-style "installed tests", and are run by the autopkgtest.

The installed-tests directory for python3.X contains a bunch of executable
scripts (for which I want to use #!/usr/bin/python3.X), a native-code
extension dbus_py_test.so compiled for python3.X, and an executable
test-import-repeatedly which embeds the Python 3.X interpreter like
e.g. vim does (is linked to libpython3.X). The extension and embedder
were necessary to reproduce some historical dbus-python bugs that I
couldn't with pure Python.

dbus-python's debian/rules loops over all those private directories running
an appropriate dh_python3 --shebang for each one.

dh-python assumes that an unversioned extension in a private directory
is designed to be loaded by the default Python interpreter, so when it
sees dbus_py_test.so it generates a dependency on the default Python
interpreter: currently that's python3 (>= 3.7), (<< 3.8~).

I tried renaming each copy of dbus_py_test.so to
dbus_py_test.cpython-37m-x86_64-linux-gnu.so or similar (whatever is
appropriate for the corresponding python3.X version), but that makes
dh_python3 generate *contradictory* dependencies: at the time of writing
(during the migration from 3.7 to 3.8) it generates

    python3 (>= 3.7), python3 (<< 3.8~), python3 (>= 3.8), python3 (<< 3.9~)

which is impossible to satisfy. This gets simplified to

    python3 (<< 3.8~), python3 (>= 3.8)

in the actual package, but that's also impossible.

I also tried doing each dh_python3 with a different DEBPYTHON3_DEFAULT=3.X
to make it assume that /usr/lib/.../python3.X/test/dbus_py_test.so belongs
to python3.X, but that makes it generate the same contradictory
dependencies.

I was able to work around this by moving dbus_py_test.so into the public
Python directory /usr/lib/python3/dist-packages *and* renaming it to
dbus_py_test.cpython-37m-x86_64-linux-gnu.so or similar.

    smcv

#942720#19
Date:
2025-12-21 01:07:46 UTC
From:
To:
Hi Simon (2019.11.18_09:34:19_-0400)

Sorry for never looking at this sooner, I forget to do it while we have
multiple supported versions in the archive.

I can reproduce the issue by reverting
03a575e082f3b6313c52f16808186d39e9942448 and building dbus-python.

I was not familiar with GNOME's installed test style. My inclination
would have been to have one Python tree that I run the tests against
with each supported Python version. I see the upstream exposes the
PYTHON variable for this purpose, so there could be two trees of '.test'
files referring to one tree of Python source.

I guess this would require some work in the package's build system to
support it... If you did that, then I think this whole issue becomes moot.
binary package. That was not something it was designed to do, and it's
how you get mutually-incompatible sets of dependencies.

I don't know how other debhelper scripts handle this, but I'd expect
that anything that's expecting to generate comprehensive sets of
dependencies could run into trouble in this situation.

Back to this issue, do we even need to alter the shebangs? It looks like
the .test files explicitly call the correct Python, so we can do
something as simple as:

override_dh_python3:
	dh_python3 /usr/libexec/installed-tests/dbus-python/

That will generate:
  Depends: dbus-daemon, python3-dbus, python3 (<< 3.15), python3 (>= 3.13~), python3:any, libc6 (>= 2.34), libpython3.13 (>= 3.13.0~rc3), libpython3.14 (>= 3.14.1)

The tests don't pass, and I didn't dig into why, but they could probably
be made to work.

However, a little sed shebang hackery makes them work:

override_dh_python3:
	set -e; for x in $(PYTHON3); do \
		sed -i "1 s,^#!.*,#!/usr/bin/python$$x," \
			debian/python3-dbus-tests/usr/libexec/installed-tests/dbus-python/python$$x/test/*.py; \
	done
	dh_python3 /usr/libexec/installed-tests/dbus-python/

So, where does that leave us?

While the bug looked nasty from the description, I'm really not
convinced that dh-python should change anything here. Maybe document
that you can't call dh_python3 multiple times for different Python
versions, but that's not something I can easily imagine needing to do in
Debian. This was a very unusual use-case.

Stefano