Coverage for src/sensai/util/version.py: 57%

21 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-08-13 22:17 +0000

1 

2 

3class Version: 

4 """ 

5 Assists in checking the version of a Python package based on the __version__ attribute 

6 """ 

7 def __init__(self, package): 

8 """ 

9 :param package: the package object 

10 """ 

11 self.components = package.__version__.split(".") 

12 

13 def is_at_least(self, *components: int): 

14 """ 

15 Checks this version against the given version components. 

16 This version object must contain at least the respective number of components 

17 

18 :param components: version components in order (i.e. major, minor, patch, etc.) 

19 :return: True if the version is at least the given version, False otherwise 

20 """ 

21 for i, desired_min_version in enumerate(components): 

22 actual_version = int(self.components[i]) 

23 if actual_version < desired_min_version: 

24 return False 

25 elif actual_version > desired_min_version: 

26 return True 

27 return True 

28 

29 def is_at_most(self, *components: int): 

30 """ 

31 Checks this version against the given version components. 

32 This version object must contain at least the respective number of components 

33 

34 :param components: version components in order (i.e. major, minor, patch, etc.) 

35 :return: True if the version is at most the given version, False otherwise 

36 """ 

37 for i, desired_max_version in enumerate(components): 

38 actual_version = int(self.components[i]) 

39 if actual_version > desired_max_version: 

40 return False 

41 elif actual_version < desired_max_version: 

42 return True 

43 return True 

44 

45 def is_equal(self, *components: int): 

46 """ 

47 Checks this version against the given version components. 

48 This version object must contain at least the respective number of components 

49 

50 :param components: version components in order (i.e. major, minor, patch, etc.) 

51 :return: True if the version is the given version, False otherwise 

52 """ 

53 return self.components[:len(components)] == list(components)