Skip to content

Commit 9c2ac90

Browse files
authored
Merge pull request #56 from kassonlab/brer-md-55
Better reporting for import errors.
2 parents 6124042 + 4df6ebb commit 9c2ac90

File tree

1 file changed

+35
-11
lines changed

1 file changed

+35
-11
lines changed

src/brer/run_config.py

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
"""RunConfig class handles the actual workflow logic."""
2-
__all__ = ('RunConfig',)
2+
__all__ = ("RunConfig",)
33

44
import collections.abc
55
import dataclasses
6+
import functools
67
import logging
78
import os
89
import pathlib
@@ -25,24 +26,47 @@
2526
_Path = Union[str, pathlib.Path]
2627

2728

28-
def _gmxapi_missing(*args, **kwargs):
29-
raise RuntimeError('brer requires gmxapi. See https://github.com/kassonlab/brer_md#requirements')
29+
def _gmxapi_missing(*args, exc_info=None, **kwargs):
30+
message = (
31+
"brer requires gmxapi. See https://github.com/kassonlab/brer_md#requirements"
32+
)
33+
if exc_info:
34+
message += f" {exc_info}"
35+
raise RuntimeError(message)
3036

3137

3238
try:
3339
# noinspection PyPep8Naming,PyUnresolvedReferences
3440
from gmxapi.simulation.context import Context as _context
35-
# noinspection PyUnresolvedReferences
36-
from gmxapi.simulation.workflow import WorkElement, from_tpr
37-
except (ImportError, ModuleNotFoundError):
41+
except (ImportError, ModuleNotFoundError) as e:
3842
try:
3943
# noinspection PyPep8Naming
4044
from gmx.context import Context as _context
41-
from gmx.workflow import from_tpr, WorkElement
42-
except (ImportError, ModuleNotFoundError):
43-
_context = _gmxapi_missing
44-
from_tpr = _gmxapi_missing
45-
WorkElement = _gmxapi_missing
45+
except (ImportError, ModuleNotFoundError) as e:
46+
missing = functools.partial(_gmxapi_missing, exception=str(e))
47+
_context = missing
48+
49+
try:
50+
# noinspection PyUnresolvedReferences
51+
from gmxapi.simulation.workflow import from_tpr
52+
except (ImportError, ModuleNotFoundError) as e:
53+
try:
54+
# noinspection PyPep8Naming
55+
from gmx.workflow import from_tpr
56+
except (ImportError, ModuleNotFoundError) as e:
57+
missing = functools.partial(_gmxapi_missing, exception=str(e))
58+
from_tpr = missing
59+
60+
try:
61+
# noinspection PyUnresolvedReferences
62+
from gmxapi.simulation.workflow import WorkElement
63+
except (ImportError, ModuleNotFoundError) as e:
64+
try:
65+
# noinspection PyPep8Naming
66+
from gmx.workflow import WorkElement
67+
except (ImportError, ModuleNotFoundError) as e:
68+
missing = functools.partial(_gmxapi_missing, exception=str(e))
69+
WorkElement = missing
4670

4771

4872
def check_consistency(*, data: PairDataCollection, state: RunData):

0 commit comments

Comments
 (0)