-
Notifications
You must be signed in to change notification settings - Fork 0
Patchcheck tmp2 #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Patchcheck tmp2 #14
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
| - uses: actions/setup-python@v4 | ||
| with: | ||
| python-version: "3.x" | ||
| - name: "Run patchcheck.py" | ||
| run: python ./Tools/patchcheck/patchcheck.py --ci true | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |||||
| import os.path | ||||||
| import subprocess | ||||||
| import sysconfig | ||||||
| from pathlib import Path | ||||||
|
|
||||||
| import reindent | ||||||
| import untabify | ||||||
|
|
@@ -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') | ||||||
|
|
||||||
|
|
||||||
|
|
@@ -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: | ||||||
|
|
@@ -175,6 +187,15 @@ def report_modified_files(file_paths): | |||||
| 'Tools/c-analyzer/cpython/_parser.py', | ||||||
| }) | ||||||
|
|
||||||
| #: Python files with bad syntax | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To avoid hardcoding filenames, we could skip the whole There was a problem hiding this comment. Choose a reason for hiding this commentThe 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): | ||||||
|
|
@@ -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)) | ||||||
| ) | ||||||
| ] | ||||||
|
|
@@ -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 | ||||||
|
|
@@ -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() | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.