Skip to content

Commit

Permalink
Run patchcheck in GitHub Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed Sep 17, 2023
1 parent 8ea4ad4 commit 5ad4faf
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,17 @@ jobs:
with:
python-version: "3.x"
- uses: pre-commit/action@v3.0.0

patchcheck:
runs-on: ubuntu-latest
timeout-minutes: 10

steps:
- uses: actions/checkout@v4
with:
show-progress: false
- uses: actions/setup-python@v4
with:
python-version: "3.x"
- name: "Run patchcheck.py"
run: python ./Tools/patchcheck/patchcheck.py --ci true
35 changes: 28 additions & 7 deletions Tools/patchcheck/patchcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import os.path
import subprocess
import sysconfig
from pathlib import Path

import reindent
import untabify
Expand All @@ -14,10 +15,10 @@
# Excluded directories which are copies of external libraries:
# don't check their coding style
EXCLUDE_DIRS = [
os.path.join('Modules', '_decimal', 'libmpdec'),
os.path.join('Modules', 'expat'),
os.path.join('Modules', 'zlib'),
]
'Modules/_decimal/libmpdec',
'Modules/expat',
'Modules/zlib',
]
SRCDIR = sysconfig.get_config_var('srcdir')


Expand Down Expand Up @@ -159,6 +160,17 @@ def changed_files(base_branch=None):
return filenames2


@status("Getting the list of all files",
info=lambda x: n_files_str(len(x)))
def all_files():
return [
file for path in Path(SRCDIR).rglob("*")
if (file := path.resolve().relative_to(SRCDIR).as_posix())
and not any(file.startswith(path) for path in EXCLUDE_DIRS)
]



def report_modified_files(file_paths):
count = len(file_paths)
if count == 0:
Expand All @@ -175,6 +187,15 @@ def report_modified_files(file_paths):
'Tools/c-analyzer/cpython/_parser.py',
})

#: Python files with bad syntax
_PYTHON_SYNTAX_PROBLEMS = frozenset({
'Lib/test/tokenizedata/bad_coding.py',
'Lib/test/tokenizedata/bad_coding2.py',
'Lib/test/tokenizedata/badsyntax_3131.py',
'Lib/test/tokenizedata/coding20731.py',
'Lib/test/badsyntax_pep3120.py'
})


@status("Fixing Python file whitespace", info=report_modified_files)
def normalize_whitespace(file_paths):
Expand All @@ -184,7 +205,7 @@ def normalize_whitespace(file_paths):
path for path in file_paths
if (
path.endswith('.py')
and path not in _PYTHON_FILES_WITH_TABS
and path not in _PYTHON_FILES_WITH_TABS | _PYTHON_SYNTAX_PROBLEMS
and reindent.check(os.path.join(SRCDIR, path))
)
]
Expand Down Expand Up @@ -264,8 +285,7 @@ def ci(pull_request):
if pull_request == 'false':
print('Not a pull request; skipping')
return
base_branch = get_base_branch()
file_paths = changed_files(base_branch)
file_paths = all_files()
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
Expand Down Expand Up @@ -320,6 +340,7 @@ def main():
help='Perform pass/fail checks')
args = parser.parse_args()
if args.ci:
SRCDIR = Path(__file__).resolve().parents[2].as_posix()
ci(args.ci)
else:
main()

0 comments on commit 5ad4faf

Please sign in to comment.