mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-06 20:16:53 +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,13 +1,7 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import math
|
||||
import os
|
||||
from typing import Iterable
|
||||
from typing import Optional
|
||||
from typing import Sequence
|
||||
from typing import Set
|
||||
|
|
@ -17,7 +11,7 @@ from pre_commit_hooks.util import CalledProcessError
|
|||
from pre_commit_hooks.util import cmd_output
|
||||
|
||||
|
||||
def lfs_files(): # type: () -> Set[str]
|
||||
def lfs_files() -> Set[str]:
|
||||
try:
|
||||
# Introduced in git-lfs 2.2.0, first working in 2.2.1
|
||||
lfs_ret = cmd_output('git', 'lfs', 'status', '--json')
|
||||
|
|
@ -27,23 +21,20 @@ def lfs_files(): # type: () -> Set[str]
|
|||
return set(json.loads(lfs_ret)['files'])
|
||||
|
||||
|
||||
def find_large_added_files(filenames, maxkb):
|
||||
# type: (Iterable[str], int) -> int
|
||||
def find_large_added_files(filenames: Sequence[str], maxkb: int) -> int:
|
||||
# Find all added files that are also in the list of files pre-commit tells
|
||||
# us about
|
||||
filenames = (added_files() & set(filenames)) - lfs_files()
|
||||
|
||||
retv = 0
|
||||
for filename in filenames:
|
||||
for filename in (added_files() & set(filenames)) - lfs_files():
|
||||
kb = int(math.ceil(os.stat(filename).st_size / 1024))
|
||||
if kb > maxkb:
|
||||
print('{} ({} KB) exceeds {} KB.'.format(filename, kb, maxkb))
|
||||
print(f'{filename} ({kb} KB) exceeds {maxkb} KB.')
|
||||
retv = 1
|
||||
|
||||
return retv
|
||||
|
||||
|
||||
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='*',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue