Version class object that stores SemVer version information.
| 65 | |
| 66 | |
| 67 | class Version(object): |
| 68 | """Version class object that stores SemVer version information.""" |
| 69 | |
| 70 | def __init__(self, major, minor, patch, identifier_string, version_type): |
| 71 | """Constructor. |
| 72 | |
| 73 | Args: |
| 74 | major: major string eg. (1) |
| 75 | minor: minor string eg. (3) |
| 76 | patch: patch string eg. (1) |
| 77 | identifier_string: extension string eg. (-rc0) |
| 78 | version_type: version parameter ((REGULAR|NIGHTLY)_VERSION) |
| 79 | """ |
| 80 | self.major = major |
| 81 | self.minor = minor |
| 82 | self.patch = patch |
| 83 | self.identifier_string = identifier_string |
| 84 | self.version_type = version_type |
| 85 | self._update_string() |
| 86 | |
| 87 | def _update_string(self): |
| 88 | self.string = "%s.%s.%s%s" % (self.major, |
| 89 | self.minor, |
| 90 | self.patch, |
| 91 | self.identifier_string) |
| 92 | |
| 93 | def __str__(self): |
| 94 | return self.string |
| 95 | |
| 96 | def set_identifier_string(self, identifier_string): |
| 97 | self.identifier_string = identifier_string |
| 98 | self._update_string() |
| 99 | |
| 100 | @property |
| 101 | def pep_440_str(self): |
| 102 | if self.version_type == REGULAR_VERSION: |
| 103 | return_string = "%s.%s.%s%s" % (self.major, |
| 104 | self.minor, |
| 105 | self.patch, |
| 106 | self.identifier_string) |
| 107 | return return_string.replace("-", "") |
| 108 | else: |
| 109 | return_string = "%s.%s.%s" % (self.major, |
| 110 | self.minor, |
| 111 | self.identifier_string) |
| 112 | return return_string.replace("-", "") |
| 113 | |
| 114 | @staticmethod |
| 115 | def parse_from_string(string, version_type): |
| 116 | """Returns version object from Semver string. |
| 117 | |
| 118 | Args: |
| 119 | string: version string |
| 120 | version_type: version parameter |
| 121 | |
| 122 | Raises: |
| 123 | RuntimeError: If the version string is not valid. |
| 124 | """ |
no outgoing calls
no test coverage detected