diff --git a/Lib/fontTools/cu2qu/cu2qu.py b/Lib/fontTools/cu2qu/cu2qu.py index f99053b26..0aaaf653b 100644 --- a/Lib/fontTools/cu2qu/cu2qu.py +++ b/Lib/fontTools/cu2qu/cu2qu.py @@ -17,10 +17,14 @@ try: import cython -except ImportError: + + COMPILED = cython.compiled +except (AttributeError, ImportError): # if cython not installed, use mock module with no-op decorators and types from fontTools.misc import cython + COMPILED = False + import math from .errors import Error as Cu2QuError, ApproxNotFoundError @@ -33,14 +37,6 @@ MAX_N = 100 NAN = float("NaN") -if cython.compiled: - # Yep, I'm compiled. - COMPILED = True -else: - # Just a lowly interpreted script. - COMPILED = False - - @cython.cfunc @cython.inline @cython.returns(cython.double) diff --git a/Lib/fontTools/misc/bezierTools.py b/Lib/fontTools/misc/bezierTools.py index bdc3005c5..141279255 100644 --- a/Lib/fontTools/misc/bezierTools.py +++ b/Lib/fontTools/misc/bezierTools.py @@ -9,10 +9,14 @@ from collections import namedtuple try: import cython -except ImportError: + + COMPILED = cython.compiled +except (AttributeError, ImportError): # if cython not installed, use mock module with no-op decorators and types from fontTools.misc import cython + COMPILED = False + Intersection = namedtuple("Intersection", ["pt", "t1", "t2"]) @@ -48,13 +52,6 @@ __all__ = [ "segmentSegmentIntersections", ] -if cython.compiled: - # Yep, I'm compiled. - COMPILED = True -else: - # Just a lowly interpreted script. - COMPILED = False - def calcCubicArcLength(pt1, pt2, pt3, pt4, tolerance=0.005): """Calculates the arc length for a cubic Bezier segment. diff --git a/Lib/fontTools/misc/symfont.py b/Lib/fontTools/misc/symfont.py index c9e0a10c0..0bd69a386 100644 --- a/Lib/fontTools/misc/symfont.py +++ b/Lib/fontTools/misc/symfont.py @@ -123,15 +123,12 @@ def printGreenPen(penName, funcs, file=sys.stdout, docstring=None): """from fontTools.pens.basePen import BasePen, OpenContourError try: import cython -except ImportError: + + COMPILED = cython.compiled +except (AttributeError, ImportError): # if cython not installed, use mock module with no-op decorators and types from fontTools.misc import cython -if cython.compiled: - # Yep, I'm compiled. - COMPILED = True -else: - # Just a lowly interpreted script. COMPILED = False diff --git a/Lib/fontTools/pens/momentsPen.py b/Lib/fontTools/pens/momentsPen.py index df17032dd..dab0d10e2 100644 --- a/Lib/fontTools/pens/momentsPen.py +++ b/Lib/fontTools/pens/momentsPen.py @@ -2,15 +2,12 @@ from fontTools.pens.basePen import BasePen, OpenContourError try: import cython -except ImportError: + + COMPILED = cython.compiled +except (AttributeError, ImportError): # if cython not installed, use mock module with no-op decorators and types from fontTools.misc import cython -if cython.compiled: - # Yep, I'm compiled. - COMPILED = True -else: - # Just a lowly interpreted script. COMPILED = False diff --git a/Lib/fontTools/qu2cu/qu2cu.py b/Lib/fontTools/qu2cu/qu2cu.py index 141b00bd6..23f07c76c 100644 --- a/Lib/fontTools/qu2cu/qu2cu.py +++ b/Lib/fontTools/qu2cu/qu2cu.py @@ -18,10 +18,14 @@ try: import cython -except ImportError: + + COMPILED = cython.compiled +except (AttributeError, ImportError): # if cython not installed, use mock module with no-op decorators and types from fontTools.misc import cython + COMPILED = False + from fontTools.misc.bezierTools import splitCubicAtTC from collections import namedtuple import math @@ -35,14 +39,6 @@ from typing import ( __all__ = ["quadratic_to_curves"] -if cython.compiled: - # Yep, I'm compiled. - COMPILED = True -else: - # Just a lowly interpreted script. - COMPILED = False - - # Copied from cu2qu @cython.cfunc @cython.returns(cython.int) diff --git a/Lib/fontTools/varLib/iup.py b/Lib/fontTools/varLib/iup.py index 27f0ee110..84077eb1e 100644 --- a/Lib/fontTools/varLib/iup.py +++ b/Lib/fontTools/varLib/iup.py @@ -7,15 +7,12 @@ from numbers import Integral, Real try: import cython -except ImportError: + + COMPILED = cython.compiled +except (AttributeError, ImportError): # if cython not installed, use mock module with no-op decorators and types from fontTools.misc import cython -if cython.compiled: - # Yep, I'm compiled. - COMPILED = True -else: - # Just a lowly interpreted script. COMPILED = False