basic script for configuring git hooks

This commit is contained in:
2025-12-31 12:24:40 +13:00
parent bca6632809
commit 049ef7f27f

23
setup.py Normal file
View File

@@ -0,0 +1,23 @@
import sys
import os
from pathlib import Path
PYTHON_BIN = sys.executable
HOOK_SCRIPT_PATH = Path(".hooks/kicad_cli_tools.py")
HOOK_TYPE = "pre-push"
HOOK_PATH = Path(f".git/hooks/{HOOK_TYPE}")
# used if the hook path already exists we dont want to over write anything you have in there
# we would append however all of the default hooks have and `exit 0` which means it wont run
OLD_HOOK_PATH = Path(f".git/hooks/{HOOK_TYPE}-old")
if (os.path.exists(HOOK_PATH)):
os.rename(HOOK_PATH, OLD_HOOK_PATH)
with open(HOOK_PATH, "w") as txt:
txt.writelines([
"#!/bin/sh\n", #shebang
f"{PYTHON_BIN} {HOOK_SCRIPT_PATH}\n"
"exit 0\n" #make sure she closes
])