From 56c30b72414bf7f3c01b91010a67c84c2a9e5d18 Mon Sep 17 00:00:00 2001 From: sirlilpanda Date: Fri, 23 Jan 2026 14:41:24 +1300 Subject: [PATCH] hooks setup script --- setup.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 setup.py diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..db860b1 --- /dev/null +++ b/setup.py @@ -0,0 +1,28 @@ +import sys +import os +import stat +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 + ]) + +# make sure its executable +st = os.stat(HOOK_PATH) +os.chmod(HOOK_PATH, st.st_mode | stat.S_IEXEC) \ No newline at end of file