Skip to content

Commit f79d808

Browse files
committed
feat: read version from installed pkg with fallback to bundler/src
1 parent a986b9a commit f79d808

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

cli/app/commands/version/version.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
from importlib.metadata import version
1+
import sys
2+
from importlib.metadata import PackageNotFoundError, version
3+
from pathlib import Path
24

35
from rich.console import Console
46
from rich.panel import Panel
@@ -9,9 +11,27 @@ class VersionCommand:
911
def __init__(self):
1012
self.console = Console()
1113

14+
def _get_version(self) -> str:
15+
"""Get version from package metadata or bundled version.txt"""
16+
try:
17+
return version("nixopus")
18+
except PackageNotFoundError:
19+
# Read from version.txt (works in both dev and PyInstaller bundle)
20+
if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'):
21+
# Running from PyInstaller bundle
22+
version_file = Path(sys._MEIPASS) / "version.txt"
23+
else:
24+
# Running from source
25+
version_file = Path(__file__).parent.parent.parent.parent.parent / "version.txt"
26+
27+
if version_file.exists():
28+
return version_file.read_text().strip().lstrip("v")
29+
30+
return "unknown"
31+
1232
def run(self):
1333
"""Display the version of the CLI"""
14-
cli_version = version("nixopus")
34+
cli_version = self._get_version()
1535

1636
version_text = Text()
1737
version_text.append("Nixopus CLI", style="bold blue")

cli/app/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import os
22
import time
3-
from importlib.metadata import version as get_version
43

54
import typer
65
from rich.console import Console
@@ -73,7 +72,8 @@ def main(
7372

7473
console.print(panel)
7574

76-
cli_version = get_version("nixopus")
75+
version_cmd = VersionCommand()
76+
cli_version = version_cmd._get_version()
7777
version_text = Text()
7878
version_text.append("Version: ", style="bold white")
7979
version_text.append(f"v{cli_version}", style="green")

0 commit comments

Comments
 (0)