fix: python bindings: use stdlib distutils when setuptools is installed
authorMichael Jeanson <mjeanson@efficios.com>
Thu, 15 Jun 2023 17:29:54 +0000 (13:29 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 18 Oct 2023 04:45:23 +0000 (00:45 -0400)
When the setuptools package is installed, it monkey patches the standard
library distutils even if the user code doesn't import setuptools.

This results in a failure to install the Python agent in a directory
which isn't in the current PYTHONPATH. To allow this, setuptools requires
the '--single-version-externally-managed' options which is not
implemented in distutils.

To resolve this, force the use of distutils for Python < 3.12 even when
setuptools is installed with the 'SETUPTOOLS_USE_DISTUTILS' environment
variable and use the previously mentionned setuptools option with Python
>= 3.12 which doesn't include distutils anymore.

Change-Id: I9e8412021c6ec79b0a9ea38759c475113e4ea018
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10371
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
.gitignore
configure.ac
src/bindings/python/bt2/Makefile.am

index f61686207a30bdc1469fe11024d15e9f4aa38475..f1ae13d93404e0473383d7bbdec8254f57edc68b 100644 (file)
@@ -31,6 +31,8 @@
 /src/plugins/ctf/common/metadata/parser.cpp
 /src/plugins/ctf/common/metadata/parser.hpp
 /src/plugins/ctf/common/metadata/parser.output
+/src/bindings/python/bt2/bt2.egg-info
+/src/bindings/python/bt2/dist
 /src/cli/babeltrace2
 /src/cli/babeltrace2.bin
 /src/cli/babeltrace2-log
index f81e73342dff671e8ea1f487939833e4a5006462..95483337b0b633a6bee32fd2b4ac2e0f5a0d060c 100644 (file)
@@ -535,6 +535,14 @@ AS_IF([test -n "$PYTHON_CONFIG"], [have_python_dev=yes], [have_python_dev=no])
 AM_CONDITIONAL([HAVE_PYTHON], [test "x$have_python" = xyes])
 AM_CONDITIONAL([HAVE_PYTHON_DEV], [test "x$have_python_dev" = xyes])
 
+AS_IF([test "x$have_python" = xyes], [
+  AX_COMPARE_VERSION(["$PYTHON_VERSION"], [ge], ["3.12"], [
+    have_python_312_or_greater=yes
+  ])
+])
+
+AM_CONDITIONAL([HAVE_PYTHON_312_OR_GREATER], [test "x$have_python_312_or_greater" = xyes])
+
 AS_IF([AE_IS_FEATURE_ENABLED([python-bindings]) || AE_IS_FEATURE_ENABLED([python-plugins])], [
   AS_IF([test "x$have_python_dev" = xno], [
     AC_MSG_ERROR([Cannot find a suitable python-config. You can override the python-config path with the PYTHON_CONFIG environment variable.])
index 6b31a743391c52eae99f471cf9b3bb509c84fbb4..fee3313430acd46991c6196976723a24937512a2 100644 (file)
@@ -155,12 +155,21 @@ pyinstall_verbose = $(pyinstall_verbose_@AM_V@)
 pyinstall_verbose_ = $(pyinstall_verbose_@AM_DEFAULT_V@)
 pyinstall_verbose_0 = @
 
+# For Python < 3.12, force the use of distutils even if setuptools is
+# installed. For Python >= 3.12, set the externally managed option to allow
+# installation in a directory which isn't in the current PYTHONPATH.
+if HAVE_PYTHON_312_OR_GREATER
+PY_INSTALL_OPTS = --single-version-externally-managed
+else
+export SETUPTOOLS_USE_DISTUTILS=stdlib
+endif
+
 install-exec-local: build-python-bindings.stamp
        $(pyinstall_verbose)opts="--prefix=$(prefix) --exec-prefix=$(exec_prefix) --record $(INSTALLED_FILES) --verbose --no-compile $(DISTSETUPOPTS)"; \
        if [ "$(DESTDIR)" != "" ]; then \
                opts="$$opts --root=$(DESTDIR)"; \
        fi; \
-       $(PYTHON) $(builddir)/setup.py install $$opts;
+       $(PYTHON) $(builddir)/setup.py install $(PY_INSTALL_OPTS) $$opts;
 
 clean-local:
        rm -rf $(builddir)/build
This page took 0.025865 seconds and 4 git commands to generate.