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
« prev ^ index » next coverage.py v7.15.4, created at 2026-10-18 15:02 +0000
1#!/usr/bin/env python3
3# Standard libraries
4from os import environ
5from sys import version_info
7# Components
8from ..system.platform import Platform
9from .bundle import Bundle
11# Version class
12class Version:
14 # Getter
15 @staticmethod
16 def get() -> str:
18 # Fake test version
19 if Bundle.ENV_DEBUG_VERSION_FAKE in environ:
20 return environ[Bundle.ENV_DEBUG_VERSION_FAKE]
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
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)
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)
41 # Default fallback
42 except Exception: # pylint: disable=broad-exception-caught # pragma: no cover
43 return '0.0.0'
45 # Path
46 @staticmethod
47 def path() -> str:
49 # Acquire path
50 path = __file__
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]
57 # Result
58 return path
60 # Python
61 @staticmethod
62 def python() -> str:
64 # Acquire Python version
65 version = f'{version_info.major}.{version_info.minor}'
67 # Result
68 return version