[lttng-dev] [PATCH lttng-ust] Fix: (un)install targets of Python agent

Francis Deslauriers francis.deslauriers at efficios.com
Tue Feb 28 16:07:50 UTC 2017


This Makefile was using Distutils' setup.py to install the Python agent
but was using the Autoconf's $pkgpythondir variable for the uninstall
process. The two folders can be different on some distributions which
made the uninstall attempting to delete a non-existant folder and
effectively not uninstalling.

We now save the paths of the installed files and use this information
during the uninstallation.

Also, we print a warning if the install directory is not included in the
PYTHONPATH variable.

Signed-off-by: Francis Deslauriers <francis.deslauriers at efficios.com>
---
 .gitignore                  |  1 +
 python-lttngust/Makefile.am | 22 ++++++++--------
 python-lttngust/setup.py.in | 62 +++++++++++++++++++++++++++++++++------------
 3 files changed, 59 insertions(+), 26 deletions(-)

diff --git a/.gitignore b/.gitignore
index 0d322b1..fe43230 100644
--- a/.gitignore
+++ b/.gitignore
@@ -86,3 +86,4 @@ python-lttngust/lttngust/__init__.py
 python-lttngust/**/*.pyc
 python-lttngust/build
 python-lttngust/setup.py
+python-lttngust/installed_files.txt
diff --git a/python-lttngust/Makefile.am b/python-lttngust/Makefile.am
index cc28989..d7c2071 100644
--- a/python-lttngust/Makefile.am
+++ b/python-lttngust/Makefile.am
@@ -1,25 +1,27 @@
 # Use setup.py for the installation instead of Autoconf.
 # This ease the installation process and assure a *pythonic*
 # installation.
-agent_path=lttngust
+INSTALLED_FILES=$(builddir)/installed_files.txt
 all-local:
 	$(PYTHON) setup.py build --verbose
 
+# This target installs the Python package and saves the path of all the
+# installed files in the INSTALLED_FILES text file to be used during this
+# uninstallation
 install-exec-local:
-	@opts="--prefix=$(prefix) --verbose --no-compile $(DISTSETUPOPTS)"; \
+	@opts="--prefix=$(prefix) --verbose --record $(INSTALLED_FILES) --no-compile $(DISTSETUPOPTS)"; \
 	if [ "$(DESTDIR)" != "" ]; then \
 		opts="$$opts --root=$(DESTDIR)"; \
 	fi; \
 	$(PYTHON) setup.py install $$opts;
 
 clean-local:
-	rm -rf build
+	rm -rf $(builddir)/build
 
+# Distutils' setup.py does not include an uninstall target, we thus need to do
+# it manually. We use the INSTALLED_FILES file produced during the install to
+# clean up the install folder and delete the folder it self.
 uninstall-local:
-	rm -rf $(DESTDIR)$(pkgpythondir)
-
-EXTRA_DIST=$(agent_path)
-
-# Remove automake generated file before dist
-dist-hook:
-	rm -rf $(distdir)/$(agent_path)/__init__.py
+	cat $(INSTALLED_FILES) | xargs rm -rf
+	cat $(INSTALLED_FILES) | $(GREP) "__init__.py" | xargs dirname | xargs rmdir
+	rm -f $(INSTALLED_FILES)
diff --git a/python-lttngust/setup.py.in b/python-lttngust/setup.py.in
index 370fd61..89cd5f0 100644
--- a/python-lttngust/setup.py.in
+++ b/python-lttngust/setup.py.in
@@ -15,22 +15,52 @@
 # along with this library; if not, write to the Free Software Foundation, Inc.,
 # 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
 
+import sys
+
 from distutils.core import setup, Extension
 
+PY_PATH_WARN_MSG = """
+-------------------------------------WARNING------------------------------------
+The install directory used:\n ({})\nis not included in your PYTHONPATH.
+
+To add this directory to your Python search path permanently you can add the
+following command to your .bashrc/.zshrc:
+    export PYTHONPATH="${{PYTHONPATH}}:{}"
+--------------------------------------------------------------------------------
+"""
+
+def main():
+    dist = setup(name='lttngust',
+            version='@PACKAGE_VERSION@',
+            description='LTTng-UST Python agent',
+            packages=['lttngust'],
+            package_dir={'lttngust': 'lttngust'},
+            options={'build': {'build_base': 'build'}},
+            url='http://lttng.org',
+            license='LGPL-2.1',
+            classifiers=[
+                'Development Status :: 5 - Production/Stable',
+                'Intended Audience :: Developers',
+                'License :: OSI Approved :: GNU Lesser General Public License v2 (LGPLv2)',
+                'Programming Language :: Python :: 2.7',
+                'Programming Language :: Python :: 3'
+                'Topic :: System :: Logging',
+                ])
+
+# After the installation, we check that the install directory is included in
+# the Python search path and we print a warning message when it's not. We need
+# to do this because Python search path differs depending on the distro and
+# some distros don't include any `/usr/local/` (the default install prefix) in
+# the search path. This is also useful for out-of-tree installs and tests. It's
+# only relevant to make this check on the `install` command.
+
+    if 'install' in dist.command_obj:
+        install_dir = dist.command_obj['install'].install_libbase
+        if install_dir not in sys.path:
+            # We can't consider this an error because if affects every
+            # distro differently. We only warn the user that some
+            # extra configuration is needed to use the agent
+            print(PY_PATH_WARN_MSG.format(install_dir, install_dir))
 
-setup(name='lttngust',
-      version='@PACKAGE_VERSION@',
-      description='LTTng-UST Python agent',
-      packages=['lttngust'],
-      package_dir={'lttngust': 'lttngust'},
-      options={'build': {'build_base': 'build'}},
-      url='http://lttng.org',
-      license='LGPL-2.1',
-      classifiers=[
-          'Development Status :: 5 - Production/Stable',
-          'Intended Audience :: Developers',
-          'License :: OSI Approved :: GNU Lesser General Public License v2 (LGPLv2)',
-          'Programming Language :: Python :: 2.7',
-          'Programming Language :: Python :: 3'
-          'Topic :: System :: Logging',
-      ])
+if __name__ == '__main__':
+    main()
-- 
2.7.4



More information about the lttng-dev mailing list