|
51 | 51 |
|
52 | 52 | def _read_app_version() -> str: |
53 | 53 | """ |
54 | | - Read the app version from tauri.conf.json. |
| 54 | + Read the app version. |
55 | 55 |
|
56 | 56 | Search order: |
57 | | - 1. DOCTORFILL_VERSION env var (injected by CI at build time) |
58 | | - 2. tauri.conf.json next to the executable (PyInstaller bundle) |
59 | | - 3. tauri.conf.json at project root (development) |
| 57 | + 1. src._version module (baked in at CI build time via PyInstaller) |
| 58 | + 2. tauri.conf.json at project root (development fallback) |
60 | 59 | """ |
61 | | - # 1. Env var set by CI / build script |
62 | | - env_version = os.environ.get("DOCTORFILL_VERSION") |
63 | | - if env_version: |
64 | | - return env_version |
65 | | - |
66 | | - # 2. Candidate paths for tauri.conf.json |
67 | | - candidates = [] |
| 60 | + # 1. Version baked into the bundle by CI |
| 61 | + try: |
| 62 | + from src._version import __version__ as baked_version |
| 63 | + if baked_version and baked_version != "dev": |
| 64 | + return baked_version |
| 65 | + except ImportError: |
| 66 | + pass |
68 | 67 |
|
69 | | - # PyInstaller bundle: exe is next to src-tauri/ at install time, |
70 | | - # but during dev the conf lives at project_root/src-tauri/tauri.conf.json |
71 | | - exe_dir = Path(sys.executable).parent |
72 | | - candidates.append(exe_dir / "tauri.conf.json") |
73 | | - candidates.append(exe_dir.parent / "src-tauri" / "tauri.conf.json") |
| 68 | + # Also try the top-level _version module (PyInstaller flattens imports) |
| 69 | + try: |
| 70 | + import _version as _v # type: ignore[import] |
| 71 | + if _v.__version__ and _v.__version__ != "dev": |
| 72 | + return _v.__version__ |
| 73 | + except ImportError: |
| 74 | + pass |
74 | 75 |
|
75 | | - # Development: walk up from this file to find src-tauri/ |
| 76 | + # 2. Development: walk up from this file to find src-tauri/tauri.conf.json |
76 | 77 | here = Path(__file__).resolve() |
77 | 78 | for parent in here.parents: |
78 | 79 | candidate = parent / "src-tauri" / "tauri.conf.json" |
79 | | - candidates.append(candidate) |
80 | | - if parent.name == "DoctorFill-Python": |
81 | | - break |
82 | | - |
83 | | - for path in candidates: |
84 | | - if path.exists(): |
| 80 | + if candidate.exists(): |
85 | 81 | try: |
86 | | - data = json.loads(path.read_text(encoding="utf-8")) |
| 82 | + data = json.loads(candidate.read_text(encoding="utf-8")) |
87 | 83 | version = data.get("version") |
88 | 84 | if version: |
89 | 85 | return str(version) |
90 | 86 | except Exception: |
91 | 87 | pass |
| 88 | + if parent.name == "DoctorFill-Python": |
| 89 | + break |
92 | 90 |
|
93 | 91 | return "unknown" |
94 | 92 |
|
|
0 commit comments