forked from gitter-badger/Library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
executable file
·106 lines (84 loc) · 2.83 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env python3
""" Digital Library — a digital book management system
Copyright (C) 2015 Yuriy Syrovetskiy <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
from ast import literal_eval
from os import listdir
from subprocess import CalledProcessError, check_call, check_output
from sys import stderr
PEP8_OPTIONS = [
"--show-source",
"--ignore=" + ','.join([
'E251', # unexpected spaces around keyword / parameter equals
'E402', # module level import not at top of file
# for import selenium.egg
'W503', # line break before binary operator
]),
]
PYLINT_OPTIONS = [
"--output-format=colorized",
"--rcfile=.pylintrc",
"--reports=no",
]
PYLINT_ISSUED_WARNING = 4
PYLINT_ISSUED_REFACTOR = 8
def get_python_exe_version():
return literal_eval(
check_output(
['python', '-c', 'import sys; print(tuple(sys.version_info))']
)
.decode()
)
def run(prog, args=None, ignore_exit_code=None):
if args is None:
args = []
try:
check_call([prog] + args)
except CalledProcessError as e:
if ignore_exit_code is not None and ignore_exit_code(e.returncode):
print(e, file=stderr)
else:
raise e from None
def ignore_flags(mask):
return lambda code: code & ~mask == 0
def main():
src_files = [f for f in listdir() if f.endswith('.py')]
src_packages = ["digital_library"]
srcs = src_files + src_packages
try:
python_exe_version = get_python_exe_version()
if python_exe_version >= (3,):
pyflakes = 'pyflakes'
pylint = 'pylint'
pytest = 'py.test'
else:
pyflakes = 'pyflakes3'
pylint = 'pylint3'
pytest = 'py.test-3'
run('pep8', PEP8_OPTIONS + srcs)
run(pyflakes, srcs)
run(
pylint,
PYLINT_OPTIONS + srcs,
ignore_exit_code = ignore_flags(
PYLINT_ISSUED_WARNING | PYLINT_ISSUED_REFACTOR
),
)
run(pytest)
except CalledProcessError as e:
print(e, file=stderr)
exit(e.returncode)
else:
print("OK")
if __name__ == '__main__':
main()