-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpre_commit_checks.py
More file actions
executable file
·68 lines (56 loc) · 1.94 KB
/
pre_commit_checks.py
File metadata and controls
executable file
·68 lines (56 loc) · 1.94 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python3
"""
Pre-commit checks script.
Run this before submitting a pull request
"""
import os
import subprocess
import sys
def run_command(command, description):
"""Run a command and handle errors."""
print(f"🔍 {description}...")
try:
result = subprocess.run(command, shell=True, check=True, capture_output=True, text=True)
if result.stdout:
print(result.stdout)
print(f"✅ {description} complete")
return True
except subprocess.CalledProcessError as e:
print(f"❌ {description} failed")
if e.stdout:
print("STDOUT:", e.stdout)
if e.stderr:
print("STDERR:", e.stderr)
return False
def main():
"""Main function to run all pre-commit checks."""
print("🔍 Running pre-commit checks...")
print("=" * 50)
# Change to script directory
script_dir = os.path.dirname(os.path.abspath(__file__))
os.chdir(script_dir)
print(f"📁 Working directory: {os.getcwd()}")
print()
checks = [
("black .", "Running black to format code"),
("isort .", "Running isort to sort imports"),
("autoflake8 . --in-place -r -v", "Running autoflake8 to remove unused imports and variables"),
("flake8 .", "Running flake8 for linting"),
("interrogate .", "Running interrogate for documentation coverage"),
("coverage run -m unittest discover && coverage report", "Running tests with coverage"),
]
all_passed = True
for command, description in checks:
if not run_command(command, description):
all_passed = False
break
print()
if all_passed:
print("🎉 All pre-commit checks passed!")
print("Your code is ready for pull request submission.")
sys.exit(0)
else:
print("💥 Some checks failed. Please fix the issues and try again.")
sys.exit(1)
if __name__ == "__main__":
main()