forked from testcontainers/testcontainers-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversion.py
More file actions
30 lines (20 loc) · 871 Bytes
/
Copy pathversion.py
File metadata and controls
30 lines (20 loc) · 871 Bytes
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
from typing import Callable
from packaging.version import Version
class ComparableVersion:
def __init__(self, version):
self.version = Version(version)
def __lt__(self, other: str):
return self._apply_op(other, lambda x, y: x < y)
def __le__(self, other: str):
return self._apply_op(other, lambda x, y: x <= y)
def __eq__(self, other: str):
return self._apply_op(other, lambda x, y: x == y)
def __ne__(self, other: str):
return self._apply_op(other, lambda x, y: x != y)
def __gt__(self, other: str):
return self._apply_op(other, lambda x, y: x > y)
def __ge__(self, other: str):
return self._apply_op(other, lambda x, y: x >= y)
def _apply_op(self, other: str, op: Callable[[Version, Version], bool]):
other = Version(other)
return op(self.version, other)