Skip to content

Commit 730edd3

Browse files
committed
make pycddlib optional
1 parent 87753d1 commit 730edd3

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

burnman/classes/polytope.py

+17-3
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,28 @@
1111
from scipy.spatial import Delaunay
1212
from scipy.special import comb
1313
from copy import copy
14-
import cdd as cdd_float
1514

1615
from .material import cached_property
1716

1817
from ..utils.math import independent_row_indices
1918

2019

20+
# Try to import pycddlib.
21+
# First, try separating the imports into float and
22+
# fractional, then fall back to only using the float
23+
# representation, and finally don't import anything
24+
# (limiting functionality)
2125
try:
26+
cdd_float = importlib.import_module("cdd")
2227
cdd_fraction = importlib.import_module("cdd.gmp")
2328
cdd_gmp_loaded = True
2429
except ImportError:
25-
cdd_fraction = importlib.import_module("cdd")
26-
cdd_gmp_loaded = False
30+
try:
31+
cdd_float = importlib.import_module("cdd")
32+
cdd_fraction = importlib.import_module("cdd")
33+
cdd_gmp_loaded = False
34+
except ImportError:
35+
cdd_float = None
2736

2837

2938
class SimplexGrid(object):
@@ -140,6 +149,11 @@ def __init__(
140149
dependent endmembers are defined.
141150
:type independent_endmember_occupancies: numpy.array (2D) or None
142151
"""
152+
if cdd_float is None:
153+
raise ImportError(
154+
"You need to install pycddlib to create a MaterialPolytope object."
155+
)
156+
143157
if equalities.dtype != inequalities.dtype:
144158
raise Exception(
145159
f"The equalities and inequalities arrays should have the same type ({equalities.dtype} != {inequalities.dtype})."

0 commit comments

Comments
 (0)