|
1 | 1 | """RunConfig class handles the actual workflow logic.""" |
2 | | -__all__ = ('RunConfig',) |
| 2 | +__all__ = ("RunConfig",) |
3 | 3 |
|
4 | 4 | import collections.abc |
5 | 5 | import dataclasses |
| 6 | +import functools |
6 | 7 | import logging |
7 | 8 | import os |
8 | 9 | import pathlib |
|
25 | 26 | _Path = Union[str, pathlib.Path] |
26 | 27 |
|
27 | 28 |
|
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) |
30 | 36 |
|
31 | 37 |
|
32 | 38 | try: |
33 | 39 | # noinspection PyPep8Naming,PyUnresolvedReferences |
34 | 40 | 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: |
38 | 42 | try: |
39 | 43 | # noinspection PyPep8Naming |
40 | 44 | 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 |
46 | 70 |
|
47 | 71 |
|
48 | 72 | def check_consistency(*, data: PairDataCollection, state: RunData): |
|
0 commit comments