mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
[3.12] GH-109408: Move the C file whitespace check from patchcheck to pre-commit (GH-109890) (#110636)
(cherry picked from commit f5edb56328
)
This commit is contained in:
parent
948576574f
commit
c9157feeec
3 changed files with 23 additions and 90 deletions
|
@ -21,8 +21,7 @@ def main():
|
|||
if optname == '-t':
|
||||
tabsize = int(optvalue)
|
||||
|
||||
for filename in args:
|
||||
process(filename, tabsize)
|
||||
return max(process(filename, tabsize) for filename in args)
|
||||
|
||||
|
||||
def process(filename, tabsize, verbose=True):
|
||||
|
@ -32,10 +31,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)
|
||||
|
@ -49,7 +48,8 @@ def process(filename, tabsize, verbose=True):
|
|||
f.write(newtext)
|
||||
if verbose:
|
||||
print(filename)
|
||||
return 1
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
raise SystemExit(main())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue