Skip to content

Commit 855e2f7

Browse files
committed
fix: bake version into PyInstaller bundle via src/_version.py
1 parent 52d6174 commit 855e2f7

File tree

3 files changed

+28
-25
lines changed

3 files changed

+28
-25
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ jobs:
4040
- name: Build Python sidecar
4141
shell: bash
4242
run: |
43-
export DOCTORFILL_VERSION="${GITHUB_REF_NAME#v}"
43+
VERSION="${GITHUB_REF_NAME#v}"
44+
echo "__version__ = \"${VERSION}\"" > src/_version.py
4445
pyinstaller --noconfirm pyinstaller.spec
4546
4647
- name: Copy sidecar binary (Unix)

src/_version.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# This file is auto-generated by the CI build pipeline.
2+
# Do not edit manually — changes will be overwritten on release builds.
3+
# For local development, edit this value manually if needed.
4+
__version__ = "dev"

src/web/app.py

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -51,44 +51,42 @@
5151

5252
def _read_app_version() -> str:
5353
"""
54-
Read the app version from tauri.conf.json.
54+
Read the app version.
5555
5656
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)
6059
"""
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
6867

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
7475

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
7677
here = Path(__file__).resolve()
7778
for parent in here.parents:
7879
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():
8581
try:
86-
data = json.loads(path.read_text(encoding="utf-8"))
82+
data = json.loads(candidate.read_text(encoding="utf-8"))
8783
version = data.get("version")
8884
if version:
8985
return str(version)
9086
except Exception:
9187
pass
88+
if parent.name == "DoctorFill-Python":
89+
break
9290

9391
return "unknown"
9492

0 commit comments

Comments
 (0)