summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimeon Simeonov2018-09-13 23:45:55 +0200
committerSimeon Simeonov2018-09-13 23:45:55 +0200
commit0361a966ed1f8bc8fcf024e211ed35097d6cffa3 (patch)
tree16a7f249dcc7ba37aea1129d0c79dc78e43e87ed
parentc0259c87a7a2343a21634e038a50ff549bc975e5 (diff)
Use pygit2 instead of gitapi and flake8 instead of pep8
-rwxr-xr-xpygitchecker.py42
1 files changed, 29 insertions, 13 deletions
diff --git a/pygitchecker.py b/pygitchecker.py
index 29c9167..77f85ec 100755
--- a/pygitchecker.py
+++ b/pygitchecker.py
@@ -3,8 +3,30 @@
3import argparse 3import argparse
4import sys 4import sys
5 5
6import gitapi 6import pygit2
7import pep8 7
8from flake8.api import legacy as flake8_legacy
9
10
11def fetch_git_files(args):
12 """
13 Fetches new and modified .py-files using pygit2
14 """
15 repo = pygit2.Repository(args.repo_path)
16 status = repo.status()
17 git_files_list = list()
18 if not status:
19 return git_files_list
20 for gfile, state in status.items():
21 if (
22 state in (pygit2.GIT_STATUS_WT_MODIFIED,
23 pygit2.GIT_STATUS_WT_NEW,
24 pygit2.GIT_STATUS_INDEX_NEW,
25 pygit2.GIT_STATUS_INDEX_MODIFIED) and
26 gfile.lower().endswith('.py')
27 ):
28 git_files_list.append(gfile)
29 return git_files_list
8 30
9 31
10if __name__ == '__main__': 32if __name__ == '__main__':
@@ -23,16 +45,10 @@ if __name__ == '__main__':
23 default=False, 45 default=False,
24 help='Disable pep8 checks') 46 help='Disable pep8 checks')
25 args = parser.parse_args() 47 args = parser.parse_args()
26 git_repo = gitapi.Repo(args.repo_path) 48 git_files = fetch_git_files(args)
27 status = git_repo.git_status() 49 if not git_files:
28 if 'M' not in status:
29 print('No modifications') 50 print('No modifications')
30 sys.exit(0) 51 sys.exit(0)
31 remarks = False 52 report = flake8_legacy.get_style_guide().check_files(git_files)
32 for mfile in status.get('M'): 53 if report.total_errors:
33 if not args.disable_pep8: 54 print('Total errors: {errors}'.format(errors=report.total_errors))
34 checker = pep8.Checker(mfile)
35 if checker.check_all():
36 remarks = True
37 if remarks:
38 print('Done!')