-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathpack
More file actions
executable file
·54 lines (45 loc) · 2.29 KB
/
pack
File metadata and controls
executable file
·54 lines (45 loc) · 2.29 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
49
50
51
52
53
54
#!/usr/bin/env python3
import os
import sys
import subprocess
import platform
import venv_manager
def main():
try:
# Path to the actual pack.py application script
pack_py_target_script = os.path.join(venv_manager.CLIPPY_DIR, "pack.py")
if not os.path.isfile(pack_py_target_script):
print(f"Error: The target script '{pack_py_target_script}' was not found.", file=sys.stderr)
sys.exit(1)
# Ensure the virtual environment is set up and get the Python executable from it
venv_python_executable = venv_manager.ensure_venv(
venv_manager.CLIPPY_DIR)
# Arguments to pass to pack.py (all arguments passed to this launcher)
args_for_pack_py = sys.argv[1:]
command = [venv_python_executable, pack_py_target_script] + args_for_pack_py
# Execute pack.py using the venv's Python.
# os.execv replaces the current process with the new one (mimics bash `exec`).
if platform.system() == "Windows":
# os.execv can be less straightforward on Windows for interpreted scripts.
# subprocess.run achieves a similar outcome by waiting for the process
# and then exiting with its return code.
process = subprocess.run(command, check=False) # check=False to allow pack.py to control exit code
sys.exit(process.returncode)
else:
os.execv(command[0], command)
# If os.execv returns, it means an error occurred (e.g., executable not found)
# This part is typically not reached on success.
print(f"Error: os.execv failed to execute '{command[0]}'.", file=sys.stderr)
sys.exit(127) # Typical exit code for command not found
except FileNotFoundError as e:
print(f"Error: A required file or executable was not found. {e}", file=sys.stderr)
sys.exit(1)
except subprocess.CalledProcessError as e:
# This handles errors from ensure_venv if check=True leads to an exception there.
print(f"An error occurred during setup or execution: {e}", file=sys.stderr)
sys.exit(e.returncode if e.returncode is not None else 1)
except Exception as e:
print(f"An unexpected error occurred: {e}", file=sys.stderr)
sys.exit(1)
if __name__ == "__main__":
main()