Coverage for /home/runner/work/bijux-cli/bijux-cli/src/bijux_cli/__version__.py: 80%

20 statements  

« prev     ^ index     » next       coverage.py v7.10.4, created at 2025-08-19 23:36 +0000

1# SPDX-License-Identifier: MIT 

2# Copyright © 2025 Bijan Mousavi 

3 

4"""Provides version metadata for the Bijux CLI package. 

5 

6This module dynamically retrieves version information from the installed 

7package's metadata and the project's pyproject.toml file. This ensures that 

8versions are managed from a single source of truth. 

9 

10It exposes two primary versions: 

11 * `version`: The main application version (`packaging.version.Version`). 

12 * `api_version`: A separate version for the plugin API, used for 

13 compatibility checks. 

14""" 

15 

16from __future__ import annotations 

17 

18from importlib.metadata import PackageNotFoundError 

19from importlib.metadata import version as _get_version 

20from pathlib import Path 

21import tomllib 

22 

23from packaging.version import Version 

24 

25try: 

26 __version__: str = _get_version("bijux-cli") 

27except PackageNotFoundError: 

28 __version__ = "0.1.0" 

29 

30 

31try: 

32 pyproject_path = Path(__file__).parent.parent.parent / "pyproject.toml" 

33 with pyproject_path.open("rb") as f: 

34 pyproject_data = tomllib.load(f) 

35 __api_version__: str = pyproject_data["tool"]["bijux"]["api_version"] 

36except (FileNotFoundError, KeyError): 

37 __api_version__ = "0.1.0" 

38 

39version = Version(__version__) 

40api_version = Version(__api_version__) 

41 

42__all__ = ["version", "api_version", "__version__", "__api_version__"]