prevent cython.compiled raise AttributeError if cython not properly installed
It's possible sometimes that 'import cython' does not fail but then 'cython.compiled' raises AttributeError. It actually happened in our internal production environment... Similar issue to https://github.com/pydantic/pydantic/pull/573 and https://github.com/ipython/ipython/issues/13294
This commit is contained in:
parent
e7c6d2aa8b
commit
0df4997661
@ -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)
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user