Modernize python and update pylint (#5096)

Update code to conform to the newer version of pylint available in
ubuntu-22.04, with few exceptions:
    - 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

Update python files to use f-stirngs

Add minimum python versions (3.6 and 3.8) to the CI jobs: without it the
default python version did not support the `with` statement for
`subprocess.Popen` used in `build.py` on macos, or in some cases f-stirngs

Remove `from __future__` imports that are no-ops in python 3

Remove shebang from non executable files

Re-enable most pylint checkers, except `missing-docstring`

JerryScript-DCO-1.0-Signed-off-by: Máté Tokodi mate.tokodi@szteszoftver.hu
This commit is contained in:
Máté Tokodi
2023-10-25 17:32:14 +02:00
committed by GitHub
parent a588e49661
commit bc408b159b
26 changed files with 469 additions and 503 deletions
+19 -23
View File
@@ -14,8 +14,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function
import argparse
import csv
import itertools
@@ -45,7 +43,7 @@ UNICODE_PLANE_TYPE_SUPPLEMENTARY = 1
# 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
@@ -81,7 +79,7 @@ class UnicodeBasicSource(object):
idx = 0
for table in tables:
self.add_table(table,
"/**\n * %s %s.\n */" % (self._range_table_descriptions[idx], category),
f"/**\n * {self._range_table_descriptions[idx]} {category}.\n */",
self._range_table_types[idx],
category,
self._range_table_names[idx])
@@ -103,18 +101,16 @@ class UnicodeBasicSource(object):
def add_table(self, table, description, table_type, category, table_name):
if table and sum(table) != 0:
self._data.append(description)
self._data.append("static const %s lit_unicode_%s%s%s[] JERRY_ATTR_CONST_DATA ="
% (table_type,
category.lower(),
"_" + table_name if table_name else "",
self._table_name_suffix))
self._data.append(f"static const {table_type} lit_unicode_{category.lower()}"
f"{'_' + table_name if table_name else ''}{self._table_name_suffix}"
f"[] JERRY_ATTR_CONST_DATA =")
self._data.append("{")
self._data.append(format_code(table, 1, 6 if self._table_name_suffix else 4))
self._data.append("};")
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))
@@ -127,14 +123,14 @@ class UnicodeSupplementarySource(UnicodeBasicSource):
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):
"""
@@ -194,7 +190,7 @@ class UnicodeBasicCategorizer(object):
# <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)
@@ -227,7 +223,7 @@ class UnicodeBasicCategorizer(object):
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:
@@ -246,7 +242,7 @@ class UnicodeBasicCategorizer(object):
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:
@@ -293,8 +289,8 @@ def generate_ranges(script_args, plane_type):
c_source = UnicodeBasicSource(RANGES_C_SOURCE)
categorizer = UnicodeBasicCategorizer()
header_completion = ["/* This file is automatically generated by the %s script" % os.path.basename(__file__),
" * from %s. Do not edit! */" % (DERIVED_PROPS_FILE),
header_completion = [f"/* This file is automatically generated by the {os.path.basename(__file__)} script",
f" * from {DERIVED_PROPS_FILE}. Do not edit! */",
""]
c_source.complete_header("\n".join(header_completion))
@@ -652,8 +648,8 @@ def generate_conversions(script_args, plane_type):
c_source = UnicodeBasicSource(CONVERSIONS_C_SOURCE)
categorizer = UnicodeBasicCategorizer()
header_completion = ["/* This file is automatically generated by the %s script" % os.path.basename(__file__),
" * from %s and %s files. Do not edit! */" % (UNICODE_DATA_FILE, SPECIAL_CASING_FILE),
header_completion = [f"/* This file is automatically generated by the {os.path.basename(__file__)} script",
f" * from {UNICODE_DATA_FILE} and {SPECIAL_CASING_FILE} files. Do not edit! */",
""]
c_source.complete_header("\n".join(header_completion))
@@ -725,8 +721,8 @@ def generate_folding(script_args, plane_type):
c_source = UnicodeBasicSource(FOLDING_C_SOURCE)
categorizer = UnicodeBasicCategorizer()
header_completion = ["/* This file is automatically generated by the %s script" % os.path.basename(__file__),
" * from the %s file. Do not edit! */" % (CASE_FOLDING_FILE),
header_completion = [f"/* This file is automatically generated by the {os.path.basename(__file__)} script",
f" * from the {CASE_FOLDING_FILE} file. Do not edit! */",
""]
c_source.complete_header("\n".join(header_completion))
@@ -740,7 +736,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)
@@ -782,7 +778,7 @@ def main():
''')
def check_dir(path):
if not os.path.isdir(path) or not os.access(path, os.R_OK):
raise argparse.ArgumentTypeError('The %s directory does not exist or is not readable!' % path)
raise argparse.ArgumentTypeError(f'The {path} directory does not exist or is not readable!')
return path
parser.add_argument('--unicode-dir', metavar='DIR', action='store', required=True,