drawsvg-ui 0.4.0__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.
app_info.py ADDED
@@ -0,0 +1,61 @@
1
+ from __future__ import annotations
2
+
3
+ from importlib import metadata
4
+ from pathlib import Path
5
+ from typing import Optional
6
+
7
+ PACKAGE_NAME = "drawsvg-ui"
8
+ GITHUB_URL = "https://github.com/Taron686/UI_drawsvg"
9
+
10
+
11
+ def get_version() -> str:
12
+ """
13
+ Resolve the application version from installed metadata when available.
14
+ Falls back to reading pyproject.toml so running from a checkout still shows a version.
15
+ """
16
+ try:
17
+ return metadata.version(PACKAGE_NAME)
18
+ except metadata.PackageNotFoundError:
19
+ pass
20
+
21
+ version = _read_version_from_pyproject()
22
+ return version or "0.0.0"
23
+
24
+
25
+ def _read_version_from_pyproject() -> Optional[str]:
26
+ """Best-effort lookup of the version field in pyproject.toml when running from source."""
27
+ pyproject_path = Path(__file__).resolve().parent.parent / "pyproject.toml"
28
+ if not pyproject_path.is_file():
29
+ return None
30
+
31
+ try:
32
+ content = pyproject_path.read_text(encoding="utf-8")
33
+ except OSError:
34
+ return None
35
+
36
+ # Prefer tomllib when available (Python 3.11+ or backport)
37
+ try:
38
+ import tomllib # type: ignore
39
+ except ModuleNotFoundError:
40
+ tomllib = None
41
+
42
+ if tomllib is not None:
43
+ try:
44
+ data = tomllib.loads(content)
45
+ project = data.get("project", {})
46
+ version = project.get("version")
47
+ if version:
48
+ return str(version)
49
+ except Exception:
50
+ pass
51
+
52
+ for line in content.splitlines():
53
+ stripped = line.strip()
54
+ if not stripped.startswith("version"):
55
+ continue
56
+ _, _, remainder = stripped.partition("=")
57
+ candidate = remainder.strip().strip('"').strip("'")
58
+ if candidate:
59
+ return candidate
60
+
61
+ return None