From 606aa7318f5634f93a141ef96b9402aecd16c9e5 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Tue, 26 Sep 2023 11:26:01 +0100 Subject: [PATCH 1/4] Move the Python file whitespace check to pre-commit --- .pre-commit-config.yaml | 9 +++++++++ Tools/patchcheck/patchcheck.py | 16 +++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4c1fd20ea921b8..047a3730d14151 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -19,6 +19,15 @@ repos: - id: trailing-whitespace types_or: [c, python, rst] + - repo: local + hooks: + - id: python-file-whitespace + name: "Check Python file whitespace" + entry: "python Tools/patchcheck/reindent.py --nobackup --newline LF" + language: "system" + types: [python] + exclude: '^(Lib/test/tokenizedata/.*|Tools/c-analyzer/cpython/_parser.py)$' + - repo: https://github.com/sphinx-contrib/sphinx-lint rev: v0.6.8 hooks: diff --git a/Tools/patchcheck/patchcheck.py b/Tools/patchcheck/patchcheck.py index fa3a43af6e6048..edf5aa22171ed4 100755 --- a/Tools/patchcheck/patchcheck.py +++ b/Tools/patchcheck/patchcheck.py @@ -266,12 +266,10 @@ def ci(pull_request): return base_branch = get_base_branch() file_paths = changed_files(base_branch) - python_files = [fn for fn in file_paths if fn.endswith('.py')] c_files = [fn for fn in file_paths if fn.endswith(('.c', '.h'))] doc_files = [fn for fn in file_paths if fn.startswith('Doc') and fn.endswith(('.rst', '.inc'))] fixed = [] - fixed.extend(normalize_whitespace(python_files)) fixed.extend(normalize_c_whitespace(c_files)) fixed.extend(normalize_docs_whitespace(doc_files)) if not fixed: @@ -284,13 +282,10 @@ def ci(pull_request): def main(): base_branch = get_base_branch() file_paths = changed_files(base_branch) - python_files = [fn for fn in file_paths if fn.endswith('.py')] c_files = [fn for fn in file_paths if fn.endswith(('.c', '.h'))] doc_files = [fn for fn in file_paths if fn.startswith('Doc') and fn.endswith(('.rst', '.inc'))] misc_files = {p for p in file_paths if p.startswith('Misc')} - # PEP 8 whitespace rules enforcement. - normalize_whitespace(python_files) # C rules enforcement. normalize_c_whitespace(c_files) # Doc whitespace enforcement. @@ -307,10 +302,13 @@ def main(): regenerated_pyconfig_h_in(file_paths) # Test suite run and passed. - if python_files or c_files: - end = " and check for refleaks?" if c_files else "?" - print() - print("Did you run the test suite" + end) + has_c_files = any(fn for fn in file_paths if fn.endswith(('.c', '.h'))) + has_python_files = any(fn for fn in file_paths if fn.endswith('.py')) + print() + if has_c_files: + print("Did you run the test suite and check for refleaks?") + elif has_python_files: + print("Did you run the test suite?") if __name__ == '__main__': From d7160fdee37da22e279efcde636412e0d236331c Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Tue, 26 Sep 2023 11:32:56 +0100 Subject: [PATCH 2/4] Unused function --- Tools/patchcheck/patchcheck.py | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/Tools/patchcheck/patchcheck.py b/Tools/patchcheck/patchcheck.py index edf5aa22171ed4..89cedbda105f56 100755 --- a/Tools/patchcheck/patchcheck.py +++ b/Tools/patchcheck/patchcheck.py @@ -7,7 +7,6 @@ import subprocess import sysconfig -import reindent import untabify @@ -176,21 +175,6 @@ def report_modified_files(file_paths): }) -@status("Fixing Python file whitespace", info=report_modified_files) -def normalize_whitespace(file_paths): - """Make sure that the whitespace for .py files have been normalized.""" - reindent.makebackup = False # No need to create backups. - fixed = [ - path for path in file_paths - if ( - path.endswith('.py') - and path not in _PYTHON_FILES_WITH_TABS - and reindent.check(os.path.join(SRCDIR, path)) - ) - ] - return fixed - - @status("Fixing C file whitespace", info=report_modified_files) def normalize_c_whitespace(file_paths): """Report if any C files """ From 4adbd0d12b1af61cef7e0ea388c2f0ebb4cf8197 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Tue, 26 Sep 2023 11:38:11 +0100 Subject: [PATCH 3/4] Minor pattern update --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 047a3730d14151..eebb291ea63b9b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -26,7 +26,7 @@ repos: entry: "python Tools/patchcheck/reindent.py --nobackup --newline LF" language: "system" types: [python] - exclude: '^(Lib/test/tokenizedata/.*|Tools/c-analyzer/cpython/_parser.py)$' + exclude: '^(Lib/test/tokenizedata/|Tools/c-analyzer/cpython/_parser).*$' - repo: https://github.com/sphinx-contrib/sphinx-lint rev: v0.6.8 From 7b99698b0882b75ec7c94bf7dd2533306a9f6b48 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Tue, 26 Sep 2023 11:39:04 +0100 Subject: [PATCH 4/4] quotes --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index eebb291ea63b9b..393faa949e938a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -23,8 +23,8 @@ repos: hooks: - id: python-file-whitespace name: "Check Python file whitespace" - entry: "python Tools/patchcheck/reindent.py --nobackup --newline LF" - language: "system" + entry: 'python Tools/patchcheck/reindent.py --nobackup --newline LF' + language: 'system' types: [python] exclude: '^(Lib/test/tokenizedata/|Tools/c-analyzer/cpython/_parser).*$'