Skip to content

Commit b7b1358

Browse files
committed
Add Cantera 3.0 dependency check to utilities.py
1 parent 94e7c10 commit b7b1358

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

utilities.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def check_dependencies():
4848
print('{0:<15}{1:<15}{2}'.format('Package', 'Version', 'Location'))
4949

5050
missing = {
51+
'cantera': _check_cantera(),
5152
'openbabel': _check_openbabel(),
5253
'pydqed': _check_pydqed(),
5354
'pyrdl': _check_pyrdl(),
@@ -57,9 +58,18 @@ def check_dependencies():
5758

5859
if any(missing.values()):
5960
print("""
61+
╔═══════════════════════════════════════════════════════════════════════════╗
62+
║ ! ! ║
63+
║ ! ! WARNING: MISSING DEPENDENCIES ! ! ║
64+
║ !!!!! !!!!! ║
65+
╚═══════════════════════════════════════════════════════════════════════════╝
66+
6067
There are missing dependencies as listed above. Please install them before proceeding.
6168
6269
conda env update -f environment.yml
70+
71+
Or (often better) make a new conda environment and restart the installation instructions.
72+
See https://reactionmechanismgenerator.github.io/RMG-Py/users/rmg/installation
6373
6474
Be sure to activate your conda environment (rmg_env by default) before installing or updating.
6575
""")
@@ -68,6 +78,35 @@ def check_dependencies():
6878
Everything was found :)
6979
""")
7080

81+
def _check_cantera():
82+
"""Check for Cantera with version >= 3.0"""
83+
missing = False
84+
85+
try:
86+
import cantera
87+
except ImportError:
88+
print('{0:<30}{1}'.format('Cantera',
89+
'Not found. Necessary for output file writing and utilities.'))
90+
missing = True
91+
else:
92+
version = cantera.__version__
93+
location = cantera.__file__
94+
95+
# Parse version string to compare (e.g., "3.0.0" -> (3, 0))
96+
try:
97+
version_tuple = tuple(int(x) for x in version.split('.')[:2])
98+
except (ValueError, IndexError):
99+
version_tuple = (0, 0)
100+
101+
if version_tuple < (3, 0):
102+
print('{0:<15}{1:<15}{2}'.format('Cantera', version, location))
103+
print(' !!! Cantera version must be 3.0 or later.')
104+
missing = True
105+
else:
106+
print('{0:<15}{1:<15}{2}'.format('Cantera', version, location))
107+
108+
return missing
109+
71110

72111
def _check_openbabel():
73112
"""Check for OpenBabel"""

0 commit comments

Comments
 (0)