-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path__init__.py
More file actions
45 lines (38 loc) · 1.7 KB
/
__init__.py
File metadata and controls
45 lines (38 loc) · 1.7 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# mypy: disable-error-code="attr-defined"
"""Command Line Interface to Password Pusher - secure information distribution with automatic expiration controls."""
from importlib import metadata as importlib_metadata
from pathlib import Path
def get_version() -> str:
try:
return importlib_metadata.version(__name__)
except importlib_metadata.PackageNotFoundError:
# Fallback: read version from pyproject.toml when running from source
try:
pyproject_path = Path(__file__).parent.parent / "pyproject.toml"
if pyproject_path.exists():
# Try tomllib (Python 3.11+) or tomli (Python 3.10)
try:
import tomllib
except ImportError:
try:
import tomli as tomllib
except ImportError:
# Fallback: simple regex extraction for Python 3.10 without tomli
import re
content = pyproject_path.read_text()
match = re.search(
r'^version\s*=\s*"([^"]+)"', content, re.MULTILINE
)
if match:
return match.group(1)
return "unknown"
with open(pyproject_path, "rb") as f:
pyproject_data = tomllib.load(f)
version = pyproject_data.get("project", {}).get(
"version", "unknown"
)
return str(version) if version is not None else "unknown"
except Exception:
pass
return "unknown"
version: str = get_version()