-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversion.py
74 lines (61 loc) · 1.85 KB
/
version.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
class Version:
def __init__(self, major:int, minor:int, bug:int):
"""Object for version recording.
Uses the major.minor.bug notation.
Parameters
----------
major: int
The major number for the version number.
minor: int
The minor number for the version number.
bug: int
The bug number for the version number.
"""
self.major = major
self.minor = minor
self.bug = bug
def __str__(self) -> str:
"""Turn this object into a nicely formatted string"""
return f"{self.major}.{self.minor}.{self.bug}"
def __eq__(self, other:"Version") -> bool:
"""Perform an equality check between this and another Version object
Parameters
----------
other: Version
Another version object to check equality of.
Returns
bool
Rather the two Version objects are equal.
"""
if self.major != other.major:
return False
elif self.minor != other.minor:
return False
elif self.bug != other.bug:
return False
else:
return True
@staticmethod
def from_str(string:str) -> "Version":
"""Turn a string of numbers into a Version object
Parameters
----------
string: str
The format is major.minor.bug, and they should be
integers
Returns
-------
Version
The constructed Version object.
"""
if string is None:
return Version(0,0,0)
else:
numbers = string.split(".")
return Version(
int(numbers[0]),
int(numbers[1]),
int(numbers[2])
)
# The version for Controllers
__version__ = Version(1,4,0)