From 8baa8a0bf055f0762c0fd7a1c7d93c17c66b601b Mon Sep 17 00:00:00 2001 From: Firdaus Hakimi Date: Tue, 19 Mar 2024 00:50:12 +0800 Subject: [PATCH 1/6] Import install_hook.py from yeet-api --- install_hook.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 install_hook.py diff --git a/install_hook.py b/install_hook.py new file mode 100644 index 0000000..f6a1483 --- /dev/null +++ b/install_hook.py @@ -0,0 +1,21 @@ +# SPDX-License-Identifier + +from pathlib import Path + +SCRIPT = r"""#!/bin/sh +set -o noglob + +poetry run install-hook + +python -m black . + +for file in $(git diff --cached --name-only); do + test -f $file && git add $file +done""" + + +def main() -> None: + print("Installing pre-commit hook") + with open(".git/hooks/pre-commit", "w") as f: + f.write(SCRIPT) + Path(".git/hooks/pre-commit").chmod(0o700) From b40e0a47357b1a226fb27ba17a4d5db847f9c995 Mon Sep 17 00:00:00 2001 From: Firdaus Hakimi Date: Tue, 19 Mar 2024 00:52:26 +0800 Subject: [PATCH 2/6] install_hook: Run black using poetry --- install_hook.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/install_hook.py b/install_hook.py index f6a1483..cd42304 100644 --- a/install_hook.py +++ b/install_hook.py @@ -1,5 +1,7 @@ # SPDX-License-Identifier +import os + from pathlib import Path SCRIPT = r"""#!/bin/sh @@ -7,7 +9,7 @@ poetry run install-hook -python -m black . +poetry run black . for file in $(git diff --cached --name-only); do test -f $file && git add $file @@ -18,4 +20,7 @@ def main() -> None: print("Installing pre-commit hook") with open(".git/hooks/pre-commit", "w") as f: f.write(SCRIPT) + + print(f"Installing dev dependencies (for black)") + os.system("poetry install --with dev") Path(".git/hooks/pre-commit").chmod(0o700) From 28bad93797f05564bfe19971a9e0307a1e9f9684 Mon Sep 17 00:00:00 2001 From: Firdaus Hakimi Date: Tue, 19 Mar 2024 00:54:47 +0800 Subject: [PATCH 3/6] install_hook: Move under scripts/ --- install_hook.py => scripts/install_hook.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename install_hook.py => scripts/install_hook.py (100%) diff --git a/install_hook.py b/scripts/install_hook.py similarity index 100% rename from install_hook.py rename to scripts/install_hook.py From 8bbc2b704d4b5e9e437d8ad7cf80b244baa26bbc Mon Sep 17 00:00:00 2001 From: Firdaus Hakimi Date: Tue, 19 Mar 2024 00:58:08 +0800 Subject: [PATCH 4/6] scripts: install_hook: Run main manually --- scripts/install_hook.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/install_hook.py b/scripts/install_hook.py index cd42304..96c90bf 100644 --- a/scripts/install_hook.py +++ b/scripts/install_hook.py @@ -24,3 +24,6 @@ def main() -> None: print(f"Installing dev dependencies (for black)") os.system("poetry install --with dev") Path(".git/hooks/pre-commit").chmod(0o700) + + +main() From d6cff80efe01204a1999aa1af6abc97b53fb2a59 Mon Sep 17 00:00:00 2001 From: Firdaus Hakimi Date: Tue, 19 Mar 2024 01:18:35 +0800 Subject: [PATCH 5/6] scripts: install_hook: Remove malformed license header --- scripts/install_hook.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/install_hook.py b/scripts/install_hook.py index 96c90bf..0ce0ad6 100644 --- a/scripts/install_hook.py +++ b/scripts/install_hook.py @@ -1,5 +1,3 @@ -# SPDX-License-Identifier - import os from pathlib import Path From 7edee2f89f810b287312372e19ce8e4878da6c2c Mon Sep 17 00:00:00 2001 From: Firdaus Hakimi Date: Tue, 19 Mar 2024 01:20:38 +0800 Subject: [PATCH 6/6] scripts: install_hook: Adapt to non-poetry-scripts way of execution --- scripts/install_hook.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install_hook.py b/scripts/install_hook.py index 0ce0ad6..cdac741 100644 --- a/scripts/install_hook.py +++ b/scripts/install_hook.py @@ -5,7 +5,7 @@ SCRIPT = r"""#!/bin/sh set -o noglob -poetry run install-hook +python3 scripts/install_hook.py poetry run black .