Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/attr/_version_info.py @ 0:4f3585e2f14b draft default tip
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author | shellac |
---|---|
date | Mon, 22 Mar 2021 18:12:50 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4f3585e2f14b |
---|---|
1 from __future__ import absolute_import, division, print_function | |
2 | |
3 from functools import total_ordering | |
4 | |
5 from ._funcs import astuple | |
6 from ._make import attrib, attrs | |
7 | |
8 | |
9 @total_ordering | |
10 @attrs(eq=False, order=False, slots=True, frozen=True) | |
11 class VersionInfo(object): | |
12 """ | |
13 A version object that can be compared to tuple of length 1--4: | |
14 | |
15 >>> attr.VersionInfo(19, 1, 0, "final") <= (19, 2) | |
16 True | |
17 >>> attr.VersionInfo(19, 1, 0, "final") < (19, 1, 1) | |
18 True | |
19 >>> vi = attr.VersionInfo(19, 2, 0, "final") | |
20 >>> vi < (19, 1, 1) | |
21 False | |
22 >>> vi < (19,) | |
23 False | |
24 >>> vi == (19, 2,) | |
25 True | |
26 >>> vi == (19, 2, 1) | |
27 False | |
28 | |
29 .. versionadded:: 19.2 | |
30 """ | |
31 | |
32 year = attrib(type=int) | |
33 minor = attrib(type=int) | |
34 micro = attrib(type=int) | |
35 releaselevel = attrib(type=str) | |
36 | |
37 @classmethod | |
38 def _from_version_string(cls, s): | |
39 """ | |
40 Parse *s* and return a _VersionInfo. | |
41 """ | |
42 v = s.split(".") | |
43 if len(v) == 3: | |
44 v.append("final") | |
45 | |
46 return cls( | |
47 year=int(v[0]), minor=int(v[1]), micro=int(v[2]), releaselevel=v[3] | |
48 ) | |
49 | |
50 def _ensure_tuple(self, other): | |
51 """ | |
52 Ensure *other* is a tuple of a valid length. | |
53 | |
54 Returns a possibly transformed *other* and ourselves as a tuple of | |
55 the same length as *other*. | |
56 """ | |
57 | |
58 if self.__class__ is other.__class__: | |
59 other = astuple(other) | |
60 | |
61 if not isinstance(other, tuple): | |
62 raise NotImplementedError | |
63 | |
64 if not (1 <= len(other) <= 4): | |
65 raise NotImplementedError | |
66 | |
67 return astuple(self)[: len(other)], other | |
68 | |
69 def __eq__(self, other): | |
70 try: | |
71 us, them = self._ensure_tuple(other) | |
72 except NotImplementedError: | |
73 return NotImplemented | |
74 | |
75 return us == them | |
76 | |
77 def __lt__(self, other): | |
78 try: | |
79 us, them = self._ensure_tuple(other) | |
80 except NotImplementedError: | |
81 return NotImplemented | |
82 | |
83 # Since alphabetically "dev0" < "final" < "post1" < "post2", we don't | |
84 # have to do anything special with releaselevel for now. | |
85 return us < them |