-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from peopledoc/issue_47_use_version_object_eve…
…rywhere Use Version objects all the way up
- Loading branch information
Showing
13 changed files
with
150 additions
and
117 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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,19 @@ | ||
import dataclasses | ||
|
||
from septentrion import exceptions | ||
|
||
|
||
@dataclasses.dataclass(order=True, unsafe_hash=True, frozen=True) | ||
class Version: | ||
def __init__(self, version_string: str): | ||
|
||
version_tuple: tuple = dataclasses.field(compare=True) | ||
original_string: str = dataclasses.field(compare=False) | ||
|
||
@classmethod | ||
def from_string(cls, version_string: str) -> "Version": | ||
try: | ||
assert version_string | ||
self._version = tuple(int(e) for e in version_string.split(".")) | ||
version_tuple = tuple(int(e) for e in version_string.split(".")) | ||
except (AssertionError, ValueError) as exc: | ||
raise exceptions.InvalidVersion(str(exc)) from exc | ||
|
||
def __lt__(self, other: object) -> bool: | ||
if isinstance(other, Version): | ||
return self._version < other._version | ||
raise NotImplementedError | ||
|
||
def __eq__(self, other: object) -> bool: | ||
if isinstance(other, Version): | ||
return self._version == other._version | ||
raise NotImplementedError | ||
|
||
def __repr__(self) -> str: | ||
version_string = ".".join(str(n) for n in self._version) | ||
return f'{self.__class__.__name__}("{version_string}")' | ||
return cls(version_tuple=version_tuple, original_string=version_string) |
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
Oops, something went wrong.