-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
50 lines (41 loc) · 1.56 KB
/
setup.py
File metadata and controls
50 lines (41 loc) · 1.56 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
"""
Setup script for commit message generator.
Creates virtual environment and installs dependencies.
"""
import os
import sys
import subprocess
import venv
from pathlib import Path
def main():
script_dir = Path(__file__).parent.absolute()
venv_dir = script_dir / "venv"
print(f"Setting up virtual environment in {venv_dir}")
# Create virtual environment
if venv_dir.exists():
print("Virtual environment already exists. Removing old one...")
import shutil
shutil.rmtree(venv_dir)
print("Creating virtual environment...")
venv.create(venv_dir, with_pip=True)
# Determine the correct python executable path
if os.name == 'nt': # Windows
python_exe = venv_dir / "Scripts" / "python.exe"
pip_exe = venv_dir / "Scripts" / "pip.exe"
else: # Unix-like
python_exe = venv_dir / "bin" / "python"
pip_exe = venv_dir / "bin" / "pip"
# Install requirements
requirements_file = script_dir / "requirements.txt"
if requirements_file.exists():
print("Installing dependencies...")
subprocess.run([str(pip_exe), "install", "-r", str(requirements_file)], check=True)
else:
print("No requirements.txt found, skipping dependency installation")
print("Setup complete!")
print(f"Virtual environment created at: {venv_dir}")
print("\nTo use this script as a git hook:")
print("1. Copy or symlink this directory to your project's .git/hooks/")
print("2. Make sure the hook script is executable")
if __name__ == "__main__":
main()