mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-07 20:26:54 +00:00
pre-commit-hooks: python3.6+
This commit is contained in:
parent
551d1a07b3
commit
f5c42a050b
60 changed files with 291 additions and 493 deletions
|
|
@ -1,20 +1,16 @@
|
|||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
from typing import IO
|
||||
from typing import Optional
|
||||
from typing import Sequence
|
||||
|
||||
|
||||
def fix_file(file_obj): # type: (IO[bytes]) -> int
|
||||
def fix_file(file_obj: IO[bytes]) -> int:
|
||||
# Test for newline at end of file
|
||||
# Empty files will throw IOError here
|
||||
try:
|
||||
file_obj.seek(-1, os.SEEK_END)
|
||||
except IOError:
|
||||
except OSError:
|
||||
return 0
|
||||
last_character = file_obj.read(1)
|
||||
# last_character will be '' for an empty file
|
||||
|
|
@ -52,7 +48,7 @@ def fix_file(file_obj): # type: (IO[bytes]) -> int
|
|||
return 0
|
||||
|
||||
|
||||
def main(argv=None): # type: (Optional[Sequence[str]]) -> int
|
||||
def main(argv: Optional[Sequence[str]] = None) -> int:
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('filenames', nargs='*', help='Filenames to fix')
|
||||
args = parser.parse_args(argv)
|
||||
|
|
@ -64,11 +60,11 @@ def main(argv=None): # type: (Optional[Sequence[str]]) -> int
|
|||
with open(filename, 'rb+') as file_obj:
|
||||
ret_for_file = fix_file(file_obj)
|
||||
if ret_for_file:
|
||||
print('Fixing {}'.format(filename))
|
||||
print(f'Fixing {filename}')
|
||||
retv |= ret_for_file
|
||||
|
||||
return retv
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
||||
exit(main())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue