[pygobject] setup.py: cache pkg-config calls



commit 618ccf06ad75bc481dec59b7da86a550571968c5
Author: Christoph Reiter <reiter christoph gmail com>
Date:   Wed Feb 14 01:34:02 2018 +0100

    setup.py: cache pkg-config calls
    
    This saves 300ms for a noop build_tests command

 setup.py | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)
---
diff --git a/setup.py b/setup.py
index ac65294e..8635dbca 100755
--- a/setup.py
+++ b/setup.py
@@ -102,18 +102,23 @@ def parse_pkg_info(conf_dir):
     return message
 
 
-def _run_pkg_config(args):
-    command = ["pkg-config"] + args
-
-    try:
-        return subprocess.check_output(command)
-    except OSError as e:
-        if e.errno == errno.ENOENT:
-            raise SystemExit(
-                "%r not found.\nArguments: %r" % (command[0], command))
-        raise SystemExit(e)
-    except subprocess.CalledProcessError as e:
-        raise SystemExit(e)
+def _run_pkg_config(args, _cache={}):
+    command = tuple(["pkg-config"] + args)
+
+    if command not in _cache:
+        try:
+            result = subprocess.check_output(command)
+        except OSError as e:
+            if e.errno == errno.ENOENT:
+                raise SystemExit(
+                    "%r not found.\nArguments: %r" % (command[0], command))
+            raise SystemExit(e)
+        except subprocess.CalledProcessError as e:
+            raise SystemExit(e)
+        else:
+            _cache[command] = result
+
+    return _cache[command]
 
 
 def pkg_config_version_check(pkg, version):


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