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