Skip to content

Commit bc408b1

Browse files
authored
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 [email protected]
1 parent a588e49 commit bc408b1

26 files changed

+475
-509
lines changed

.github/workflows/gh-actions.yml

Lines changed: 62 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ jobs:
1717
python-version: '3.10'
1818
- run: sudo apt update
1919
# TODO: update checkers to current versions available in ubuntu 22.04
20-
# - run: sudo apt install doxygen clang-format-10 cppcheck pylint python-serial
20+
# - run: sudo apt install doxygen clang-format-10 cppcheck python-serial
21+
- run: sudo apt install pylint
2122
- run: $RUNNER --check-signed-off=gh-actions
2223
if: ${{ always() }}
2324
# - run: $RUNNER --check-doxygen
@@ -28,16 +29,18 @@ jobs:
2829
if: ${{ always() }}
2930
# - run: $RUNNER --check-strings
3031
# if: ${{ always() }}
31-
# - run: $RUNNER --check-pylint
32-
# if: ${{ always() }}
32+
- run: $RUNNER --check-pylint
33+
if: ${{ always() }}
3334
# - run: $RUNNER --check-cppcheck
3435
# if: ${{ always() }}
3536

3637
Linux_x86-64_Build_Correctness_Debugger_Tests:
3738
runs-on: ubuntu-latest
3839
steps:
3940
- uses: actions/checkout@v2
40-
- uses: actions/setup-python@v2
41+
- uses: actions/setup-python@v4
42+
with:
43+
python-version: '>=3.6'
4144
- run: $RUNNER -q --jerry-tests
4245
- run: $RUNNER -q --jerry-tests --build-debug
4346
- run: $RUNNER -q --jerry-debugger
@@ -47,6 +50,9 @@ jobs:
4750
runs-on: ubuntu-latest
4851
steps:
4952
- uses: actions/checkout@v2
53+
- uses: actions/setup-python@v4
54+
with:
55+
python-version: '>=3.6'
5056
- run: sudo apt update
5157
- run: sudo apt install gcc-multilib
5258
- run: $RUNNER -q --jerry-tests --buildoptions=--compile-flag=-m32,--cpointer-32bit=on
@@ -56,20 +62,29 @@ jobs:
5662
runs-on: macos-latest
5763
steps:
5864
- uses: actions/checkout@v2
65+
- uses: actions/setup-python@v4
66+
with:
67+
python-version: '>=3.6'
5968
- run: $RUNNER -q --jerry-tests
6069
- run: $RUNNER -q --unittests
6170

6271
OSX_x86-64_Build_Correctness_Unit_Tests_Debug:
6372
runs-on: macos-latest
6473
steps:
6574
- uses: actions/checkout@v2
75+
- uses: actions/setup-python@v4
76+
with:
77+
python-version: '>=3.6'
6678
- run: $RUNNER -q --jerry-tests --build-debug
6779
- run: $RUNNER -q --unittests --build-debug
6880

6981
Linux_x86-64_Build_Option_Tests:
7082
runs-on: ubuntu-latest
7183
steps:
7284
- uses: actions/checkout@v2
85+
- uses: actions/setup-python@v4
86+
with:
87+
python-version: '>=3.6'
7388
- run: sudo apt update
7489
- run: sudo apt install gcc-multilib
7590
- run: $RUNNER --buildoption-test
@@ -78,6 +93,9 @@ jobs:
7893
runs-on: ubuntu-latest
7994
steps:
8095
- uses: actions/checkout@v2
96+
- uses: actions/setup-python@v4
97+
with:
98+
python-version: '>=3.6'
8199
- run: $RUNNER --test262 update
82100
- uses: actions/upload-artifact@v2
83101
if: success() || failure()
@@ -90,6 +108,9 @@ jobs:
90108
runs-on: ubuntu-latest
91109
steps:
92110
- uses: actions/checkout@v2
111+
- uses: actions/setup-python@v4
112+
with:
113+
python-version: '>=3.6'
93114
- run: $RUNNER --test262 update --build-debug --test262-test-list=built-ins,annexB,harness,intl402
94115
- uses: actions/upload-artifact@v2
95116
if: success() || failure()
@@ -102,6 +123,9 @@ jobs:
102123
runs-on: ubuntu-latest
103124
steps:
104125
- uses: actions/checkout@v2
126+
- uses: actions/setup-python@v4
127+
with:
128+
python-version: '>=3.6'
105129
- run: $RUNNER --test262 update --build-debug --test262-test-list=language
106130
- uses: actions/upload-artifact@v2
107131
if: success() || failure()
@@ -114,6 +138,9 @@ jobs:
114138
runs-on: ubuntu-latest
115139
steps:
116140
- uses: actions/checkout@v2
141+
- uses: actions/setup-python@v4
142+
with:
143+
python-version: '>=3.6'
117144
- run: $RUNNER -q --unittests
118145
- run: $RUNNER -q --unittests --build-debug
119146

@@ -123,6 +150,9 @@ jobs:
123150
CC: clang
124151
steps:
125152
- uses: actions/checkout@v2
153+
- uses: actions/setup-python@v4
154+
with:
155+
python-version: '>=3.6'
126156
- run: sudo apt update
127157
- run: sudo apt install gcc-multilib
128158
- run: $RUNNER -q --unittests
@@ -135,6 +165,9 @@ jobs:
135165
ASAN_OPTIONS: detect_stack_use_after_return=1:check_initialization_order=true:strict_init_order=true
136166
steps:
137167
- uses: actions/checkout@v2
168+
- uses: actions/setup-python@v4
169+
with:
170+
python-version: '>=3.6'
138171
- run: sudo apt update
139172
- run: sudo apt install gcc-multilib
140173
- run: >-
@@ -148,6 +181,9 @@ jobs:
148181
ASAN_OPTIONS: detect_stack_use_after_return=1:check_initialization_order=true:strict_init_order=true
149182
steps:
150183
- uses: actions/checkout@v2
184+
- uses: actions/setup-python@v4
185+
with:
186+
python-version: '>=3.6'
151187
- run: sudo apt update
152188
- run: sudo apt install gcc-multilib
153189
- run: >-
@@ -161,6 +197,9 @@ jobs:
161197
UBSAN_OPTIONS: print_stacktrace=1
162198
steps:
163199
- uses: actions/checkout@v2
200+
- uses: actions/setup-python@v4
201+
with:
202+
python-version: '>=3.6'
164203
- run: sudo apt update
165204
- run: sudo apt install gcc-multilib
166205
- run: >-
@@ -179,6 +218,9 @@ jobs:
179218
TIMEOUT: 300
180219
steps:
181220
- uses: actions/checkout@v2
221+
- uses: actions/setup-python@v4
222+
with:
223+
python-version: '>=3.6'
182224
- run: sudo apt update
183225
- run: sudo apt install gcc-arm-linux-gnueabihf libc6-dev-armhf-cross qemu-user-static
184226
- run: >-
@@ -192,6 +234,9 @@ jobs:
192234
TIMEOUT: 300
193235
steps:
194236
- uses: actions/checkout@v2
237+
- uses: actions/setup-python@v4
238+
with:
239+
python-version: '>=3.6'
195240
- run: sudo apt update
196241
- run: sudo apt install gcc-arm-linux-gnueabihf libc6-dev-armhf-cross qemu-user-static
197242
- run: >-
@@ -205,6 +250,9 @@ jobs:
205250
TIMEOUT: 300
206251
steps:
207252
- uses: actions/checkout@v2
253+
- uses: actions/setup-python@v4
254+
with:
255+
python-version: '>=3.6'
208256
- run: sudo apt update
209257
- run: sudo apt install gcc-aarch64-linux-gnu libc6-dev-armhf-cross qemu-user-static
210258
- run: >-
@@ -218,6 +266,9 @@ jobs:
218266
TIMEOUT: 300
219267
steps:
220268
- uses: actions/checkout@v2
269+
- uses: actions/setup-python@v4
270+
with:
271+
python-version: '>=3.6'
221272
- run: sudo apt update
222273
- run: sudo apt install gcc-aarch64-linux-gnu libc6-dev-armhf-cross qemu-user-static
223274
- run: >-
@@ -242,9 +293,9 @@ jobs:
242293
runs-on: ubuntu-latest
243294
steps:
244295
- uses: actions/checkout@v2
245-
- uses: actions/setup-python@v2
296+
- uses: actions/setup-python@v4
246297
with:
247-
python-version: '3.x'
298+
python-version: '>=3.6'
248299
- run: sudo apt update
249300
- run: sudo apt install gperf dfu-util device-tree-compiler
250301
- run: make -f ./targets/os/zephyr/Makefile.travis install
@@ -254,6 +305,9 @@ jobs:
254305
runs-on: ubuntu-latest
255306
steps:
256307
- uses: actions/checkout@v2
308+
- uses: actions/setup-python@v4
309+
with:
310+
python-version: '>=3.6'
257311
- run: sudo apt update
258312
- run: sudo apt install gcc-arm-none-eabi libnewlib-arm-none-eabi gperf
259313
- run: make -f ./targets/os/nuttx/Makefile.travis install-noapt
@@ -276,9 +330,9 @@ jobs:
276330
runs-on: ubuntu-latest
277331
steps:
278332
- uses: actions/checkout@v2
279-
- uses: actions/setup-python@v2
333+
- uses: actions/setup-python@v4
280334
with:
281-
python-version: '3.8'
335+
python-version: '>=3.8'
282336
- run: make -f ./targets/baremetal-sdk/espressif/esp8266-rtos-sdk/Makefile.travis install-noapt
283337
- run: make -f ./targets/baremetal-sdk/espressif/esp8266-rtos-sdk/Makefile.travis script
284338

jerry-debugger/jerry_client.py

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

17-
from __future__ import print_function
1817
from cmd import Cmd
1918
from pprint import pprint
2019
import math
@@ -42,7 +41,7 @@ def __init__(self, debugger):
4241
def precmd(self, line):
4342
self.stop = False
4443
if self.debugger.non_interactive:
45-
print("%s" % line)
44+
print(f"{line}")
4645
return line
4746

4847
def postcmd(self, stop, line):
@@ -104,14 +103,14 @@ def do_next(self, args):
104103
if res_type == result.END:
105104
self.quit = True
106105
return
107-
elif res_type == result.TEXT:
106+
if res_type == result.TEXT:
108107
write(result.get_text())
109108
elif res_type == result.PROMPT:
110109
break
111110

112111
args -= 1
113112
except ValueError as val_errno:
114-
print("Error: expected a positive integer: %s" % val_errno)
113+
print(f"Error: expected a positive integer: {val_errno}")
115114
do_n = do_next
116115

117116
def do_step(self, _):
@@ -185,10 +184,10 @@ def do_eval_at(self, args):
185184
code = args[1]
186185

187186
if index < 0 or index > 65535:
188-
raise ValueError("Invalid scope chain index: %d (must be between 0 and 65535)" % index)
187+
raise ValueError(f"Invalid scope chain index: {index} (must be between 0 and 65535)")
189188

190189
except ValueError as val_errno:
191-
print("Error: %s" % (val_errno))
190+
print(f"Error: {val_errno}")
192191
return
193192

194193
self.debugger.eval_at(code, index)
@@ -259,10 +258,10 @@ def src_check_args(args):
259258

260259
return line_num
261260
except ValueError as val_errno:
262-
print("Error: Non-negative integer number expected: %s" % (val_errno))
261+
print(f"Error: Non-negative integer number expected: {val_errno}")
263262
return -1
264263

265-
# pylint: disable=too-many-branches,too-many-locals,too-many-statements
264+
# pylint: disable=too-many-branches,too-many-locals,too-many-statements,import-outside-toplevel
266265
def main():
267266
args = jerry_client_main.arguments_parse()
268267

@@ -325,7 +324,7 @@ def main():
325324

326325
if res_type == result.END:
327326
break
328-
elif res_type == result.PROMPT:
327+
if res_type == result.PROMPT:
329328
prompt.cmdloop()
330329
elif res_type == result.TEXT:
331330
write(result.get_text())
@@ -339,7 +338,7 @@ def main():
339338
MSG = str(error_msg)
340339
if ERRNO == 111:
341340
sys.exit("Failed to connect to the JerryScript debugger.")
342-
elif ERRNO == 32 or ERRNO == 104:
341+
elif ERRNO in (32, 104):
343342
sys.exit("Connection closed.")
344343
else:
345-
sys.exit("Failed to connect to the JerryScript debugger.\nError: %s" % (MSG))
344+
sys.exit(f"Failed to connect to the JerryScript debugger.\nError: {MSG}")

0 commit comments

Comments
 (0)