mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
#9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
This commit is contained in:
parent
50de5f56a9
commit
a9afb68789
3 changed files with 68 additions and 33 deletions
|
@ -3,27 +3,12 @@
|
|||
# Make a reST file compliant to our pre-commit hook.
|
||||
# Currently just remove trailing whitespace.
|
||||
|
||||
import sys
|
||||
|
||||
import sys, re, shutil
|
||||
|
||||
ws_re = re.compile(br'\s+(\r?\n)$')
|
||||
import patchcheck
|
||||
|
||||
def main(argv=sys.argv):
|
||||
rv = 0
|
||||
for filename in argv[1:]:
|
||||
try:
|
||||
with open(filename, 'rb') as f:
|
||||
lines = f.readlines()
|
||||
new_lines = [ws_re.sub(br'\1', line) for line in lines]
|
||||
if new_lines != lines:
|
||||
print('Fixing %s...' % filename)
|
||||
shutil.copyfile(filename, filename + '.bak')
|
||||
with open(filename, 'wb') as f:
|
||||
f.writelines(new_lines)
|
||||
except Exception as err:
|
||||
print('Cannot fix %s: %s' % (filename, err))
|
||||
rv = 1
|
||||
return rv
|
||||
patchcheck.normalize_docs_whitespace(argv[1:])
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue