-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
137 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters