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
+6 -8
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 fileinput
import os
@@ -24,7 +22,7 @@ import shlex
import sys
class DoctestExtractor(object):
class DoctestExtractor:
"""
An extractor to process Markdown files and find doctests inside.
"""
@@ -50,7 +48,7 @@ class DoctestExtractor(object):
:param message: a description of the problem.
:param lineno: the location that triggered the warning.
"""
print('%s:%d: %s' % (self._infile, lineno, message), file=sys.stderr)
print(f'{self._infile}:{lineno}: {message}', file=sys.stderr)
def _process_decl(self, params):
"""
@@ -72,7 +70,7 @@ class DoctestExtractor(object):
decl[tokens[i]] = tokens[i + 2].strip('\'"')
if 'name' not in decl:
decl['name'] = '%s%d.c' % (self._outname_base, self._outname_cnt)
decl['name'] = f'{self._outname_base}{self._outname_cnt}.c'
self._outname_cnt += 1
if 'test' not in decl:
@@ -87,7 +85,7 @@ class DoctestExtractor(object):
:return: a tuple of a list (of the first line(s) of the doctest) and the
line number of the start of the code block.
"""
return ['#line %d "%s"\n' % (fileinput.filelineno() + 1, self._infile)], fileinput.filelineno()
return [f'#line {fileinput.filelineno() + 1} "{self._infile}"\n'], fileinput.filelineno()
def _process_code_end(self, decl, code):
"""
@@ -99,9 +97,9 @@ class DoctestExtractor(object):
outname = os.path.join(self._outdir, decl['name']).replace('\\', '/')
action = decl['test']
if self._dry:
print('%s %s' % (action, outname))
print(f'{action} {outname}')
else:
with open(outname, 'w') as outfile:
with open(outname, 'w', encoding='utf8') as outfile:
outfile.writelines(code)
def process(self, infile):