From d9bf54d4556d8df769e904427ac1a17087855b78 Mon Sep 17 00:00:00 2001 From: Michael Jeanson Date: Wed, 14 Jun 2023 16:55:28 -0400 Subject: [PATCH] fix: python agent: use stdlib distutils when setuptools is installed 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 Signed-off-by: Mathieu Desnoyers --- configure.ac | 3 +++ python-lttngust/Makefile.am | 11 ++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index c6623817..1ea435fc 100644 --- a/configure.ac +++ b/configure.ac @@ -424,6 +424,7 @@ AS_IF([test "x$python_agent" = "xyes"], [ AM_PATH_PYTHON([2.7]) 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]) @@ -434,6 +435,8 @@ AS_IF([test "x$python_agent" = "xyes"], [ ]) ]) +AM_CONDITIONAL([HAVE_PYTHON_312_OR_GREATER], [test "x$have_python_312_or_greater" = "xyes"]) + # sdt.h integration AC_ARG_WITH([sdt], [ AS_HELP_STRING([--with-sdt], [provide SystemTap integration via sdt.h [default=no]]) diff --git a/python-lttngust/Makefile.am b/python-lttngust/Makefile.am index b5154c0a..c3280b70 100644 --- a/python-lttngust/Makefile.am +++ b/python-lttngust/Makefile.am @@ -2,6 +2,15 @@ GENERATED_BINDINGS_DEPS = \ lttngust/__init__.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 + # Use setup.py for the installation instead of Autoconf. # This ease the installation process and assure a *pythonic* # installation. @@ -13,7 +22,7 @@ install-exec-local: if [ "$(DESTDIR)" != "" ]; then \ opts="$$opts --root=$(DESTDIR)"; \ fi; \ - $(PYTHON) setup.py install $$opts; + $(PYTHON) setup.py install $(PY_INSTALL_OPTS) $$opts; clean-local: rm -rf $(builddir)/build -- 2.34.1