Elffuss BraidHub

kikocis/auto-code-rover public

main · 3.2 KiBRawPermalink
1diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py
2--- a/lib/matplotlib/__init__.py
3+++ b/lib/matplotlib/__init__.py
4@@ -129,25 +129,60 @@
5 year = 2007
6 }"""
7
8+# modelled after sys.version_info
9+_VersionInfo = namedtuple('_VersionInfo',
10+ 'major, minor, micro, releaselevel, serial')
11
12-def __getattr__(name):
13- if name == "__version__":
14+
15+def _parse_to_version_info(version_str):
16+ """
17+ Parse a version string to a namedtuple analogous to sys.version_info.
18+
19+ See:
20+ https://packaging.pypa.io/en/latest/version.html#packaging.version.parse
21+ https://docs.python.org/3/library/sys.html#sys.version_info
22+ """
23+ v = parse_version(version_str)
24+ if v.pre is None and v.post is None and v.dev is None:
25+ return _VersionInfo(v.major, v.minor, v.micro, 'final', 0)
26+ elif v.dev is not None:
27+ return _VersionInfo(v.major, v.minor, v.micro, 'alpha', v.dev)
28+ elif v.pre is not None:
29+ releaselevel = {
30+ 'a': 'alpha',
31+ 'b': 'beta',
32+ 'rc': 'candidate'}.get(v.pre[0], 'alpha')
33+ return _VersionInfo(v.major, v.minor, v.micro, releaselevel, v.pre[1])
34+ else:
35+ # fallback for v.post: guess-next-dev scheme from setuptools_scm
36+ return _VersionInfo(v.major, v.minor, v.micro + 1, 'alpha', v.post)
37+
38+
39+def _get_version():
40+ """Return the version string used for __version__."""
41+ # Only shell out to a git subprocess if really needed, and not on a
42+ # shallow clone, such as those used by CI, as the latter would trigger
43+ # a warning from setuptools_scm.
44+ root = Path(__file__).resolve().parents[2]
45+ if (root / ".git").exists() and not (root / ".git/shallow").exists():
46 import setuptools_scm
47+ return setuptools_scm.get_version(
48+ root=root,
49+ version_scheme="post-release",
50+ local_scheme="node-and-date",
51+ fallback_version=_version.version,
52+ )
53+ else: # Get the version from the _version.py setuptools_scm file.
54+ return _version.version
55+
56+
57+def __getattr__(name):
58+ if name in ("__version__", "__version_info__"):
59 global __version__ # cache it.
60- # Only shell out to a git subprocess if really needed, and not on a
61- # shallow clone, such as those used by CI, as the latter would trigger
62- # a warning from setuptools_scm.
63- root = Path(__file__).resolve().parents[2]
64- if (root / ".git").exists() and not (root / ".git/shallow").exists():
65- __version__ = setuptools_scm.get_version(
66- root=root,
67- version_scheme="post-release",
68- local_scheme="node-and-date",
69- fallback_version=_version.version,
70- )
71- else: # Get the version from the _version.py setuptools_scm file.
72- __version__ = _version.version
73- return __version__
74+ __version__ = _get_version()
75+ global __version__info__ # cache it.
76+ __version_info__ = _parse_to_version_info(__version__)
77+ return __version__ if name == "__version__" else __version_info__
78 raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
79
80