Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/[email protected]

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

steps:
- uses: actions/checkout@v4
with:
show-progress: false
Comment on lines +34 to +35
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#: Python files with bad syntax
# Python files with bad syntax

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copied the style from the above (this is the style Sphinx uses for documentation comments, but unsure why the above used it)

_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',
Comment on lines +192 to +195
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid hardcoding filenames, we could skip the whole tokenizedata directory, as we did in python#109513.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine by me!

'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()