Skip to content
Prev Previous commit
Next Next commit
Fix tabs when run locally
  • Loading branch information
AA-Turner committed Sep 26, 2023
commit 0e20e9f090ff48dd643d33a14058a69b476fac0f
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ repos:
hooks:
- id: c-file-whitespace
name: "Check C file whitespace"
language: pygrep
entry: '\t'
entry: "python Tools/patchcheck/untabify.py"
language: "system"
types_or: ['c', 'c++']
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We were running on .c and .h files before:

c_files = [fn for fn in file_paths if fn.endswith(('.c', '.h'))]

Both of those are matched by the c type, so this would be closer to parity:

Suggested change
types_or: ['c', 'c++']
types_or: [c]

We do have half a dozen .cpp files in the codebase, do we want to expand to include them? Should we also add c++ for trailing-whitespace above?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The test passed with 'c++' included, I imagined that it was a previous oversight that they weren't included. I'll check if the trailing whitespace check also passes.

Copy link
Copy Markdown
Member Author

@AA-Turner AA-Turner Sep 26, 2023

Choose a reason for hiding this comment

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

Tools/msi/bundle/bootstrap/PythonBootstrapperApplication.cpp fails with 16 lines changed. Other than that all good (@zooba would you be alright with us enabling the trailing whitespace check here? No real views either way, if you'd prefer to keep the whitespace then that's the status quo anyway!)

A

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(We can always remove c++ later if needed.)

# Don't check the style of copies directories containing external libraries
Comment thread
hugovk marked this conversation as resolved.
Outdated
exclude: '^Modules/(_decimal/libmpdec|expat|zlib)/.*$'
Comment thread
AA-Turner marked this conversation as resolved.
Outdated
Expand Down
7 changes: 4 additions & 3 deletions Tools/patchcheck/untabify.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ def process(filename, tabsize, verbose=True):
encoding = f.encoding
except IOError as msg:
print("%r: I/O error: %s" % (filename, msg))
return
return 2
newtext = text.expandtabs(tabsize)
if newtext == text:
return
return 0
backup = filename + "~"
try:
os.unlink(backup)
Expand All @@ -49,7 +49,8 @@ def process(filename, tabsize, verbose=True):
f.write(newtext)
if verbose:
print(filename)
return 1


if __name__ == '__main__':
main()
raise SystemExit(main())
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

process() now has return values, which go to main(), but main() always returns None so we never get any errors here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oh, I didn't realise! pre-commit was failing in my local testing when I introduced tabs, perhaps it just fails when a file is changed after the hook has run.