A version object that can be compared to tuple of length 1--4: >>> attr.VersionInfo(19, 1, 0, "final") <= (19, 2) True >>> attr.VersionInfo(19, 1, 0, "final") < (19, 1, 1) True >>> vi = attr.VersionInfo(19, 2, 0, "final") >>> vi < (19, 1, 1) False >>> vi < (19,
| 11 | @total_ordering |
| 12 | @attrs(eq=False, order=False, slots=True, frozen=True) |
| 13 | class VersionInfo(object): |
| 14 | """ |
| 15 | A version object that can be compared to tuple of length 1--4: |
| 16 | |
| 17 | >>> attr.VersionInfo(19, 1, 0, "final") <= (19, 2) |
| 18 | True |
| 19 | >>> attr.VersionInfo(19, 1, 0, "final") < (19, 1, 1) |
| 20 | True |
| 21 | >>> vi = attr.VersionInfo(19, 2, 0, "final") |
| 22 | >>> vi < (19, 1, 1) |
| 23 | False |
| 24 | >>> vi < (19,) |
| 25 | False |
| 26 | >>> vi == (19, 2,) |
| 27 | True |
| 28 | >>> vi == (19, 2, 1) |
| 29 | False |
| 30 | |
| 31 | .. versionadded:: 19.2 |
| 32 | """ |
| 33 | |
| 34 | year = attrib(type=int) |
| 35 | minor = attrib(type=int) |
| 36 | micro = attrib(type=int) |
| 37 | releaselevel = attrib(type=str) |
| 38 | |
| 39 | @classmethod |
| 40 | def _from_version_string(cls, s): |
| 41 | """ |
| 42 | Parse *s* and return a _VersionInfo. |
| 43 | """ |
| 44 | v = s.split(".") |
| 45 | if len(v) == 3: |
| 46 | v.append("final") |
| 47 | |
| 48 | return cls( |
| 49 | year=int(v[0]), minor=int(v[1]), micro=int(v[2]), releaselevel=v[3] |
| 50 | ) |
| 51 | |
| 52 | def _ensure_tuple(self, other): |
| 53 | """ |
| 54 | Ensure *other* is a tuple of a valid length. |
| 55 | |
| 56 | Returns a possibly transformed *other* and ourselves as a tuple of |
| 57 | the same length as *other*. |
| 58 | """ |
| 59 | |
| 60 | if self.__class__ is other.__class__: |
| 61 | other = astuple(other) |
| 62 | |
| 63 | if not isinstance(other, tuple): |
| 64 | raise NotImplementedError |
| 65 | |
| 66 | if not (1 <= len(other) <= 4): |
| 67 | raise NotImplementedError |
| 68 | |
| 69 | return astuple(self)[: len(other)], other |
| 70 |