[pypy-commit] cffi default: Reduce number of exceptions

vyskocilm pypy.commits at gmail.com
Thu Jan 31 04:27:05 EST 2019


Author: Michal Vyskocil <michal.vyskocil at gmail.com>
Branch: 
Changeset: r3203:703ab36069d0
Date: 2019-01-11 22:38 +0100
http://bitbucket.org/cffi/cffi/changeset/703ab36069d0/

Log:	Reduce number of exceptions

diff --git a/cffi/error.py b/cffi/error.py
--- a/cffi/error.py
+++ b/cffi/error.py
@@ -22,14 +22,9 @@
     cdef, but no verification has been done
     """
 
-class PkgConfigNotFound(Exception):
-    """ An error raised when pkgconfig was not found"""
+class PkgConfigError(Exception):
+    """ An error raised for all pkg-config related errors
+    except version mismatch"""
 
-class PkgConfigError(Exception):
-    """ Generic super class for pkg-config related errors"""
-
-class PkgConfigModuleNotFound(PkgConfigError):
-    """ Module or it's pkg-config file was not found on a system"""
-
-class PkgConfigModuleVersionNotFound(PkgConfigError):
-    """ Requested version of module was not found"""
+class PkgConfigModuleVersionNotFound(Exception):
+    """ An error raised when requested version was not found"""
diff --git a/cffi/pkgconfig.py b/cffi/pkgconfig.py
--- a/cffi/pkgconfig.py
+++ b/cffi/pkgconfig.py
@@ -3,7 +3,6 @@
 import sys
 import re
 
-from .error import PkgConfigNotFound
 from .error import PkgConfigModuleVersionNotFound
 from .error import PkgConfigError
 
@@ -34,14 +33,12 @@
     except FileNotFoundError:
         pass
     if pc is None:
-        raise PkgConfigNotFound("pkg-config was not found on this system")
+        raise PkgConfigError("pkg-config was not found on this system")
     
     bout, berr = pc.communicate()
     if berr is not None:
         err = berr.decode(sys.getfilesystemencoding())
-        if re.search("Package .* was not found in the pkg-config search path", err, re.MULTILINE) is not None:
-            raise PkgConfigNotFoundError(err)
-        elif re.search("Requested '.*' but version of ", err, re.MULTILINE):
+        if re.search("Requested '.*' but version of ", err, re.MULTILINE) is not None:
             raise PkgConfigModuleVersionNotFound(err)
         else:
             PkgConfigError(err)
@@ -61,8 +58,6 @@
     libbar.
 
     Raises
-    * PkgConfigNotFound if pkg-config is not installed
-    * PkgConfigModuleNotFoun if requested module not found
     * PkgConfigModuleVersionNotFound if requested version does not match
     * PkgConfigError for all other errors
     """


More information about the pypy-commit mailing list