fix: python bindings: install on Debian python >= 3.10
authorMichael Jeanson <mjeanson@efficios.com>
Tue, 13 Jun 2023 22:22:37 +0000 (18:22 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 18 Oct 2023 04:45:23 +0000 (00:45 -0400)
Starting with Debian's Python 3.10, the default install scheme is
'posix_local' which is a Debian specific scheme based on 'posix_prefix'
but with an added 'local' prefix. This is the default so users doing
system wide manual installations of python modules end up in
'/usr/local'. This interferes with our autotools based install which
already defaults to '/usr/local' and expects a provided prefix to be
used verbatim.

Monkeypatch sysconfig to override this scheme and use 'posix_prefix'
instead.

Change-Id: I41973f6db4966519aa1c7e74a9d1e9b5d90bf7ea
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10343
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
src/bindings/python/bt2/setup.py.in

index 9b4294c7e0c9712cea32350342f14fa4744b44eb..d9c0bf33245a072256dd3f63824f5dcb7bae3937 100644 (file)
@@ -6,13 +6,37 @@
 import sys
 import os
 
-if sys.version_info < (3, 12):
-    from distutils.core import setup, Extension
-    import distutils.sysconfig as sysconfig
-else:
+# Distutils was removed in Python 3.12, use setuptools as an alternative.
+if sys.version_info >= (3, 12):
     from setuptools import setup, Extension
+else:
+    from distutils.core import setup, Extension
+
+# Starting with Debian's Python 3.10, the default install scheme is
+# 'posix_local' which is a Debian specific scheme based on 'posix_prefix' but
+# with an added 'local' prefix. This is the default so users doing system wide
+# manual installations of python modules end up in '/usr/local'. This
+# interferes with our autotools based install which already defaults to
+# '/usr/local' and expect a provided prefix to be used verbatim.
+#
+# Monkeypatch sysconfig to override this scheme and use 'posix_prefix' instead.
+if sys.version_info >= (3, 10):
     import sysconfig
 
+    original_get_preferred_scheme = sysconfig.get_preferred_scheme
+
+    def our_get_preferred_scheme(key):
+        scheme = original_get_preferred_scheme(key)
+        if scheme == "posix_local":
+            return "posix_prefix"
+        else:
+            return scheme
+
+    sysconfig.get_preferred_scheme = our_get_preferred_scheme
+
+else:
+    import distutils.sysconfig as sysconfig
+
 PY_PATH_WARN_MSG = """
 -------------------------------------WARNING------------------------------------
 The install directory used:\n ({})\nis not included in your PYTHONPATH.
This page took 0.026127 seconds and 4 git commands to generate.