From: Michael Jeanson Date: Thu, 15 Jun 2023 17:29:54 +0000 (-0400) Subject: fix: python bindings: use stdlib distutils when setuptools is installed X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=cb50b38fd0c51b3b0c650b2437cbba572321d53a fix: python bindings: 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 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 Reviewed-on: https://review.lttng.org/c/babeltrace/+/10371 Tested-by: jenkins Reviewed-by: Philippe Proulx --- diff --git a/.gitignore b/.gitignore index f6168620..f1ae13d9 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/configure.ac b/configure.ac index f81e7334..95483337 100644 --- a/configure.ac +++ b/configure.ac @@ -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.]) diff --git a/src/bindings/python/bt2/Makefile.am b/src/bindings/python/bt2/Makefile.am index 6b31a743..fee33134 100644 --- a/src/bindings/python/bt2/Makefile.am +++ b/src/bindings/python/bt2/Makefile.am @@ -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