first commit
This commit is contained in:
commit
417e54da96
5696 changed files with 900003 additions and 0 deletions
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,109 @@
|
|||
import sys
|
||||
from os import walk
|
||||
from os.path import isdir, join, normpath
|
||||
|
||||
import pep8
|
||||
|
||||
|
||||
pep8_ignores = (
|
||||
'E125', # continuation line does not
|
||||
# distinguish itself from next logical line
|
||||
'E126', # continuation line over-indented for hanging indent
|
||||
'E127', # continuation line over-indented for visual indent
|
||||
'E128', # continuation line under-indented for visual indent
|
||||
'E402', # module level import not at top of file
|
||||
'E741', # ambiguous variable name
|
||||
'E731', # do not assign a lambda expression, use a def
|
||||
'W503', # allow putting binary operators after line split
|
||||
)
|
||||
|
||||
|
||||
class KivyStyleChecker(pep8.Checker):
|
||||
|
||||
def __init__(self, filename):
|
||||
pep8.Checker.__init__(self, filename, ignore=pep8_ignores)
|
||||
|
||||
def report_error(self, line_number, offset, text, check):
|
||||
return pep8.Checker.report_error(
|
||||
self, line_number, offset, text, check)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print("DEPRECATED: Use pre-commit.com framework instead: ",
|
||||
"pip install pre-commit && make hook")
|
||||
|
||||
def usage():
|
||||
print('Usage: python pep8kivy.py <file_or_folder_to_check>*')
|
||||
print('Folders will be checked recursively.')
|
||||
sys.exit(1)
|
||||
|
||||
if len(sys.argv) < 2:
|
||||
usage()
|
||||
elif sys.argv == 2:
|
||||
targets = sys.argv[-1]
|
||||
else:
|
||||
targets = sys.argv[-1].split()
|
||||
|
||||
def check(fn):
|
||||
try:
|
||||
checker = KivyStyleChecker(fn)
|
||||
except IOError:
|
||||
# File couldn't be opened, so was deleted apparently.
|
||||
# Don't check deleted files.
|
||||
return 0
|
||||
return checker.check_all()
|
||||
|
||||
errors = 0
|
||||
|
||||
exclude_dirs = [
|
||||
'kivy/lib',
|
||||
'kivy/deps',
|
||||
'kivy/tools/pep8checker',
|
||||
'coverage',
|
||||
'doc'
|
||||
]
|
||||
exclude_dirs = [normpath(i) for i in exclude_dirs]
|
||||
exclude_files = [
|
||||
'kivy/gesture.py',
|
||||
'kivy/tools/stub-gl-debug.py',
|
||||
'kivy/modules/webdebugger.py',
|
||||
'kivy/modules/_webdebugger.py'
|
||||
]
|
||||
exclude_files = [normpath(i) for i in exclude_files]
|
||||
|
||||
for target in targets:
|
||||
if isdir(target):
|
||||
for dirpath, dirnames, filenames in walk(target):
|
||||
cont = False
|
||||
dpath = normpath(dirpath)
|
||||
for pat in exclude_dirs:
|
||||
if dpath.startswith(pat):
|
||||
cont = True
|
||||
break
|
||||
if cont:
|
||||
continue
|
||||
for filename in filenames:
|
||||
if not filename.endswith('.py'):
|
||||
continue
|
||||
cont = False
|
||||
complete_filename = join(dirpath, filename)
|
||||
for pat in exclude_files:
|
||||
if complete_filename.endswith(pat):
|
||||
cont = True
|
||||
if cont:
|
||||
continue
|
||||
|
||||
errors += check(complete_filename)
|
||||
|
||||
else:
|
||||
# Got a single file to check
|
||||
for pat in exclude_dirs + exclude_files:
|
||||
if pat in target:
|
||||
break
|
||||
else:
|
||||
if target.endswith('.py'):
|
||||
errors += check(target)
|
||||
|
||||
if errors:
|
||||
print("Error: {} style guide violation(s) encountered.".format(errors))
|
||||
sys.exit(1)
|
|
@ -0,0 +1,80 @@
|
|||
#!/usr/bin/env python
|
||||
'''
|
||||
Kivy Git Pre-Commit Hook to Enforce Styleguide
|
||||
==============================================
|
||||
|
||||
DEPRECATED: Use pre-commit.com framework instead:
|
||||
`pip install pre-commit && make hook`
|
||||
|
||||
This script is not supposed to be run directly.
|
||||
Instead, copy it to your kivy/.git/hooks/ directory, call it 'pre-commit'
|
||||
and make it executable.
|
||||
|
||||
If you attempt to commit, git will run this script, which in turn will run
|
||||
the styleguide checker over your code and abort the commit if there are any
|
||||
errors. If that happens, please fix & retry.
|
||||
|
||||
To install::
|
||||
|
||||
cp kivy/tools/pep8checker/pre-commit.githook .git/hooks/pre-commit
|
||||
chmod +x .git/hooks/pre-commit
|
||||
'''
|
||||
|
||||
import os
|
||||
import sys
|
||||
from os.path import dirname, abspath, sep, join
|
||||
from subprocess import call, Popen, PIPE
|
||||
|
||||
curdir = dirname(abspath(__file__))
|
||||
kivydir = sep.join(curdir.split(sep)[:-2])
|
||||
srcdir = join(kivydir, 'kivy')
|
||||
script = join(srcdir, 'tools', 'pep8checker', 'pep8kivy.py')
|
||||
try:
|
||||
with open(script):
|
||||
pass
|
||||
except IOError:
|
||||
# if this not the kivy project, find the script file in the kivy project
|
||||
os.environ['KIVY_NO_CONSOLELOG'] = '1'
|
||||
import kivy
|
||||
script = join(dirname(kivy.__file__), 'tools', 'pep8checker', 'pep8kivy.py')
|
||||
srcdir = ''
|
||||
|
||||
# Only check the files that were staged
|
||||
# proc = Popen(['git', 'diff', '--cached', '--name-only', 'HEAD'], stdout=PIPE)
|
||||
# targets = [join(kivydir, target) for target in proc.stdout]
|
||||
|
||||
# Correction: only check the files that were staged, but do not include
|
||||
# deleted files.
|
||||
proc = Popen(['git', 'diff', '--cached', '--name-status', 'HEAD'], stdout=PIPE)
|
||||
proc.wait()
|
||||
|
||||
# This gives output like the following:
|
||||
#
|
||||
# A examples/widgets/lists/list_simple_in_kv.py
|
||||
# A examples/widgets/lists/list_simple_in_kv_2.py
|
||||
# D kivy/uix/observerview.py
|
||||
#
|
||||
# So check for D entries and remove them from targets.
|
||||
#
|
||||
targets = []
|
||||
for target in proc.stdout:
|
||||
parts = [p.strip() for p in target.split()]
|
||||
if parts[0] != 'D':
|
||||
targets.append(join(kivydir, target.decode(encoding='UTF-8')))
|
||||
|
||||
# Untested possibility: After making the changes above for removing deleted
|
||||
# files from targets, saw also where the git diff call could be:
|
||||
#
|
||||
# git diff --cached --name-only --diff-filter=ACM
|
||||
# (leaving off D)
|
||||
#
|
||||
# and we could then remove the special handling in python for targets above.
|
||||
|
||||
call(['git', 'stash', 'save', '--keep-index', '--quiet'])
|
||||
retval = call([sys.executable, script, srcdir] + targets)
|
||||
call(['git', 'stash', 'pop', '--quiet'])
|
||||
|
||||
if retval:
|
||||
# There are style guide violations
|
||||
print("Your commit has been aborted. Please fix the violations and retry.")
|
||||
sys.exit(1)
|
Loading…
Add table
Add a link
Reference in a new issue