Skip to content

Commit

Permalink
add Version class
Browse files Browse the repository at this point in the history
  • Loading branch information
Sup2point0 committed May 13, 2024
1 parent fec35b5 commit fc7d159
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions source/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from dataclasses import dataclass


@ dataclass(slots = True)
class Version:
'''A lightweight representation of a 3-value version number.'''

root: int = 1
major: int = 0
minor: int = 0
dev: str = ""

def __post_init__(self):
if isinstance(self.root, str):
parts = self.root.split(".")

self.root = int(parts.pop(0))
if parts:
self.major = int(parts.pop(0))
if parts:
self.minor = int(parts.pop(0))
if parts:
self.dev = ".".join(parts)

def update(self, part: str) -> Version:
'''Increment the version.'''

match part:
case "root":
self.root += 1
self.major = 0
self.minor = 0

case "major":
self.major += 1
self.minor = 0

case "minor":
self.minor += 1

0 comments on commit fc7d159

Please sign in to comment.