2323import subprocess
2424import sys
2525from pathlib import Path
26+ from typing import Optional
2627
2728
28- def find_zigx_binary () -> Path :
29+ def find_zigx_binary () -> Optional [ Path ] :
2930 """Find the zigx binary in common locations."""
3031 # Check if running from source
3132 pkg_dir = Path (__file__ ).parent
32-
33+
3334 # Look for zig-out directory (built binary)
3435 zig_out = pkg_dir / "zig-out" / "bin" / get_binary_name ()
3536 if zig_out .exists ():
3637 return zig_out
37-
38+
3839 # Look in parent's zig-out (development mode)
3940 parent_zig_out = pkg_dir .parent / "zigx" / "zig-out" / "bin" / get_binary_name ()
4041 if parent_zig_out .exists ():
4142 return parent_zig_out
42-
43+
4344 # Look in installed location
4445 bin_dir = Path (sys .prefix ) / "bin"
4546 installed = bin_dir / get_binary_name ()
4647 if installed .exists ():
4748 return installed
48-
49+
4950 # Check if zig is available and try to build
5051 return None
5152
@@ -62,16 +63,16 @@ def ensure_binary() -> Path:
6263 binary = find_zigx_binary ()
6364 if binary :
6465 return binary
65-
66+
6667 # Try to build from source
6768 pkg_dir = Path (__file__ ).parent
6869 zig_src = pkg_dir / "src"
69-
70+
7071 # Check for Zig source
7172 if not (zig_src / "main.zig" ).exists ():
7273 # Maybe in development structure
7374 zig_src = pkg_dir .parent / "zigx" / "src"
74-
75+
7576 if (zig_src / "main.zig" ).exists ():
7677 build_dir = zig_src .parent
7778 print ("Building zigx from source..." , file = sys .stderr )
@@ -91,7 +92,7 @@ def ensure_binary() -> Path:
9192 print (f"Build failed: { result .stderr } " , file = sys .stderr )
9293 except FileNotFoundError :
9394 pass
94-
95+
9596 raise RuntimeError (
9697 "zigx binary not found. Please ensure Zig is installed and run:\n "
9798 " cd zigx && zig build\n "
@@ -106,7 +107,7 @@ def run(*args: str) -> int:
106107 except RuntimeError as e :
107108 print (str (e ), file = sys .stderr )
108109 return 1
109-
110+
110111 result = subprocess .run ([str (binary )] + list (args ), check = False )
111112 return result .returncode
112113
0 commit comments