Author: Michal Vyskocil <[email protected]>
Branch: 
Changeset: r3199:58d9217d4315
Date: 2019-01-09 08:39 +0100
http://bitbucket.org/cffi/cffi/changeset/58d9217d4315/

Log:    Exception based flow

        Now the with non pkg-config backup would be ``` module_name =
        "_czmq" source = "#include <czmq.h>" try: print(f"### pkg-config
        path") ffibuilder.set_source( module_name, source,
        pkgconfig=["libczmq"] ) except Exception as e: print(f"Exception e:
        {e}") ffibuilder.set_source( module_name, source, libraries=["czmq"]
        ) ```

diff --git a/cffi/api.py b/cffi/api.py
--- a/cffi/api.py
+++ b/cffi/api.py
@@ -641,10 +641,7 @@
         if os.sep in module_name or (os.altsep and os.altsep in module_name):
             raise ValueError("'module_name' must not contain '/': use a dotted 
"
                              "name to make a 'package.module' location")
-        if "pkgconfig" in kwds and pkgconfig.is_installed():
-            if "libraries" in kwds:
-                del kwds["libraries"]  # real library names are going to be
-                                        # provided by pkg-config
+        if "pkgconfig" in kwds:
             pkgconfig.merge_flags(kwds, pkgconfig.flags(kwds["pkgconfig"]))
             del kwds["pkgconfig"]
         self._assigned_source = (str(module_name), source,
diff --git a/cffi/pkgconfig.py b/cffi/pkgconfig.py
--- a/cffi/pkgconfig.py
+++ b/cffi/pkgconfig.py
@@ -2,14 +2,6 @@
 import subprocess
 import sys
 
-def is_installed():
-    """Check if pkg-config is installed or not"""
-    try:
-        subprocess.check_output(["pkg-config", "--version"])
-        return True
-    except subprocess.CalledProcessError:
-        return False
-
 
 def merge_flags(cfg1, cfg2):
     """Merge values from cffi config flags cfg2 to cf1
@@ -39,14 +31,19 @@
 
     Usage
         ...
-        ffibuilder.set_source("_foo", libraries = ["foo", "bar"], pkgconfig = 
["libfoo", "libbar"])
+        ffibuilder.set_source("_foo", pkgconfig = ["libfoo", "libbar"])
 
-    If `pkg-config` is installed on build machine, then arguments
-    `include_dirs`, `library_dirs`, `libraries`, `define_macros`,
-    `extra_compile_args` and `extra_link_args` are extended with an output of
-    `pkg-config` for `libfoo` and `libbar`.
+    If pkg-config is installed on build machine, then arguments include_dirs,
+    library_dirs, libraries, define_macros, extra_compile_args and
+    extra_link_args are extended with an output of pkg-config for libfoo and
+    libbar.
+
+    Raise `FileNotFoundError` if pkg-config is not installed or
+    `subprocess.CalledProcessError` if pkg-config fails.
     """
 
+    subprocess.check_output(["pkg-config", "--version"])
+
     # make API great again!
     if isinstance(libs, (str, bytes)):
         libs = (libs, )
diff --git a/testing/cffi1/test_pkgconfig.py b/testing/cffi1/test_pkgconfig.py
--- a/testing/cffi1/test_pkgconfig.py
+++ b/testing/cffi1/test_pkgconfig.py
@@ -32,8 +32,8 @@
 
 
 def test_pkgconfig():
-    kwargs = pkgconfig.flags("python-3.6")
-    assert kwargs == {
+    flags = pkgconfig.flags("python-3.6")
+    assert flags == {
         'include_dirs': [u'/usr/include/python3.6m'],
         'library_dirs': [u'/usr/lib64'],
         'libraries': [u'python3.6'],
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to