|
102 | 102 | import tempfile
|
103 | 103 | import warnings
|
104 | 104 |
|
| 105 | +import numpy |
| 106 | + |
105 | 107 | # cbook must import matplotlib only within function
|
106 | 108 | # definitions, so it is safe to import from it here.
|
107 |
| -from . import _api, cbook, docstring, rcsetup |
| 109 | +from . import _api, _version, cbook, docstring, rcsetup |
108 | 110 | from matplotlib.cbook import MatplotlibDeprecationWarning, sanitize_sequence
|
109 | 111 | from matplotlib.cbook import mplDeprecation # deprecated
|
110 | 112 | from matplotlib.rcsetup import validate_backend, cycler
|
111 | 113 |
|
112 |
| -import numpy |
113 |
| - |
114 |
| -# Get the version from the _version.py versioneer file. For a git checkout, |
115 |
| -# this is computed based on the number of commits since the last tag. |
116 |
| -from ._version import get_versions |
117 |
| -__version__ = str(get_versions()['version']) |
118 |
| -del get_versions |
119 | 114 |
|
120 | 115 | _log = logging.getLogger(__name__)
|
121 | 116 |
|
|
135 | 130 | }"""
|
136 | 131 |
|
137 | 132 |
|
| 133 | +def __getattr__(name): |
| 134 | + if name == "__version__": |
| 135 | + import setuptools_scm |
| 136 | + global __version__ # cache it. |
| 137 | + # Only shell out to a git subprocess if really needed. |
| 138 | + root = Path(__file__).resolve().parents[2] |
| 139 | + if (root / ".git").exists(): |
| 140 | + __version__ = setuptools_scm.get_version( |
| 141 | + root=root, |
| 142 | + version_scheme="post-release", |
| 143 | + local_scheme="node-and-date", |
| 144 | + fallback_version=_version.version, |
| 145 | + ) |
| 146 | + else: # Get the version from the _version.py setuptools_scm file. |
| 147 | + __version__ = _version.version |
| 148 | + return __version__ |
| 149 | + raise AttributeError(f"module {__name__!r} has no attribute {name!r}") |
| 150 | + |
| 151 | + |
138 | 152 | def _check_versions():
|
139 | 153 |
|
140 | 154 | # Quickfix to ensure Microsoft Visual C++ redistributable
|
@@ -1435,7 +1449,6 @@ def inner(ax, *args, data=None, **kwargs):
|
1435 | 1449 | return inner
|
1436 | 1450 |
|
1437 | 1451 |
|
1438 |
| -_log.debug('matplotlib version %s', __version__) |
1439 | 1452 | _log.debug('interactive is %s', is_interactive())
|
1440 | 1453 | _log.debug('platform is %s', sys.platform)
|
1441 | 1454 | _log.debug('loaded modules: %s', list(sys.modules))
|
0 commit comments