-
Notifications
You must be signed in to change notification settings - Fork 96
Expand file tree
/
Copy pathversions.py
More file actions
59 lines (46 loc) · 1.57 KB
/
versions.py
File metadata and controls
59 lines (46 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python3
"""
Utilities for handling dependencies and version changes.
"""
from . import ic # noqa: F401
from . import warnings
class _version(list):
"""
Casual parser for ``major.minor`` style version strings. We do not want to
add a 'packaging' dependency and only care about major and minor tags.
"""
def __str__(self):
return self._version
def __repr__(self):
return f'version({self._version})'
def __init__(self, version):
try:
major, minor, *_ = version.split('.')
major, minor = int(major or 0), int(minor or 0)
except Exception:
warnings._warn_proplot(f'Unexpected version {version!r}. Using 0.0.0.')
major = minor = 0
self._version = f'{major}.{minor}'
super().__init__((major, minor)) # then use builtin python list sorting
def __eq__(self, other):
return super().__eq__(_version(other))
def __ne__(self, other):
return super().__ne__(_version(other))
def __gt__(self, other):
return super().__gt__(_version(other))
def __lt__(self, other):
return super().__lt__(_version(other))
def __ge__(self, other):
return super().__ge__(_version(other))
def __le__(self, other):
return super().__le__(_version(other))
# Matplotlib version
import matplotlib # isort:skip
_version_mpl = _version(matplotlib.__version__)
# Cartopy version
try:
import cartopy
except ImportError:
_version_cartopy = _version('0.0.0')
else:
_version_cartopy = _version(cartopy.__version__)