mirror of
https://github.com/esphome/esphome.git
synced 2025-07-31 07:36:35 +00:00
[validation] Store version extra separator
This commit is contained in:
parent
1f0c606be4
commit
4f67d25506
@ -288,23 +288,31 @@ class Version:
|
|||||||
major: int
|
major: int
|
||||||
minor: int
|
minor: int
|
||||||
patch: int
|
patch: int
|
||||||
|
extra_separator: str = ""
|
||||||
extra: str = ""
|
extra: str = ""
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
if self.extra:
|
return (
|
||||||
return f"{self.major}.{self.minor}.{self.patch}-{self.extra}"
|
f"{self.major}.{self.minor}.{self.patch}{self.extra_separator}{self.extra}"
|
||||||
return f"{self.major}.{self.minor}.{self.patch}"
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def parse(cls, value: str) -> Version:
|
def parse(cls, value: str) -> Version:
|
||||||
match = re.match(r"^(\d+).(\d+).(\d+)-?(\w*)$", value)
|
match = re.match(r"^(\d+).(\d+).(\d+)(-)?(\w*)$", value)
|
||||||
if match is None:
|
if match is None:
|
||||||
raise ValueError(f"Not a valid version number {value}")
|
raise ValueError(f"Not a valid version number {value}")
|
||||||
major = int(match[1])
|
major = int(match[1])
|
||||||
minor = int(match[2])
|
minor = int(match[2])
|
||||||
patch = int(match[3])
|
patch = int(match[3])
|
||||||
extra = match[4] or ""
|
extra_separator = match[4] or ""
|
||||||
return Version(major=major, minor=minor, patch=patch, extra=extra)
|
extra = match[5] or ""
|
||||||
|
return Version(
|
||||||
|
major=major,
|
||||||
|
minor=minor,
|
||||||
|
patch=patch,
|
||||||
|
extra_separator=extra_separator,
|
||||||
|
extra=extra,
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_beta(self) -> bool:
|
def is_beta(self) -> bool:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user