-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
48 lines (38 loc) · 1.51 KB
/
app.py
File metadata and controls
48 lines (38 loc) · 1.51 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
46
47
48
import os
import sys
def get_version() -> str:
"""
Get the application version.
Priority:
1. APP_VERSION env var (for Docker/custom deployments)
2. Bundled version.txt (baked in during PyInstaller build)
3. Fallback to "0.0.0"
"""
# Priority 1: Environment variable override
env_version = os.environ.get("APP_VERSION")
if env_version:
return env_version
# Priority 2: Read from bundled version.txt
try:
if getattr(sys, "frozen", False):
# Running as PyInstaller bundle - version.txt is in _internal/
bundle_dir = os.path.dirname(sys.executable)
version_file = os.path.join(bundle_dir, "_internal", "version.txt")
else:
# Running as script - version.txt is in project root
version_file = os.path.join(os.path.dirname(__file__), "version.txt")
if os.path.exists(version_file):
with open(version_file) as f:
return f.read().strip()
except Exception:
pass
return "0.0.0"
# Handle --version flag BEFORE importing Flask to avoid initialization overhead
# This allows Electron to quickly verify the backend binary is valid
if __name__ == "__main__" and len(sys.argv) > 1 and sys.argv[1] == "--version":
print(get_version())
sys.exit(0)
from api import app # noqa: E402 - intentionally after --version check to avoid Flask init overhead
from core import config # noqa: E402
if __name__ == "__main__":
app.run(host="0.0.0.0", port=config.SERVER_PORT)