From 34fa8c15e3be5ad2a06410bae2cec77aab33c5c9 Mon Sep 17 00:00:00 2001 From: Dario Panici Date: Wed, 30 Oct 2024 14:40:12 -0400 Subject: [PATCH 1/4] change precommit so unmarked test check happens only if all other hooks pass --- .pre-commit-config.yaml | 7 +++++++ devtools/check_unmarked_tests.sh | 5 +++++ devtools/clean_logfiles.sh | 6 ++++++ 3 files changed, 18 insertions(+) mode change 100755 => 100644 devtools/check_unmarked_tests.sh create mode 100755 devtools/clean_logfiles.sh diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 76c9ea260d..fa90ac9fc7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,6 +3,7 @@ repos: rev: 24.3.0 hooks: - id: black-jupyter + log_file: devtools/pre-commit.log - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.3.0 hooks: @@ -37,3 +38,9 @@ repos: files: ^tests/ types: [python] pass_filenames: true + - repo: local + hooks: + - id: clean_logfiles + name: clean_logfiles + entry: devtools/clean_logfiles.sh + language: script diff --git a/devtools/check_unmarked_tests.sh b/devtools/check_unmarked_tests.sh old mode 100755 new mode 100644 index 08371f2119..564827783b --- a/devtools/check_unmarked_tests.sh +++ b/devtools/check_unmarked_tests.sh @@ -1,5 +1,10 @@ #!/bin/sh +if [ -f "pre-commit.log" ]; then + echo "Error in earlier pre-commit! Skipping unmarked tests check." + exit 1 +fi + # Start the timer using date (in seconds since epoch) start_time=$(date +%s) diff --git a/devtools/clean_logfiles.sh b/devtools/clean_logfiles.sh new file mode 100755 index 0000000000..54bcba686e --- /dev/null +++ b/devtools/clean_logfiles.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +if [ -f "pre-commit.log" ]; then + echo "delete pre-commit.log" + rm "pre-commit.log" +fi From 3699255ada5e0b6940fcdbd3b5aaa8aa4f5786a6 Mon Sep 17 00:00:00 2001 From: Dario Panici Date: Wed, 30 Oct 2024 14:41:58 -0400 Subject: [PATCH 2/4] update check_unmarked_tests permissions --- devtools/check_unmarked_tests.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 devtools/check_unmarked_tests.sh diff --git a/devtools/check_unmarked_tests.sh b/devtools/check_unmarked_tests.sh old mode 100644 new mode 100755 From 574f565e7f2ea4a45203612069e91a8f895dd6f8 Mon Sep 17 00:00:00 2001 From: Dario Panici Date: Wed, 30 Oct 2024 14:51:55 -0400 Subject: [PATCH 3/4] add log file to each hook --- .pre-commit-config.yaml | 10 ++++++++++ devtools/check_unmarked_tests.sh | 2 +- devtools/clean_logfiles.sh | 6 +++--- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fa90ac9fc7..88a87097ac 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,27 +8,37 @@ repos: rev: v4.3.0 hooks: - id: check-added-large-files + log_file: devtools/pre-commit.log - id: check-case-conflict + log_file: devtools/pre-commit.log - id: check-merge-conflict + log_file: devtools/pre-commit.log - id: detect-private-key + log_file: devtools/pre-commit.log - id: end-of-file-fixer + log_file: devtools/pre-commit.log - id: trailing-whitespace + log_file: devtools/pre-commit.log - id: no-commit-to-branch + log_file: devtools/pre-commit.log - repo: https://github.com/pycqa/isort rev: 5.12.0 hooks: - id: isort name: isort (python) args: ["--profile", "black"] + log_file: devtools/pre-commit.log - repo: https://github.com/PyCQA/flake8 rev: "5.0.4" hooks: - id: flake8 additional_dependencies: ["flake8-docstrings", "flake8-eradicate", "flake8-isort"] + log_file: devtools/pre-commit.log - repo: https://github.com/asottile/pyupgrade rev: v3.2.0 hooks: - id: pyupgrade + log_file: devtools/pre-commit.log - repo: local hooks: - id: check_unmarked_tests diff --git a/devtools/check_unmarked_tests.sh b/devtools/check_unmarked_tests.sh index 564827783b..ff51bd1651 100755 --- a/devtools/check_unmarked_tests.sh +++ b/devtools/check_unmarked_tests.sh @@ -1,6 +1,6 @@ #!/bin/sh -if [ -f "pre-commit.log" ]; then +if [ -f "devtools/pre-commit.log" ]; then echo "Error in earlier pre-commit! Skipping unmarked tests check." exit 1 fi diff --git a/devtools/clean_logfiles.sh b/devtools/clean_logfiles.sh index 54bcba686e..da82770dfa 100755 --- a/devtools/clean_logfiles.sh +++ b/devtools/clean_logfiles.sh @@ -1,6 +1,6 @@ #!/bin/sh -if [ -f "pre-commit.log" ]; then - echo "delete pre-commit.log" - rm "pre-commit.log" +if [ -f "devtools/pre-commit.log" ]; then + echo "delete devtools/pre-commit.log" + rm "devtools/pre-commit.log" fi From 9c0897366a3c48bfb94729adc6c19e487ddf7db3 Mon Sep 17 00:00:00 2001 From: Dario Panici <37969854+dpanici@users.noreply.github.com> Date: Wed, 30 Oct 2024 16:50:54 -0400 Subject: [PATCH 4/4] Update devtools/clean_logfiles.sh Co-authored-by: Yigit Gunsur Elmacioglu <102380275+YigitElma@users.noreply.github.com> --- devtools/clean_logfiles.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devtools/clean_logfiles.sh b/devtools/clean_logfiles.sh index da82770dfa..857f41655b 100755 --- a/devtools/clean_logfiles.sh +++ b/devtools/clean_logfiles.sh @@ -1,6 +1,6 @@ #!/bin/sh if [ -f "devtools/pre-commit.log" ]; then - echo "delete devtools/pre-commit.log" + echo "deleting devtools/pre-commit.log file..." rm "devtools/pre-commit.log" fi