Skip to content

Commit 55b7362

Browse files
committed
Fix several pylint warnings.
Fixed all of the remaining warnings in 'build.py', 'run-tests.py' and 'check-license.py'. Related issue: #1600 JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
1 parent 1b4426f commit 55b7362

File tree

5 files changed

+274
-193
lines changed

5 files changed

+274
-193
lines changed

tools/build.py

Lines changed: 86 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17+
from __future__ import print_function
18+
1719
import argparse
1820
import multiprocessing
1921
import os
@@ -30,60 +32,101 @@
3032

3133
def default_toolchain():
3234
(sysname, _, _, _, machine) = os.uname()
33-
toolchain = os.path.join(settings.PROJECT_DIR, 'cmake', 'toolchain_%s_%s.cmake' % (sysname.lower(), machine.lower()))
35+
toolchain = os.path.join(settings.PROJECT_DIR,
36+
'cmake',
37+
'toolchain_%s_%s.cmake' % (sysname.lower(), machine.lower()))
3438
return toolchain if os.path.isfile(toolchain) else None
3539

3640
def get_arguments():
3741
devhelp_preparser = argparse.ArgumentParser(add_help=False)
38-
devhelp_preparser.add_argument('--devhelp', action='store_true', default=False, help='show help with all options (including those, which are useful for developers only)')
42+
devhelp_preparser.add_argument('--devhelp', action='store_true', default=False,
43+
help='show help with all options '
44+
'(including those, which are useful for developers only)')
3945

4046
devhelp_arguments, args = devhelp_preparser.parse_known_args()
4147
if devhelp_arguments.devhelp:
4248
args.append('--devhelp')
4349

44-
def devhelp(help):
45-
return help if devhelp_arguments.devhelp else argparse.SUPPRESS
50+
def devhelp(helpstring):
51+
return helpstring if devhelp_arguments.devhelp else argparse.SUPPRESS
4652

4753
parser = argparse.ArgumentParser(parents=[devhelp_preparser])
48-
parser.add_argument('--all-in-one', metavar='X', choices=['ON', 'OFF'], default='OFF', type=str.upper, help='all-in-one build (%(choices)s; default: %(default)s)')
49-
parser.add_argument('--builddir', metavar='DIR', action='store', default=BUILD_DIR, help='specify output directory (default: %(default)s)')
54+
parser.add_argument('--all-in-one', metavar='X', choices=['ON', 'OFF'], default='OFF', type=str.upper,
55+
help='all-in-one build (%(choices)s; default: %(default)s)')
56+
parser.add_argument('--builddir', metavar='DIR', action='store', default=BUILD_DIR,
57+
help='specify output directory (default: %(default)s)')
5058
parser.add_argument('--clean', action='store_true', default=False, help='clean build')
51-
parser.add_argument('--cmake-param', metavar='OPT', action='append', default=[], help='add custom argument to CMake')
52-
parser.add_argument('--compile-flag', metavar='OPT', action='append', default=[], help='add custom compile flag')
53-
parser.add_argument('--cpointer-32bit', metavar='X', choices=['ON', 'OFF'], default='OFF', type=str.upper, help='enable 32 bit compressed pointers (%(choices)s; default: %(default)s)')
54-
parser.add_argument('--debug', action='store_const', const='Debug', default='MinSizeRel', dest='build_type', help='debug build')
55-
parser.add_argument('--error-messages', metavar='X', choices=['ON', 'OFF'], default='OFF', type=str.upper, help='enable error messages (%(choices)s; default: %(default)s)')
56-
parser.add_argument('-j', '--jobs', metavar='N', action='store', type=int, default=multiprocessing.cpu_count() + 1, help='Allowed N build jobs at once (default: %(default)s)')
57-
parser.add_argument('--jerry-cmdline', metavar='X', choices=['ON', 'OFF'], default='ON', type=str.upper, help='build jerry command line tool (%(choices)s; default: %(default)s)')
58-
parser.add_argument('--jerry-cmdline-minimal', metavar='X', choices=['ON', 'OFF'], default='OFF', type=str.upper, help='build minimal version of the jerry command line tool (%(choices)s; default: %(default)s)')
59-
parser.add_argument('--jerry-debugger', metavar='X', choices=['ON', 'OFF'], default='OFF', type=str.upper, help='enable the jerry debugger (%(choices)s; default: %(default)s)')
60-
parser.add_argument('--jerry-debugger-port', metavar='N', action='store', type=int, default=5001, help='add custom port number (default: %(default)s)')
61-
parser.add_argument('--jerry-libc', metavar='X', choices=['ON', 'OFF'], default='ON', type=str.upper, help='build and use jerry-libc (%(choices)s; default: %(default)s)')
62-
parser.add_argument('--jerry-libm', metavar='X', choices=['ON', 'OFF'], default='ON', type=str.upper, help='build and use jerry-libm (%(choices)s; default: %(default)s)')
63-
parser.add_argument('--js-parser', metavar='X', choices=['ON', 'OFF'], default='ON', type=str.upper, help='enable js-parser (%(choices)s; default: %(default)s)')
64-
parser.add_argument('--link-lib', metavar='OPT', action='append', default=[], help='add custom library to be linked')
65-
parser.add_argument('--linker-flag', metavar='OPT', action='append', default=[], help='add custom linker flag')
66-
parser.add_argument('--lto', metavar='X', choices=['ON', 'OFF'], default='ON', type=str.upper, help='enable link-time optimizations (%(choices)s; default: %(default)s)')
67-
parser.add_argument('--mem-heap', metavar='SIZE', action='store', type=int, default=512, help='size of memory heap, in kilobytes (default: %(default)s)')
68-
parser.add_argument('--port-dir', metavar='DIR', action='store', default=DEFAULT_PORT_DIR, help='add port directory (default: %(default)s)')
69-
parser.add_argument('--profile', metavar='FILE', action='store', default=DEFAULT_PROFILE, help='specify profile file (default: %(default)s)')
70-
parser.add_argument('--snapshot-exec', metavar='X', choices=['ON', 'OFF'], default='OFF', type=str.upper, help='enable executing snapshot files (%(choices)s; default: %(default)s)')
71-
parser.add_argument('--snapshot-save', metavar='X', choices=['ON', 'OFF'], default='OFF', type=str.upper, help='enable saving snapshot files (%(choices)s; default: %(default)s)')
72-
parser.add_argument('--system-allocator', metavar='X', choices=['ON', 'OFF'], default='OFF', type=str.upper, help='enable system allocator (%(choices)s; default: %(default)s)')
73-
parser.add_argument('--static-link', metavar='X', choices=['ON', 'OFF'], default='ON', type=str.upper, help='enable static linking of binaries (%(choices)s; default: %(default)s)')
74-
parser.add_argument('--strip', metavar='X', choices=['ON', 'OFF'], default='ON', type=str.upper, help='strip release binaries (%(choices)s; default: %(default)s)')
75-
parser.add_argument('--toolchain', metavar='FILE', action='store', default=default_toolchain(), help='add toolchain file (default: %(default)s)')
76-
parser.add_argument('--unittests', action='store_const', const='ON', default='OFF', help='build unittests')
77-
parser.add_argument('-v', '--verbose', action='store_const', const='ON', default='OFF', help='increase verbosity')
59+
parser.add_argument('--cmake-param', metavar='OPT', action='append', default=[],
60+
help='add custom argument to CMake')
61+
parser.add_argument('--compile-flag', metavar='OPT', action='append', default=[],
62+
help='add custom compile flag')
63+
parser.add_argument('--cpointer-32bit', metavar='X', choices=['ON', 'OFF'], default='OFF', type=str.upper,
64+
help='enable 32 bit compressed pointers (%(choices)s; default: %(default)s)')
65+
parser.add_argument('--debug', action='store_const', const='Debug', default='MinSizeRel', dest='build_type',
66+
help='debug build')
67+
parser.add_argument('--error-messages', metavar='X', choices=['ON', 'OFF'], default='OFF', type=str.upper,
68+
help='enable error messages (%(choices)s; default: %(default)s)')
69+
parser.add_argument('-j', '--jobs', metavar='N', action='store', type=int, default=multiprocessing.cpu_count() + 1,
70+
help='Allowed N build jobs at once (default: %(default)s)')
71+
parser.add_argument('--jerry-cmdline', metavar='X', choices=['ON', 'OFF'], default='ON', type=str.upper,
72+
help='build jerry command line tool (%(choices)s; default: %(default)s)')
73+
parser.add_argument('--jerry-cmdline-minimal', metavar='X', choices=['ON', 'OFF'], default='OFF', type=str.upper,
74+
help='build minimal version of the jerry command line tool (%(choices)s; default: %(default)s)')
75+
parser.add_argument('--jerry-debugger', metavar='X', choices=['ON', 'OFF'], default='OFF', type=str.upper,
76+
help='enable the jerry debugger (%(choices)s; default: %(default)s)')
77+
parser.add_argument('--jerry-debugger-port', metavar='N', action='store', type=int, default=5001,
78+
help='add custom port number (default: %(default)s)')
79+
parser.add_argument('--jerry-libc', metavar='X', choices=['ON', 'OFF'], default='ON', type=str.upper,
80+
help='build and use jerry-libc (%(choices)s; default: %(default)s)')
81+
parser.add_argument('--jerry-libm', metavar='X', choices=['ON', 'OFF'], default='ON', type=str.upper,
82+
help='build and use jerry-libm (%(choices)s; default: %(default)s)')
83+
parser.add_argument('--js-parser', metavar='X', choices=['ON', 'OFF'], default='ON', type=str.upper,
84+
help='enable js-parser (%(choices)s; default: %(default)s)')
85+
parser.add_argument('--link-lib', metavar='OPT', action='append', default=[],
86+
help='add custom library to be linked')
87+
parser.add_argument('--linker-flag', metavar='OPT', action='append', default=[],
88+
help='add custom linker flag')
89+
parser.add_argument('--lto', metavar='X', choices=['ON', 'OFF'], default='ON', type=str.upper,
90+
help='enable link-time optimizations (%(choices)s; default: %(default)s)')
91+
parser.add_argument('--mem-heap', metavar='SIZE', action='store', type=int, default=512,
92+
help='size of memory heap, in kilobytes (default: %(default)s)')
93+
parser.add_argument('--port-dir', metavar='DIR', action='store', default=DEFAULT_PORT_DIR,
94+
help='add port directory (default: %(default)s)')
95+
parser.add_argument('--profile', metavar='FILE', action='store', default=DEFAULT_PROFILE,
96+
help='specify profile file (default: %(default)s)')
97+
parser.add_argument('--snapshot-exec', metavar='X', choices=['ON', 'OFF'], default='OFF', type=str.upper,
98+
help='enable executing snapshot files (%(choices)s; default: %(default)s)')
99+
parser.add_argument('--snapshot-save', metavar='X', choices=['ON', 'OFF'], default='OFF', type=str.upper,
100+
help='enable saving snapshot files (%(choices)s; default: %(default)s)')
101+
parser.add_argument('--system-allocator', metavar='X', choices=['ON', 'OFF'], default='OFF', type=str.upper,
102+
help='enable system allocator (%(choices)s; default: %(default)s)')
103+
parser.add_argument('--static-link', metavar='X', choices=['ON', 'OFF'], default='ON', type=str.upper,
104+
help='enable static linking of binaries (%(choices)s; default: %(default)s)')
105+
parser.add_argument('--strip', metavar='X', choices=['ON', 'OFF'], default='ON', type=str.upper,
106+
help='strip release binaries (%(choices)s; default: %(default)s)')
107+
parser.add_argument('--toolchain', metavar='FILE', action='store', default=default_toolchain(),
108+
help='add toolchain file (default: %(default)s)')
109+
parser.add_argument('--unittests', action='store_const', const='ON', default='OFF',
110+
help='build unittests')
111+
parser.add_argument('-v', '--verbose', action='store_const', const='ON', default='OFF',
112+
help='increase verbosity')
78113

79114
devgroup = parser.add_argument_group('developer options')
80-
devgroup.add_argument('--link-map', metavar='X', choices=['ON', 'OFF'], default='OFF', type=str.upper, help=devhelp('enable the generation of a link map file for jerry command line tool (%(choices)s; default: %(default)s)'))
81-
devgroup.add_argument('--mem-stats', metavar='X', choices=['ON', 'OFF'], default='OFF', type=str.upper, help=devhelp('enable memory statistics (%(choices)s; default: %(default)s)'))
82-
devgroup.add_argument('--mem-stress-test', metavar='X', choices=['ON', 'OFF'], default='OFF', type=str.upper, help=devhelp('enable mem-stress test (%(choices)s; default: %(default)s)'))
83-
devgroup.add_argument('--show-opcodes', metavar='X', choices=['ON', 'OFF'], default='OFF', type=str.upper, help=devhelp('enable parser byte-code dumps (%(choices)s; default: %(default)s)'))
84-
devgroup.add_argument('--show-regexp-opcodes', metavar='X', choices=['ON', 'OFF'], default='OFF', type=str.upper, help=devhelp('enable regexp byte-code dumps (%(choices)s; default: %(default)s)'))
85-
devgroup.add_argument('--valgrind', metavar='X', choices=['ON', 'OFF'], default='OFF', type=str.upper, help=devhelp('enable Valgrind support (%(choices)s; default: %(default)s)'))
86-
devgroup.add_argument('--valgrind-freya', metavar='X', choices=['ON', 'OFF'], default='OFF', type=str.upper, help=devhelp('enable Valgrind-Freya support (%(choices)s; default: %(default)s)'))
115+
devgroup.add_argument('--link-map', metavar='X', choices=['ON', 'OFF'], default='OFF', type=str.upper,
116+
help=devhelp('enable the generation of a link map file for jerry command line tool '
117+
'(%(choices)s; default: %(default)s)'))
118+
devgroup.add_argument('--mem-stats', metavar='X', choices=['ON', 'OFF'], default='OFF', type=str.upper,
119+
help=devhelp('enable memory statistics (%(choices)s; default: %(default)s)'))
120+
devgroup.add_argument('--mem-stress-test', metavar='X', choices=['ON', 'OFF'], default='OFF', type=str.upper,
121+
help=devhelp('enable mem-stress test (%(choices)s; default: %(default)s)'))
122+
devgroup.add_argument('--show-opcodes', metavar='X', choices=['ON', 'OFF'], default='OFF', type=str.upper,
123+
help=devhelp('enable parser byte-code dumps (%(choices)s; default: %(default)s)'))
124+
devgroup.add_argument('--show-regexp-opcodes', metavar='X', choices=['ON', 'OFF'], default='OFF', type=str.upper,
125+
help=devhelp('enable regexp byte-code dumps (%(choices)s; default: %(default)s)'))
126+
devgroup.add_argument('--valgrind', metavar='X', choices=['ON', 'OFF'], default='OFF', type=str.upper,
127+
help=devhelp('enable Valgrind support (%(choices)s; default: %(default)s)'))
128+
devgroup.add_argument('--valgrind-freya', metavar='X', choices=['ON', 'OFF'], default='OFF', type=str.upper,
129+
help=devhelp('enable Valgrind-Freya support (%(choices)s; default: %(default)s)'))
87130

88131
arguments = parser.parse_args(args)
89132
if arguments.devhelp:
@@ -113,11 +156,11 @@ def generate_build_options(arguments):
113156
build_options.append('-DPORT_DIR=%s' % arguments.port_dir)
114157

115158
if os.path.isabs(arguments.profile):
116-
PROFILE = arguments.profile
159+
profile = arguments.profile
117160
else:
118-
PROFILE = os.path.join(PROFILE_DIR, arguments.profile + '.profile')
161+
profile = os.path.join(PROFILE_DIR, arguments.profile + '.profile')
119162

120-
build_options.append('-DFEATURE_PROFILE=%s' % PROFILE)
163+
build_options.append('-DFEATURE_PROFILE=%s' % profile)
121164

122165
build_options.append('-DFEATURE_DEBUGGER=%s' % arguments.jerry_debugger)
123166
build_options.append('-DFEATURE_DEBUGGER_PORT=%d' % arguments.jerry_debugger_port)

tools/check-license.py

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,30 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17+
from __future__ import print_function
18+
1719
import os
1820
import re
1921
import sys
2022
import settings
2123

24+
LICENSE = re.compile(
25+
r'((#|//|\*) Copyright .*\n'
26+
r')+\s?\2\n'
27+
r'\s?\2 Licensed under the Apache License, Version 2.0 \(the "License"\);\n'
28+
r'\s?\2 you may not use this file except in compliance with the License.\n'
29+
r'\s?\2 You may obtain a copy of the License at\n'
30+
r'\s?\2\n'
31+
r'\s?\2 http://www.apache.org/licenses/LICENSE-2.0\n'
32+
r'\s?\2\n'
33+
r'\s?\2 Unless required by applicable law or agreed to in writing, software\n'
34+
r'\s?\2 distributed under the License is distributed on an "AS IS" BASIS\n'
35+
r'\s?\2 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n'
36+
r'\s?\2 See the License for the specific language governing permissions and\n'
37+
r'\s?\2 limitations under the License.\n'
38+
)
2239

23-
license = re.compile(
24-
u"""((#|//|\*) Copyright .*
25-
)+\s?\\2
26-
\s?\\2 Licensed under the Apache License, Version 2.0 \(the "License"\);
27-
\s?\\2 you may not use this file except in compliance with the License.
28-
\s?\\2 You may obtain a copy of the License at
29-
\s?\\2
30-
\s?\\2 http://www.apache.org/licenses/LICENSE-2.0
31-
\s?\\2
32-
\s?\\2 Unless required by applicable law or agreed to in writing, software
33-
\s?\\2 distributed under the License is distributed on an "AS IS" BASIS
34-
\s?\\2 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
35-
\s?\\2 See the License for the specific language governing permissions and
36-
\s?\\2 limitations under the License.""")
37-
38-
dirs = [
40+
INCLUDE_DIRS = [
3941
'cmake',
4042
'jerry-core',
4143
'jerry-libc',
@@ -46,12 +48,12 @@
4648
'tools',
4749
]
4850

49-
exclude_dirs = [
51+
EXCLUDE_DIRS = [
5052
'targets/esp8266',
51-
os.path.relpath (settings.TEST262_TEST_SUITE_DIR, settings.PROJECT_DIR),
53+
os.path.relpath(settings.TEST262_TEST_SUITE_DIR, settings.PROJECT_DIR),
5254
]
5355

54-
exts = [
56+
EXTENSIONS = [
5557
'.c',
5658
'.cpp',
5759
'.h',
@@ -67,15 +69,15 @@
6769
def main():
6870
is_ok = True
6971

70-
for dname in dirs:
72+
for dname in INCLUDE_DIRS:
7173
for root, _, files in os.walk(dname):
72-
if any(root.startswith(exclude) for exclude in exclude_dirs):
74+
if any(root.startswith(exclude) for exclude in EXCLUDE_DIRS):
7375
continue
7476
for fname in files:
75-
if any(fname.endswith(ext) for ext in exts):
77+
if any(fname.endswith(ext) for ext in EXTENSIONS):
7678
fpath = os.path.join(root, fname)
77-
with open(fpath) as f:
78-
if not license.search(f.read()):
79+
with open(fpath) as curr_file:
80+
if not LICENSE.search(curr_file.read()):
7981
print('%s: incorrect license' % fpath)
8082
is_ok = False
8183

0 commit comments

Comments
 (0)