|
2 | 2 | """Expose features from _ArviZverse_ refactored packages together in the ``arviz`` namespace.""" |
3 | 3 |
|
4 | 4 | import logging |
| 5 | +import re |
5 | 6 |
|
6 | 7 | _log = logging.getLogger(__name__) |
7 | 8 |
|
|
16 | 17 | "exposing its functions as part of the `arviz` namespace" |
17 | 18 | ) |
18 | 19 | _log.info(_status) |
19 | | -except ModuleNotFoundError: |
20 | | - _status = "arviz_base not installed" |
21 | | - _log.exception(_status) |
22 | | -except ImportError: |
23 | | - _status = "Unable to import arviz_base" |
24 | | - _log.exception(_status) |
| 20 | +except ModuleNotFoundError as err: |
| 21 | + raise ImportError("arviz's dependency arviz_base is not installed", name="arviz") from err |
25 | 22 |
|
26 | 23 | info += _status + "\n" |
27 | 24 |
|
|
33 | 30 | import arviz_base as base |
34 | 31 | import arviz_stats as stats |
35 | 32 |
|
| 33 | + # TODO: remove patch. 0.7 version of arviz-stats didn't expose the __version__ attribute |
36 | 34 | _status = ( |
37 | | - f"arviz_stats {getattr(stats, '__version__', '0.0')} available, " |
| 35 | + f"arviz_stats {getattr(stats, '__version__', '0.7.0')} available, " |
38 | 36 | "exposing its functions as part of the `arviz` namespace" |
39 | 37 | ) |
40 | 38 | _log.info(_status) |
41 | | -except ModuleNotFoundError: |
42 | | - _status = "arviz_stats not installed" |
43 | | - _log.exception(_status) |
44 | | -except ImportError: |
45 | | - _status = "Unable to import arviz_stats" |
46 | | - _log.exception(_status) |
| 39 | +except ModuleNotFoundError as err: |
| 40 | + raise ImportError("arviz's dependency arviz_stats is not installed", name="arviz") from err |
| 41 | + |
47 | 42 | info += _status + "\n" |
48 | 43 |
|
49 | 44 | try: |
|
55 | 50 | "exposing its functions as part of the `arviz` namespace" |
56 | 51 | ) |
57 | 52 | _log.info(_status) |
58 | | -except ModuleNotFoundError: |
59 | | - _status = "arviz_plots not installed" |
60 | | - _log.exception(_status) |
61 | | -except ImportError: |
62 | | - _status = "Unable to import arviz_plots" |
63 | | - _log.exception(_status) |
| 53 | +except ModuleNotFoundError as err: |
| 54 | + raise ImportError("arviz's dependency arviz_plots is not installed", name="arviz") from err |
64 | 55 |
|
65 | 56 | info += _status |
66 | 57 |
|
|
69 | 60 |
|
70 | 61 | info = f"Status information for ArviZ {__version__}\n\n{info}" |
71 | 62 |
|
| 63 | +pat = re.compile(r"arviz_(base|stats|plots)\s([0-9]+\.[0-9]+)") |
| 64 | +matches = pat.findall(info) |
| 65 | +if any(matches[0][1] != match[1] for match in matches[1:]): |
| 66 | + raise ImportError( |
| 67 | + "Versions of arviz-xyz packages don't match to the minor version. " |
| 68 | + f"The versions found are: {matches}" |
| 69 | + ) |
| 70 | + |
72 | 71 | # clean namespace |
73 | | -del logging, _status |
| 72 | +del logging, matches, pat, re, _status |
0 commit comments