File tree Expand file tree Collapse file tree 2 files changed +24
-4
lines changed
Expand file tree Collapse file tree 2 files changed +24
-4
lines changed Original file line number Diff line number Diff line change 1- from importlib .metadata import version
1+ import sys
2+ from importlib .metadata import PackageNotFoundError , version
3+ from pathlib import Path
24
35from rich .console import Console
46from 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" )
Original file line number Diff line number Diff line change 11import os
22import time
3- from importlib .metadata import version as get_version
43
54import typer
65from 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" )
You can’t perform that action at this time.
0 commit comments