-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprepare-commit-msg
More file actions
45 lines (34 loc) · 1.23 KB
/
prepare-commit-msg
File metadata and controls
45 lines (34 loc) · 1.23 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
"""
Git hook wrapper that ensures the virtual environment is activated
before running the commit message generator.
"""
import os
import sys
import subprocess
from pathlib import Path
def get_venv_python():
"""Get the path to the Python executable in the virtual environment."""
script_dir = Path(__file__).parent.absolute()
venv_dir = script_dir / "venv"
if os.name == 'nt': # Windows
python_exe = venv_dir / "Scripts" / "python.exe"
else: # Unix-like
python_exe = venv_dir / "bin" / "python"
return python_exe
def main():
"""Run the main script using the virtual environment Python."""
venv_python = get_venv_python()
if not venv_python.exists():
print("Virtual environment not found. Please run setup.py first.", file=sys.stderr)
sys.exit(1)
script_dir = Path(__file__).parent.absolute()
main_script = script_dir / "main.py"
cmd = [str(venv_python), str(main_script)] + sys.argv[1:]
try:
result = subprocess.run(cmd, check=False)
sys.exit(result.returncode)
except Exception as e:
print(f"Error running commit message generator: {e}", file=sys.stderr)
sys.exit(1)
if __name__ == "__main__":
main()