fix: python agent: use stdlib distutils when setuptools is installed
authorMichael Jeanson <mjeanson@debian.org>
Wed, 14 Jun 2023 20:55:28 +0000 (16:55 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 20 Jun 2023 12:20:37 +0000 (08:20 -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 ins'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 proper setuptools option with python >= 3.12 which
doesn't include distutils anymore.

Change-Id: Idf477ca61bed460c9f6be7f481fe3b84624f328c
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
configure.ac
src/python-lttngust/Makefile.am

index 16dee8b368e5b60e5dd395fac86913ea1b581d49..86ef7c9cd82c64053867e60674f22c6585099aab 100644 (file)
@@ -483,6 +483,7 @@ environment variable.
   ])
 
   AX_COMPARE_VERSION(["$PYTHON_VERSION"], [ge], ["3.12"], [
+    have_python_312_or_greater=yes
     AC_MSG_CHECKING([for python setuptools])
     AS_IF(["$PYTHON" -c "import setuptools" 2>/dev/null], [
       AC_MSG_RESULT([yes])
@@ -576,6 +577,7 @@ AM_CONDITIONAL([HAVE_CMAKE], [test "x$CMAKE" != "x"])
 AM_CONDITIONAL([HAVE_CXX], [test "$HAVE_CXX11" = "1"])
 AM_CONDITIONAL([HAVE_JAVAH], [test "x$JAVAH" != "x"])
 AM_CONDITIONAL([HAVE_PERF_EVENT], [test "x$ac_cv_header_linux_perf_event_h" = "xyes"])
+AM_CONDITIONAL([HAVE_PYTHON_312_OR_GREATER], [test "x$have_python_312_or_greater" = "xyes"])
 
 
 ##                                             ##
index 64800e6fafd53587eadc5e94f6dbd8dba7858674..d53e21da6f9957cb5deece0d2034ac32218fd075 100644 (file)
@@ -14,6 +14,15 @@ GENERATED_BINDINGS_DEPS = \
        lttngust/version.py \
        setup.py
 
+# 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
+
 all-local: build-python-bindings.stamp
 
 copy-static-deps.stamp: $(addprefix $(srcdir)/, $(STATIC_BINDINGS_DEPS))
@@ -36,7 +45,7 @@ install-exec-local: build-python-bindings.stamp
        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.026671 seconds and 4 git commands to generate.