Coverage for src/package/version.py: 100.00%

23 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-10-18 15:02 +0000

1#!/usr/bin/env python3 

2 

3# Standard libraries 

4from os import environ 

5from sys import version_info 

6 

7# Components 

8from ..system.platform import Platform 

9from .bundle import Bundle 

10 

11# Version class 

12class Version: 

13 

14 # Getter 

15 @staticmethod 

16 def get() -> str: 

17 

18 # Fake test version 

19 if Bundle.ENV_DEBUG_VERSION_FAKE in environ: 

20 return environ[Bundle.ENV_DEBUG_VERSION_FAKE] 

21 

22 # Acquire version from metadata 

23 try: 

24 from importlib import metadata # pylint: disable=import-outside-toplevel 

25 return metadata.version(Bundle.PACKAGE) 

26 except Exception: # pylint: disable=broad-exception-caught # pragma: no cover 

27 pass 

28 

29 # Acquire version from resources 

30 try: # pragma: no cover 

31 import importlib.metadata # pylint: disable=import-outside-toplevel 

32 name = __name__.split('.', maxsplit=1)[0] 

33 return importlib.metadata.version(name) 

34 

35 # Acquire version from package resources 

36 except Exception: # pylint: disable=broad-exception-caught # pragma: no cover 

37 try: 

38 import importlib.metadata # pylint: disable=import-outside-toplevel 

39 return importlib.metadata.version(Bundle.PACKAGE) 

40 

41 # Default fallback 

42 except Exception: # pylint: disable=broad-exception-caught # pragma: no cover 

43 return '0.0.0' 

44 

45 # Path 

46 @staticmethod 

47 def path() -> str: 

48 

49 # Acquire path 

50 path = __file__ 

51 

52 # Strip package path 

53 index = path.rfind(Platform.PATH_SEPARATOR) 

54 index = path.rfind(Platform.PATH_SEPARATOR, 0, index) 

55 path = path[0:index] 

56 

57 # Result 

58 return path 

59 

60 # Python 

61 @staticmethod 

62 def python() -> str: 

63 

64 # Acquire Python version 

65 version = f'{version_info.major}.{version_info.minor}' 

66 

67 # Result 

68 return version