Skip to content

Commit

Permalink
Re-enable pylint CI checker
Browse files Browse the repository at this point in the history
Update code to conform to the newer version of pylint available in
ubuntu-22.04, with few exceptions:
    - disabled `consider-using-f-string`
    - disabled `import-outside-toplevel` for `main()` in
      `jerry_client.py`
    - disabled `consider-using-with` for the logfile of `TestSuite` in
      `test262-harness.py` as using `with` is not practical in that case

update test262-harness.py to use argparse instead of the now deprecated
optparse

rename variables in jerry_client_main.py that redefined python builtins
or shadowed variables from an outer scope

JerryScript-DCO-1.0-Signed-off-by: Máté Tokodi matet@inf.u-szeged.hu
  • Loading branch information
matetokodi committed Sep 22, 2023
1 parent a588e49 commit 2573192
Show file tree
Hide file tree
Showing 21 changed files with 255 additions and 261 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/gh-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ jobs:
python-version: '3.10'
- run: sudo apt update
# TODO: update checkers to current versions available in ubuntu 22.04
# - run: sudo apt install doxygen clang-format-10 cppcheck pylint python-serial
# - run: sudo apt install doxygen clang-format-10 cppcheck python-serial
- run: sudo apt install pylint
- run: $RUNNER --check-signed-off=gh-actions
if: ${{ always() }}
# - run: $RUNNER --check-doxygen
Expand All @@ -28,8 +29,8 @@ jobs:
if: ${{ always() }}
# - run: $RUNNER --check-strings
# if: ${{ always() }}
# - run: $RUNNER --check-pylint
# if: ${{ always() }}
- run: $RUNNER --check-pylint
if: ${{ always() }}
# - run: $RUNNER --check-cppcheck
# if: ${{ always() }}

Expand Down
8 changes: 4 additions & 4 deletions jerry-debugger/jerry_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def do_next(self, args):
if res_type == result.END:
self.quit = True
return
elif res_type == result.TEXT:
if res_type == result.TEXT:
write(result.get_text())
elif res_type == result.PROMPT:
break
Expand Down Expand Up @@ -262,7 +262,7 @@ def src_check_args(args):
print("Error: Non-negative integer number expected: %s" % (val_errno))
return -1

# pylint: disable=too-many-branches,too-many-locals,too-many-statements
# pylint: disable=too-many-branches,too-many-locals,too-many-statements,import-outside-toplevel
def main():
args = jerry_client_main.arguments_parse()

Expand Down Expand Up @@ -325,7 +325,7 @@ def main():

if res_type == result.END:
break
elif res_type == result.PROMPT:
if res_type == result.PROMPT:
prompt.cmdloop()
elif res_type == result.TEXT:
write(result.get_text())
Expand All @@ -339,7 +339,7 @@ def main():
MSG = str(error_msg)
if ERRNO == 111:
sys.exit("Failed to connect to the JerryScript debugger.")
elif ERRNO == 32 or ERRNO == 104:
elif ERRNO in (32, 104):
sys.exit("Connection closed.")
else:
sys.exit("Failed to connect to the JerryScript debugger.\nError: %s" % (MSG))
154 changes: 76 additions & 78 deletions jerry-debugger/jerry_client_main.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion jerry-debugger/jerry_client_rawpacket.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

MAX_BUFFER_SIZE = 256

class RawPacket(object):
class RawPacket:
""" Simplified transmission layer. """
def __init__(self, protocol):
self.protocol = protocol
Expand Down
2 changes: 1 addition & 1 deletion jerry-debugger/jerry_client_serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import select
import serial

class Serial(object):
class Serial:
""" Create a new socket using the given address family, socket type and protocol number. """
def __init__(self, serial_config):
config = serial_config.split(',')
Expand Down
2 changes: 1 addition & 1 deletion jerry-debugger/jerry_client_tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import select

# pylint: disable=too-many-arguments,superfluous-parens
class Socket(object):
class Socket:
""" Create a new socket using the given address family, socket type and protocol number. """
def __init__(self, address, socket_family=socket.AF_INET, socket_type=socket.SOCK_STREAM, proto=0, fileno=None):
self.address = address
Expand Down
2 changes: 1 addition & 1 deletion jerry-debugger/jerry_client_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
WEBSOCKET_BINARY_FRAME = 2
WEBSOCKET_FIN_BIT = 0x80

class WebSocket(object):
class WebSocket:
def __init__(self, protocol):

self.data_buffer = b""
Expand Down
6 changes: 3 additions & 3 deletions tools/amalgam.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
JERRY_MATH = os.path.join(ROOT_DIR, 'jerry-math')


class Amalgamator(object):
class Amalgamator:
# pylint: disable=too-many-instance-attributes

_RE_INCLUDE = re.compile(r'\s*#include ("|<)(.*?)("|>)\n$')
Expand Down Expand Up @@ -92,7 +92,7 @@ def add_file(self, filename, file_level=0):
self._emit_lineinfo(1, filename)

line_idx = 0
with open(filename, 'r') as input_file:
with open(filename, 'r', encoding='utf8') as input_file:
in_copyright = False
for line in input_file:
line_idx += 1
Expand Down Expand Up @@ -242,7 +242,7 @@ def amalgamate(base_dir, input_files=(), output_file=None,
for fname in sorted(c_files.values(), reverse=True):
amalgam.add_file(fname)

with open(output_file, 'w') as output:
with open(output_file, 'w', encoding='utf8') as output:
amalgam.write_output(output)


Expand Down
6 changes: 2 additions & 4 deletions tools/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,8 @@ def make_jerry(arguments):
env = dict(os.environ)
env['CMAKE_BUILD_PARALLEL_LEVEL'] = str(arguments.jobs)
env['MAKEFLAGS'] = '-j%d' % (arguments.jobs) # Workaround for CMake < 3.12
proc = subprocess.Popen(make_cmd, env=env)
proc.wait()

return proc.returncode
with subprocess.Popen(make_cmd, env=env) as proc:
return proc.returncode

def install_jerry(arguments):
install_target = 'INSTALL' if os.path.exists(os.path.join(arguments.builddir, 'Jerry.sln')) else 'install'
Expand Down
36 changes: 17 additions & 19 deletions tools/check-format.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,13 @@ def check_clang_format(args, source_file_name):

cmd.append(source_file_name)

proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
_, error = proc.communicate()
with subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) as proc:
_, error = proc.communicate()

if proc.returncode == 0:
return 0
if proc.returncode == 0:
return 0

print(error.decode('utf8'))
print(error.decode('utf8'))

return 1

Expand Down Expand Up @@ -115,22 +114,21 @@ def main(args):
CLANG_FORMAT_MIN_VERSION)
return 1

pool = multiprocessing.Pool()
failed = 0

for folder in FOLDERS:
# pylint: disable=unexpected-keyword-arg
files = sum(([glob(path.join(PROJECT_DIR, folder, "**/*.%s" % e), recursive=True)
for e in ['c', 'h']]), [])
with multiprocessing.Pool() as pool:
failed = 0

failed += run_pass(pool, check_clang_format,
[(args, sourece_file) for sourece_file in files])
failed += run_pass(pool, check_comments,
[([RE_DIRECTIVE_COMMENT, RE_FUNCTION_NAME_COMMENT], sourece_file) for sourece_file in files])
for folder in FOLDERS:
# pylint: disable=unexpected-keyword-arg
files = sum(([glob(path.join(PROJECT_DIR, folder, "**/*.%s" % e), recursive=True)
for e in ['c', 'h']]), [])

pool.close()
failed += run_pass(pool, check_clang_format,
[(args, sourece_file) for sourece_file in files])
failed += run_pass(pool, check_comments,
[([RE_DIRECTIVE_COMMENT, RE_FUNCTION_NAME_COMMENT], sourece_file) for sourece_file in
files])

return 1 if failed else 0
return 1 if failed else 0


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion tools/check-license.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def main():
for fname in files:
if any(fname.endswith(ext) for ext in EXTENSIONS):
fpath = os.path.join(root, fname)
with io.open(fpath, 'r', errors='ignore') as curr_file:
with io.open(fpath, 'r', errors='ignore', encoding='utf8') as curr_file:
if not LICENSE.search(curr_file.read()):
print('%s: incorrect license' % fpath)
is_ok = False
Expand Down
4 changes: 2 additions & 2 deletions tools/gen-doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import sys


class DoctestExtractor(object):
class DoctestExtractor:
"""
An extractor to process Markdown files and find doctests inside.
"""
Expand Down Expand Up @@ -101,7 +101,7 @@ def _process_code_end(self, decl, code):
if self._dry:
print('%s %s' % (action, outname))
else:
with open(outname, 'w') as outfile:
with open(outname, 'w', encoding='utf8') as outfile:
outfile.writelines(code)

def process(self, infile):
Expand Down
7 changes: 4 additions & 3 deletions tools/gen-strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@

import argparse
import fileinput
import subprocess
import json
import os
import re
import subprocess
import sys

from settings import FORMAT_SCRIPT, PROJECT_DIR

Expand Down Expand Up @@ -75,7 +76,7 @@ def read_magic_string_defs(debug, ini_path, item_name):
for str_ref, str_value in [x for x in defs if len(x[1]) > LIMIT_MAGIC_STR_LENGTH]:
print("error: The maximum allowed magic string size is {limit} but {str_ref} is {str_len} long.".format(
limit=LIMIT_MAGIC_STR_LENGTH, str_ref=str_ref, str_len=len(str_value)))
exit(1)
sys.exit(1)

if debug:
print('debug: magic string definitions: {dump}'
Expand Down Expand Up @@ -294,7 +295,7 @@ def generate_magic_strings(args, ini_path, item_name, pattern, inc_h_path, def_m

extended_defs = calculate_magic_string_guards(defs, uses, debug=args.debug)

with open(inc_h_path, 'w') as gen_file:
with open(inc_h_path, 'w', encoding='utf8') as gen_file:
generate_header(gen_file, ini_path)
generate_magic_string_defs(gen_file, extended_defs, def_macro)
if with_size_macro:
Expand Down
16 changes: 8 additions & 8 deletions tools/gen-unicode.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

# common code generation

class UnicodeBasicSource(object):
class UnicodeBasicSource:
# pylint: disable=too-many-instance-attributes
def __init__(self, filepath, character_type="uint16_t", length_type="uint8_t"):
self._filepath = filepath
Expand Down Expand Up @@ -114,7 +114,7 @@ def add_table(self, table, description, table_type, category, table_name):
self._data.append("") # for an extra empty line

def generate(self):
with open(self._filepath, 'w') as generated_source:
with open(self._filepath, 'w', encoding='utf8') as generated_source:
generated_source.write("\n".join(self._header))
generated_source.write("\n".join(self._data))

Expand All @@ -127,14 +127,14 @@ def __init__(self, filepath):
def add_whitepace_range(self, category, categorizer, units):
self.add_range(category, categorizer.create_tables(units))

class UnicodeBasicCategorizer(object):
class UnicodeBasicCategorizer:
def __init__(self):
self._length_limit = 0xff
self.extra_id_continue_units = set([0x200C, 0x200D])

#pylint: disable=no-self-use
def in_range(self, i):
return i >= 0x80 and i < 0x10000
return 0x80 <= i < 0x10000

def _group_ranges(self, units):
"""
Expand Down Expand Up @@ -194,7 +194,7 @@ def read_units(self, file_path, categories, subcategories=None):
# <HEX>..<HEX> ; <category> # <subcategory>
matcher = r"(?P<start>[\dA-F]+)(?:\.\.(?P<end>[\dA-F]+))?\s+; (?P<category>[\w]+) # (?P<subcategory>[\w&]{2})"

with open(file_path, "r") as src_file:
with open(file_path, "r", encoding='utf8') as src_file:
for line in src_file:
match = re.match(matcher, line)

Expand Down Expand Up @@ -227,7 +227,7 @@ def read_case_mappings(self, unicode_data_file, special_casing_file):
upper_case_mapping = {}

# Add one-to-one mappings
with open(unicode_data_file) as unicode_data:
with open(unicode_data_file, encoding='utf8') as unicode_data:
reader = csv.reader(unicode_data, delimiter=';')

for line in reader:
Expand All @@ -246,7 +246,7 @@ def read_case_mappings(self, unicode_data_file, special_casing_file):
lower_case_mapping[letter_id] = parse_unicode_sequence(small_letter)

# Update the conversion tables with the special cases
with open(special_casing_file) as special_casing:
with open(special_casing_file, encoding='utf8') as special_casing:
reader = csv.reader(special_casing, delimiter=';')

for line in reader:
Expand Down Expand Up @@ -740,7 +740,7 @@ def generate_folding(script_args, plane_type):

folding = {}

with open(case_folding_path, 'r') as case_folding:
with open(case_folding_path, 'r', encoding='utf8') as case_folding:
case_folding_re = re.compile(r'(?P<code_point>[^;]*);\s*(?P<type>[^;]*);\s*(?P<folding>[^;]*);')
for line in case_folding:
match = case_folding_re.match(line)
Expand Down
4 changes: 2 additions & 2 deletions tools/js2c.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def reduce_code(code):


def js_to_native_code(path, name, build_type):
with open(path, 'r') as js_source:
with open(path, 'r', encoding='utf8') as js_source:
code = js_source.read()

if build_type != 'debug':
Expand Down Expand Up @@ -118,7 +118,7 @@ def main():
gen_output.append("\n".join(gen_structs))
gen_output.append(FOOTER)

with open(os.path.join(script_args.output_path, 'jerry-targetjs.h'), 'w') as gen_file:
with open(os.path.join(script_args.output_path, 'jerry-targetjs.h'), 'w', encoding='utf8') as gen_file:
gen_file.write("\n".join(gen_output))


Expand Down
2 changes: 1 addition & 1 deletion tools/pylint/pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ confidence=
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use"--disable=all --enable=classes
# --disable=W"
disable=import-star-module-level,old-octal-literal,oct-method,unpacking-in-except,parameter-unpacking,backtick,old-raise-syntax,old-ne-operator,long-suffix,dict-view-method,dict-iter-method,metaclass-assignment,next-method-called,raising-string,indexing-exception,raw_input-builtin,long-builtin,file-builtin,execfile-builtin,coerce-builtin,cmp-builtin,buffer-builtin,basestring-builtin,apply-builtin,filter-builtin-not-iterating,using-cmp-argument,useless-suppression,range-builtin-not-iterating,suppressed-message,no-absolute-import,old-division,cmp-method,reload-builtin,zip-builtin-not-iterating,intern-builtin,unichr-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,input-builtin,round-builtin,hex-method,nonzero-method,map-builtin-not-iterating,missing-docstring,locally-disabled
disable=import-star-module-level,old-octal-literal,oct-method,unpacking-in-except,parameter-unpacking,backtick,old-raise-syntax,old-ne-operator,long-suffix,dict-view-method,dict-iter-method,metaclass-assignment,next-method-called,raising-string,indexing-exception,raw_input-builtin,long-builtin,file-builtin,execfile-builtin,coerce-builtin,cmp-builtin,buffer-builtin,basestring-builtin,apply-builtin,filter-builtin-not-iterating,using-cmp-argument,useless-suppression,range-builtin-not-iterating,suppressed-message,no-absolute-import,old-division,cmp-method,reload-builtin,zip-builtin-not-iterating,intern-builtin,unichr-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,input-builtin,round-builtin,hex-method,nonzero-method,map-builtin-not-iterating,missing-docstring,locally-disabled,consider-using-f-string,


[REPORTS]
Expand Down
16 changes: 7 additions & 9 deletions tools/run-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import settings

if sys.version_info.major >= 3:
import runners.util as util # pylint: disable=import-error
from runners import util
else:
sys.path.append(os.path.dirname(os.path.realpath(__file__)) + '/runners')
import util
Expand Down Expand Up @@ -284,17 +284,15 @@ def iterate_test_runner_jobs(jobs, options):
if build_dir_path in tested_paths:
sys.stderr.write('(skipping: already tested with %s)\n' % build_dir_path)
continue
else:
tested_paths.add(build_dir_path)
tested_paths.add(build_dir_path)

bin_path = get_binary_path(build_dir_path)
bin_hash = hash_binary(bin_path)

if bin_hash in tested_hashes:
sys.stderr.write('(skipping: already tested with equivalent %s)\n' % tested_hashes[bin_hash])
continue
else:
tested_hashes[bin_hash] = build_dir_path
tested_hashes[bin_hash] = build_dir_path

test_cmd = util.get_python_cmd_prefix()
test_cmd.extend([settings.TEST_RUNNER_SCRIPT, '--engine', bin_path])
Expand All @@ -309,9 +307,9 @@ def run_check(runnable, env=None):
full_env.update(env)
env = full_env

proc = subprocess.Popen(runnable, env=env)
proc.wait()
return proc.returncode
with subprocess.Popen(runnable, env=env) as proc:
proc.wait()
return proc.returncode

def run_jerry_debugger_tests(options):
ret_build = ret_test = 0
Expand Down Expand Up @@ -356,7 +354,7 @@ def run_jerry_tests(options):
skip_list = []

if job.name == 'jerry_tests-snapshot':
with open(settings.SNAPSHOT_TESTS_SKIPLIST, 'r') as snapshot_skip_list:
with open(settings.SNAPSHOT_TESTS_SKIPLIST, 'r', encoding='utf8') as snapshot_skip_list:
for line in snapshot_skip_list:
skip_list.append(line.rstrip())

Expand Down
Loading

0 comments on commit 2573192

Please sign in to comment.