-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathversion.py
More file actions
31 lines (24 loc) · 834 Bytes
/
version.py
File metadata and controls
31 lines (24 loc) · 834 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import importlib.metadata
import logging
from pathlib import Path
import toml
def get_version() -> str:
try:
# Works for local development
return _get_version_from_pyproject()
except Exception:
try:
# Works for the installed package
return _get_version_from_metadata()
except Exception as error:
logging.exception(f"Failed to get version: {error}")
return "unknown"
def _get_version_from_pyproject() -> str:
pyproject_path = Path(__file__).parent.parent / "pyproject.toml"
version: str = toml.load(pyproject_path)["project"]["version"]
return version
def _get_version_from_metadata() -> str:
try:
return importlib.metadata.version("multiversx_sdk_cli")
except:
return importlib.metadata.version("mxpy")