@@ -10,60 +10,100 @@ def main():
1010 If the user does not pass a path, uses "." as default.
1111 """
1212
13- if not platform .system ().lower ().startswith ("win" ):
14- print (f"This platform { platform .system ()} is coming soon!" )
15- return 0
16-
17- # Prevent recursive re-invocation
18- if os .environ .get ("INITVENV_LAUNCHED" ) == "1" :
19- return 0
20-
21- pkg_root = Path (__file__ ).resolve ().parent
22- scripts_dir = pkg_root / "scripts"
13+ if platform .system ().lower ().startswith ("win" ):
14+ # Prevent recursive re-invocation
15+ if os .environ .get ("INITVENV_LAUNCHED" ) == "1" :
16+ return 0
2317
24- bat = scripts_dir / "initvenv.bat"
25- exe = scripts_dir / "initvenv.exe "
18+ pkg_root = Path ( __file__ ). resolve (). parent
19+ scripts_dir = pkg_root / "scripts "
2620
27- if not bat .exists () and not exe .exists ():
28- pkg_root_up = pkg_root .parent
29- scripts_dir = pkg_root_up / "scripts"
3021 bat = scripts_dir / "initvenv.bat"
3122 exe = scripts_dir / "initvenv.exe"
3223
33- # If no path provided, default to current directory "."
34- user_args = sys .argv [1 :]
35- if not user_args :
36- target = "."
37- else :
38- target = user_args [0 ]
24+ if not bat .exists () and not exe .exists ():
25+ pkg_root_up = pkg_root .parent
26+ scripts_dir = pkg_root_up / "scripts"
27+ bat = scripts_dir / "initvenv.bat"
28+ exe = scripts_dir / "initvenv.exe"
3929
40- env = os .environ .copy ()
41- env ["INITVENV_LAUNCHED" ] = "1"
30+ # If no path provided, default to current directory "."
31+ user_args = sys .argv [1 :]
32+ if not user_args :
33+ target = "."
34+ else :
35+ target = user_args [0 ]
4236
43- cmd = os .environ .get ("COMSPEC" , "cmd.exe" )
37+ env = os .environ .copy ()
38+ env ["INITVENV_LAUNCHED" ] = "1"
4439
45- if bat .exists ():
46- bat_path = str (bat )
47- argv = [cmd , "/c" , bat_path , target ]
48- try :
49- subprocess .run (argv , check = True , env = env )
40+ cmd = os .environ .get ("COMSPEC" , "cmd.exe" )
41+
42+ if bat .exists ():
43+ bat_path = str (bat )
44+ argv = [cmd , "/c" , bat_path , target ]
45+ try :
46+ subprocess .run (argv , check = True , env = env )
47+ return 0
48+ except subprocess .CalledProcessError as e :
49+ print (f"Error executing { bat } : { e } " , file = sys .stderr )
50+ return e .returncode
51+
52+ if exe .exists ():
53+ exe_path = str (exe )
54+ argv = [exe_path , target ]
55+ try :
56+ subprocess .run (argv , check = True , env = env )
57+ return 0
58+ except subprocess .CalledProcessError as e :
59+ print (f"Error executing { exe } : { e } " , file = sys .stderr )
60+ return e .returncode
61+
62+ print ("Error: neither initvenv.bat nor initvenv.exe were found in package scripts/" , file = sys .stderr )
63+ return 2
64+ elif platform .system ().lower () == "linux" :
65+ # Prevent recursive re-invocation
66+ if os .environ .get ("INITVENV_LAUNCHED" ) == "1" :
5067 return 0
51- except subprocess .CalledProcessError as e :
52- print (f"Error executing { bat } : { e } " , file = sys .stderr )
53- return e .returncode
5468
55- if exe .exists ():
56- exe_path = str (exe )
57- argv = [exe_path , target ]
69+ # Detect architecture
70+ machine = platform .machine ().lower ()
71+ if machine in ["x86_64" , "amd64" ]:
72+ arch = "x64"
73+ elif machine in ["aarch64" , "arm64" ]:
74+ arch = "arm64"
75+ else :
76+ print (f"Unsupported architecture: { machine } " , file = sys .stderr )
77+ return 1
78+
79+ pkg_root = Path (__file__ ).resolve ().parent
80+ bin_dir = pkg_root / "bin" / f"linux-{ arch } "
81+ binary = bin_dir / "initVenv"
82+
83+ if not binary .exists ():
84+ print (f"Error: Binary not found at { binary } " , file = sys .stderr )
85+ return 2
86+
87+ # If no path provided, default to current directory "."
88+ user_args = sys .argv [1 :]
89+ if not user_args :
90+ target = "."
91+ else :
92+ target = user_args [0 ]
93+
94+ env = os .environ .copy ()
95+ env ["INITVENV_LAUNCHED" ] = "1"
96+
97+ argv = [str (binary ), target ]
5898 try :
5999 subprocess .run (argv , check = True , env = env )
60100 return 0
61101 except subprocess .CalledProcessError as e :
62- print (f"Error executing { exe } : { e } " , file = sys .stderr )
102+ print (f"Error executing { binary } : { e } " , file = sys .stderr )
63103 return e .returncode
64-
65- print ("Error: neither initvenv.bat nor initvenv.exe were found in package scripts/" , file = sys . stderr )
66- return 2
104+ else :
105+ print (f"This platform { platform . system () } is coming soon!" )
106+ return 0
67107
68108if __name__ == "__main__" :
69109 sys .exit (main ())
0 commit comments