[pygobject] setup.py: Make lookup of Python valgrind suppression files work on Fedora and in a venv



commit b77f9fb8be61698814000aefff3c1f29609bf6c8
Author: Christoph Reiter <reiter christoph gmail com>
Date:   Mon Apr 9 19:10:33 2018 +0200

    setup.py: Make lookup of Python valgrind suppression files work on Fedora and in a venv
    
    They are in /usr/share/doc/python(2-devel|3-devel|\d\d) on Fedora.
    Also search for the suppression files in more prefixes in case we are in a virtualenv
    or in case the Python interpreter isn't installed.
    
    Also removes the .supp files included in the test suite as they are no longer used.

 MANIFEST.in        |   2 +-
 setup.py           |  64 ++++++--
 tests/python2.supp | 387 -------------------------------------------
 tests/python3.supp | 471 -----------------------------------------------------
 4 files changed, 53 insertions(+), 871 deletions(-)
---
diff --git a/MANIFEST.in b/MANIFEST.in
index fab933a1..10e97b6c 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -9,6 +9,6 @@ include README.rst
 include .gitlab-ci.yml
 recursive-include examples *.py *.png *.css *.ui *.gif *.gresource *.jpg *.xml
 recursive-include gi *.h
-recursive-include tests *.py *.c *.h *.xml *.supp
+recursive-include tests *.py *.c *.h *.xml
 recursive-include docs *.rst *.svg LICENSE *.ico *.png *.css *.py *.dia Makefile
 recursive-include .gitlab-ci *.sh *.rst *.py Dockerfile*
diff --git a/setup.py b/setup.py
index 658597d7..74b5d5f3 100755
--- a/setup.py
+++ b/setup.py
@@ -602,6 +602,58 @@ class build_tests(Command):
         cmd.run()
 
 
+def get_suppression_files_for_prefix(prefix):
+    """Returns a list of valgrind suppression files for a given prefix"""
+
+    # Most specific first (/usr/share/doc is Fedora, /usr/lib is Debian)
+    # Take the first one found
+    major = str(sys.version_info[0])
+    minor = str(sys.version_info[1])
+    pyfiles = []
+    pyfiles.append(
+        os.path.join(
+            prefix, "share", "doc", "python%s%s" % (major, minor),
+            "valgrind-python.supp"))
+    pyfiles.append(
+        os.path.join(prefix, "lib", "valgrind", "python%s.supp" % major))
+    pyfiles.append(
+        os.path.join(
+            prefix, "share", "doc", "python%s-devel" % major,
+            "valgrind-python.supp"))
+    pyfiles.append(os.path.join(prefix, "lib", "valgrind", "python.supp"))
+
+    files = []
+    for f in pyfiles:
+        if os.path.isfile(f):
+            files.append(f)
+            break
+
+    files.append(os.path.join(
+        prefix, "share", "glib-2.0", "valgrind", "glib.supp"))
+    return [f for f in files if os.path.isfile(f)]
+
+
+def get_real_prefix():
+    """Returns the base Python prefix, even in a virtualenv/venv"""
+
+    return getattr(sys, "base_prefix", getattr(sys, "real_prefix", sys.prefix))
+
+
+def get_suppression_files():
+    """Returns a list of valgrind suppression files"""
+
+    prefixes = [
+        sys.prefix,
+        get_real_prefix(),
+        pkg_config_parse("--variable=prefix", "glib-2.0")[0],
+    ]
+
+    files = []
+    for prefix in prefixes:
+        files.extend(get_suppression_files_for_prefix(prefix))
+    return sorted(set(files))
+
+
 class test(Command):
     user_options = [
         ("valgrind", None, "run tests under valgrind"),
@@ -638,18 +690,6 @@ class test(Command):
         env["MALLOC_CHECK_"] = "3"
         env["G_SLICE"] = "debug-blocks"
 
-        def get_suppression_files():
-            files = []
-            if sys.version_info[0] == 2:
-                files.append(os.path.join(
-                    sys.prefix, "lib", "valgrind", "python.supp"))
-            else:
-                files.append(os.path.join(
-                    sys.prefix, "lib", "valgrind", "python3.supp"))
-            files.append(os.path.join(
-                sys.prefix, "share", "glib-2.0", "valgrind", "glib.supp"))
-            return [f for f in files if os.path.isfile(f)]
-
         pre_args = []
 
         if self.valgrind:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]