bumpcheck-py 0.1.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
bumpcheck/__init__.py ADDED
@@ -0,0 +1,35 @@
1
+ """BumpCheck package."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import tomllib
6
+ from importlib.metadata import PackageNotFoundError
7
+ from importlib.metadata import version as dist_version
8
+ from pathlib import Path
9
+
10
+ _DISTRIBUTION_NAME = "bumpcheck-py"
11
+ _UNKNOWN_VERSION = "0+unknown"
12
+
13
+
14
+ def _pyproject_version() -> str | None:
15
+ pyproject = Path(__file__).resolve().parents[2] / "pyproject.toml"
16
+ try:
17
+ with pyproject.open("rb") as handle:
18
+ data = tomllib.load(handle)
19
+ except (OSError, tomllib.TOMLDecodeError):
20
+ return None
21
+ project = data.get("project")
22
+ if not isinstance(project, dict):
23
+ return None
24
+ value = project.get("version")
25
+ return value if isinstance(value, str) else None
26
+
27
+
28
+ def _get_version() -> str:
29
+ try:
30
+ return dist_version(_DISTRIBUTION_NAME)
31
+ except PackageNotFoundError:
32
+ return _pyproject_version() or _UNKNOWN_VERSION
33
+
34
+
35
+ __version__ = _get_version()