Skip to content

Commit

Permalink
Modernize python and update pylint (#5096)
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 `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]
  • Loading branch information
matetokodi authored Oct 25, 2023
1 parent a588e49 commit bc408b1
Show file tree
Hide file tree
Showing 26 changed files with 475 additions and 509 deletions.
70 changes: 62 additions & 8 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,16 +29,18 @@ 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() }}

Linux_x86-64_Build_Correctness_Debugger_Tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/setup-python@v4
with:
python-version: '>=3.6'
- run: $RUNNER -q --jerry-tests
- run: $RUNNER -q --jerry-tests --build-debug
- run: $RUNNER -q --jerry-debugger
Expand All @@ -47,6 +50,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v4
with:
python-version: '>=3.6'
- run: sudo apt update
- run: sudo apt install gcc-multilib
- run: $RUNNER -q --jerry-tests --buildoptions=--compile-flag=-m32,--cpointer-32bit=on
Expand All @@ -56,20 +62,29 @@ jobs:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v4
with:
python-version: '>=3.6'
- run: $RUNNER -q --jerry-tests
- run: $RUNNER -q --unittests

OSX_x86-64_Build_Correctness_Unit_Tests_Debug:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v4
with:
python-version: '>=3.6'
- run: $RUNNER -q --jerry-tests --build-debug
- run: $RUNNER -q --unittests --build-debug

Linux_x86-64_Build_Option_Tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v4
with:
python-version: '>=3.6'
- run: sudo apt update
- run: sudo apt install gcc-multilib
- run: $RUNNER --buildoption-test
Expand All @@ -78,6 +93,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v4
with:
python-version: '>=3.6'
- run: $RUNNER --test262 update
- uses: actions/upload-artifact@v2
if: success() || failure()
Expand All @@ -90,6 +108,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v4
with:
python-version: '>=3.6'
- run: $RUNNER --test262 update --build-debug --test262-test-list=built-ins,annexB,harness,intl402
- uses: actions/upload-artifact@v2
if: success() || failure()
Expand All @@ -102,6 +123,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v4
with:
python-version: '>=3.6'
- run: $RUNNER --test262 update --build-debug --test262-test-list=language
- uses: actions/upload-artifact@v2
if: success() || failure()
Expand All @@ -114,6 +138,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v4
with:
python-version: '>=3.6'
- run: $RUNNER -q --unittests
- run: $RUNNER -q --unittests --build-debug

Expand All @@ -123,6 +150,9 @@ jobs:
CC: clang
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v4
with:
python-version: '>=3.6'
- run: sudo apt update
- run: sudo apt install gcc-multilib
- run: $RUNNER -q --unittests
Expand All @@ -135,6 +165,9 @@ jobs:
ASAN_OPTIONS: detect_stack_use_after_return=1:check_initialization_order=true:strict_init_order=true
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v4
with:
python-version: '>=3.6'
- run: sudo apt update
- run: sudo apt install gcc-multilib
- run: >-
Expand All @@ -148,6 +181,9 @@ jobs:
ASAN_OPTIONS: detect_stack_use_after_return=1:check_initialization_order=true:strict_init_order=true
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v4
with:
python-version: '>=3.6'
- run: sudo apt update
- run: sudo apt install gcc-multilib
- run: >-
Expand All @@ -161,6 +197,9 @@ jobs:
UBSAN_OPTIONS: print_stacktrace=1
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v4
with:
python-version: '>=3.6'
- run: sudo apt update
- run: sudo apt install gcc-multilib
- run: >-
Expand All @@ -179,6 +218,9 @@ jobs:
TIMEOUT: 300
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v4
with:
python-version: '>=3.6'
- run: sudo apt update
- run: sudo apt install gcc-arm-linux-gnueabihf libc6-dev-armhf-cross qemu-user-static
- run: >-
Expand All @@ -192,6 +234,9 @@ jobs:
TIMEOUT: 300
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v4
with:
python-version: '>=3.6'
- run: sudo apt update
- run: sudo apt install gcc-arm-linux-gnueabihf libc6-dev-armhf-cross qemu-user-static
- run: >-
Expand All @@ -205,6 +250,9 @@ jobs:
TIMEOUT: 300
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v4
with:
python-version: '>=3.6'
- run: sudo apt update
- run: sudo apt install gcc-aarch64-linux-gnu libc6-dev-armhf-cross qemu-user-static
- run: >-
Expand All @@ -218,6 +266,9 @@ jobs:
TIMEOUT: 300
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v4
with:
python-version: '>=3.6'
- run: sudo apt update
- run: sudo apt install gcc-aarch64-linux-gnu libc6-dev-armhf-cross qemu-user-static
- run: >-
Expand All @@ -242,9 +293,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/setup-python@v4
with:
python-version: '3.x'
python-version: '>=3.6'
- run: sudo apt update
- run: sudo apt install gperf dfu-util device-tree-compiler
- run: make -f ./targets/os/zephyr/Makefile.travis install
Expand All @@ -254,6 +305,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v4
with:
python-version: '>=3.6'
- run: sudo apt update
- run: sudo apt install gcc-arm-none-eabi libnewlib-arm-none-eabi gperf
- run: make -f ./targets/os/nuttx/Makefile.travis install-noapt
Expand All @@ -276,9 +330,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/setup-python@v4
with:
python-version: '3.8'
python-version: '>=3.8'
- run: make -f ./targets/baremetal-sdk/espressif/esp8266-rtos-sdk/Makefile.travis install-noapt
- run: make -f ./targets/baremetal-sdk/espressif/esp8266-rtos-sdk/Makefile.travis script

Expand Down
21 changes: 10 additions & 11 deletions jerry-debugger/jerry_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import print_function
from cmd import Cmd
from pprint import pprint
import math
Expand Down Expand Up @@ -42,7 +41,7 @@ def __init__(self, debugger):
def precmd(self, line):
self.stop = False
if self.debugger.non_interactive:
print("%s" % line)
print(f"{line}")
return line

def postcmd(self, stop, line):
Expand Down Expand Up @@ -104,14 +103,14 @@ 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

args -= 1
except ValueError as val_errno:
print("Error: expected a positive integer: %s" % val_errno)
print(f"Error: expected a positive integer: {val_errno}")
do_n = do_next

def do_step(self, _):
Expand Down Expand Up @@ -185,10 +184,10 @@ def do_eval_at(self, args):
code = args[1]

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

except ValueError as val_errno:
print("Error: %s" % (val_errno))
print(f"Error: {val_errno}")
return

self.debugger.eval_at(code, index)
Expand Down Expand Up @@ -259,10 +258,10 @@ def src_check_args(args):

return line_num
except ValueError as val_errno:
print("Error: Non-negative integer number expected: %s" % (val_errno))
print(f"Error: Non-negative integer number expected: {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 +324,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 +338,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))
sys.exit(f"Failed to connect to the JerryScript debugger.\nError: {MSG}")
Loading

0 comments on commit bc408b1

Please sign in to comment.