From f1cb6713cef394e3ff00c3d1befebba59ff9866c Mon Sep 17 00:00:00 2001 From: SorinO Date: Tue, 3 Mar 2026 18:47:17 +0200 Subject: [PATCH 1/7] scripts: add python linter and formatter Signed-off-by: SorinO --- scripts/check_py_formatting.sh | 36 ++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 scripts/check_py_formatting.sh diff --git a/scripts/check_py_formatting.sh b/scripts/check_py_formatting.sh new file mode 100644 index 00000000..add15c69 --- /dev/null +++ b/scripts/check_py_formatting.sh @@ -0,0 +1,36 @@ +#!/bin/sh +# @copyright Copyright (c) contributors to Project Ocre, +# which has been established as Project Ocre a Series of LF Projects, LLC +# +# SPDX-License-Identifier: Apache-2.0 + +# Python formatter and linter +# Checks all .py files agains autopep8 rules +# Usage: check_py_formatting.sh [-f] +# -f Fix files in place(formatting) + +set -e + +ARGUMENT="--diff --exit-code" + +if [ $# -eq 1 ]; then + if [ "$1" = "-f" ]; then + echo "Fixing files in place if necessary" + ARGUMENT="--in-place" + else + echo "Invalid option: $1" + exit 1 + fi +fi + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +ROOT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" +cd "$ROOT_DIR" + +echo "Checking Python formatting." + +find . -type f -name '*.py' \ + ! -path './tests/Unity/*' \ + ! -path './wasm-micro-runtime/*' \ + ! -path './ocre-sdk/*' \ + -print0 | xargs -0 autopep8 ${ARGUMENT} From e125b1e0d1b0c3101e4ca3074f72928d95042b26 Mon Sep 17 00:00:00 2001 From: SorinO Date: Tue, 3 Mar 2026 18:49:42 +0200 Subject: [PATCH 2/7] tests_hw: format all python files in accordance with autopep8 rules Signed-off-by: SorinO --- tests_hw/groups/demo/testcase.py | 9 +++++---- .../flashValidation/flash_validation_hello_world.py | 3 ++- tests_hw/groups/mini/testcase.py | 10 ++++++---- tests_hw/groups/supervisor-helloWorld/clean.py | 7 ++++--- tests_hw/groups/supervisor-helloWorld/setup.py | 13 +++++++------ tests_hw/groups/supervisor-helloWorld/testcase.py | 10 ++++++---- tests_hw/testlib.py | 5 +++-- 7 files changed, 33 insertions(+), 24 deletions(-) diff --git a/tests_hw/groups/demo/testcase.py b/tests_hw/groups/demo/testcase.py index 260b4c8b..cbed668e 100755 --- a/tests_hw/groups/demo/testcase.py +++ b/tests_hw/groups/demo/testcase.py @@ -3,8 +3,8 @@ import sys sys.path.append("../..") -import pexpect -import testlib +import pexpect # noqa: E402 +import testlib # noqa: E402 """ This testcase is to be used following the flashing of the default demo sample to a board. @@ -24,6 +24,7 @@ "Demo completed successfully", ] + def main(): serial_conn, pex = testlib.setup('/dev/ttyACM0') serial_conn.send_break() @@ -43,6 +44,6 @@ def main(): testlib.format_runtime_output(runtime_output, "Entire") testlib.full_exit(serial_conn, 0) - + if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/tests_hw/groups/flashValidation/flash_validation_hello_world.py b/tests_hw/groups/flashValidation/flash_validation_hello_world.py index 251403ab..9e8babe6 100755 --- a/tests_hw/groups/flashValidation/flash_validation_hello_world.py +++ b/tests_hw/groups/flashValidation/flash_validation_hello_world.py @@ -11,6 +11,7 @@ the string Hello World! appears in the output of that break command. """ + def main(): conn = serial.Serial('/dev/ttyACM0', 115200, timeout=10) @@ -43,4 +44,4 @@ def main(): if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/tests_hw/groups/mini/testcase.py b/tests_hw/groups/mini/testcase.py index 9a57bc01..0bffe90d 100755 --- a/tests_hw/groups/mini/testcase.py +++ b/tests_hw/groups/mini/testcase.py @@ -3,8 +3,9 @@ import sys sys.path.append("../..") -import pexpect -import testlib +import pexpect # noqa: E402 +import testlib # noqa: E402 + """ This testcase is to be used following the flashing of the default mini sample to a board. @@ -17,6 +18,7 @@ "powered by Ocre", ] + def main(): serial_conn, pex = testlib.setup('/dev/ttyACM0') serial_conn.send_break() @@ -36,6 +38,6 @@ def main(): testlib.format_runtime_output(runtime_output, "Entire") testlib.full_exit(serial_conn, 0) - + if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/tests_hw/groups/supervisor-helloWorld/clean.py b/tests_hw/groups/supervisor-helloWorld/clean.py index a751d939..907bc04c 100755 --- a/tests_hw/groups/supervisor-helloWorld/clean.py +++ b/tests_hw/groups/supervisor-helloWorld/clean.py @@ -3,8 +3,8 @@ import sys sys.path.append("../..") -import pexpect -import testlib +import testlib # noqa: E402 +import pexpect # noqa: E402 def main(): @@ -21,5 +21,6 @@ def main(): testlib.format_runtime_output(runtime_output, "Cleanup") testlib.full_exit(serial_conn, 0) + if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/tests_hw/groups/supervisor-helloWorld/setup.py b/tests_hw/groups/supervisor-helloWorld/setup.py index e8421105..4f3df8a0 100755 --- a/tests_hw/groups/supervisor-helloWorld/setup.py +++ b/tests_hw/groups/supervisor-helloWorld/setup.py @@ -3,8 +3,9 @@ import sys sys.path.append("../..") -import testlib -import pexpect +import testlib # noqa: E402 +import pexpect # noqa: E402 + def main(): serial_conn, pex = testlib.setup('/dev/ttyACM0') @@ -13,7 +14,7 @@ def main(): pex.write(b'ocre create -n hello-world -k ocre:api hello-world.wasm\n') expect_index = pex.expect(["ocre:~$", pexpect.TIMEOUT], 30) runtime_output = bytes(pex.before).decode(errors='ignore') - + if (expect_index == 1): print("Container failed to create container in given timeout") testlib.format_runtime_output(runtime_output, "Failed") @@ -23,9 +24,9 @@ def main(): print("Failed to create container") testlib.format_runtime_output(runtime_output, "Failed") testlib.full_exit(serial_conn, 1) - + testlib.full_exit(serial_conn, 0) - + if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/tests_hw/groups/supervisor-helloWorld/testcase.py b/tests_hw/groups/supervisor-helloWorld/testcase.py index 4b6bd759..b981bf76 100755 --- a/tests_hw/groups/supervisor-helloWorld/testcase.py +++ b/tests_hw/groups/supervisor-helloWorld/testcase.py @@ -3,8 +3,8 @@ import sys sys.path.append("../..") -import pexpect -import testlib +import pexpect # noqa: E402 +import testlib # noqa: E402 """ This testcase is to be used following the flashing of the supervisor sample to a board with the hello-world container put up. @@ -15,6 +15,7 @@ line = "powered by Ocre" + def main(): serial_conn, pex = testlib.setup('/dev/ttyACM0') @@ -36,6 +37,7 @@ def main(): testlib.format_runtime_output(runtime_output, "Entire") testlib.full_exit(serial_conn, 0) - + + if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/tests_hw/testlib.py b/tests_hw/testlib.py index a138c633..883efa2c 100644 --- a/tests_hw/testlib.py +++ b/tests_hw/testlib.py @@ -4,7 +4,8 @@ import pexpect.fdpexpect from typing import Tuple -shell_prompt = "ocre:~$" +shell_prompt = "ocre:~$" + def setup(device_filepath: str) -> Tuple[serial.Serial, pexpect.fdpexpect.fdspawn]: conn = serial.Serial(device_filepath, 115200, timeout=10) @@ -29,4 +30,4 @@ def format_runtime_output(runtime_output: str, section: str) -> None: {runtime_output} ==========--------------------------========== """) - return \ No newline at end of file + return From 5ba19aa8c830110c772d91bc1622d1dc33c5d139 Mon Sep 17 00:00:00 2001 From: SorinO Date: Tue, 3 Mar 2026 18:51:04 +0200 Subject: [PATCH 3/7] ci(formatting-checks): add python checks to the CI Signed-off-by: SorinO --- .devcontainer/linux/Dockerfile | 1 + .github/workflows/formatting-checks.yml | 3 +++ 2 files changed, 4 insertions(+) diff --git a/.devcontainer/linux/Dockerfile b/.devcontainer/linux/Dockerfile index 3301d47d..1517f67a 100644 --- a/.devcontainer/linux/Dockerfile +++ b/.devcontainer/linux/Dockerfile @@ -33,6 +33,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ sudo \ jq \ yamllint \ + python3-autopep8 \ && curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \ echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list && \ apt-get update && apt-get install -y --no-install-recommends \ diff --git a/.github/workflows/formatting-checks.yml b/.github/workflows/formatting-checks.yml index dd38741d..8863a5ca 100644 --- a/.github/workflows/formatting-checks.yml +++ b/.github/workflows/formatting-checks.yml @@ -39,6 +39,9 @@ jobs: - name: Run YAML Format Checks run: sh scripts/yml_linter.sh + - name: Run Python Format Checks + run: sh scripts/check_py_formatting.sh + - name: License Banner Checks(.c files) run: sh scripts/check_license_banner_c.sh From b6cf4a95de202b737187e29038128252d5ada9a4 Mon Sep 17 00:00:00 2001 From: SorinO Date: Wed, 4 Mar 2026 11:21:52 +0200 Subject: [PATCH 4/7] scripts: add python files to the license banner checker Signed-off-by: SorinO --- scripts/check_license_banner_conf_files.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/check_license_banner_conf_files.sh b/scripts/check_license_banner_conf_files.sh index fae8e4c9..ec8003f5 100644 --- a/scripts/check_license_banner_conf_files.sh +++ b/scripts/check_license_banner_conf_files.sh @@ -17,13 +17,13 @@ check_license_banner() { local file_header local start_line=1 - # Check first line and skip if it's a shebang line(only for .sh scripts) + # Skip shebang line if present (e.g. #!/bin/sh or #!/usr/bin/python3) local first_line first_line=$(head -n 1 "$file") - if [ "${first_line#\#\!/bin}" != "$first_line" ]; then + if [ "${first_line#\#\!/bin}" != "$first_line" ] || [ "${first_line#\#\!/usr/bin}" != "$first_line" ]; then start_line=2 fi - + file_header=$(tail -n +$start_line "$file" | head -n 4) # Expected license banner @@ -44,7 +44,7 @@ echo "Checking license banners." ERROR_FOUND=0 for file in $(find . -type f \( -name 'CMakeLists.txt' -o -name '*.yaml' \ -o -name '*.yml' -o -name '*.awk' -o -name '*.conf' -o -name 'Kconfig*' \ - -o -name '.gitignore' -o -name '.gitmodules' -o -name '*.sh' -o -name '*.cmake' \) \ + -o -name '.gitignore' -o -name '.gitmodules' -o -name '*.sh' -o -name '*.cmake' -o -name '*.py' \) \ ! -name 'utlist.h' \ ! -path './tests/Unity/*' \ ! -path './build/*' \ From 0a7f599202db4ec6f20d2c3cd58669188e36c147 Mon Sep 17 00:00:00 2001 From: SorinO Date: Wed, 4 Mar 2026 11:22:47 +0200 Subject: [PATCH 5/7] tests_hw: add license banner to all .py files Signed-off-by: SorinO --- tests_hw/groups/demo/testcase.py | 4 ++++ .../groups/flashValidation/flash_validation_hello_world.py | 4 ++++ tests_hw/groups/mini/testcase.py | 4 ++++ tests_hw/groups/supervisor-helloWorld/clean.py | 4 ++++ tests_hw/groups/supervisor-helloWorld/setup.py | 4 ++++ tests_hw/groups/supervisor-helloWorld/testcase.py | 4 ++++ tests_hw/testlib.py | 5 +++++ 7 files changed, 29 insertions(+) diff --git a/tests_hw/groups/demo/testcase.py b/tests_hw/groups/demo/testcase.py index cbed668e..76825892 100755 --- a/tests_hw/groups/demo/testcase.py +++ b/tests_hw/groups/demo/testcase.py @@ -1,4 +1,8 @@ #!/usr/bin/env python3 +# @copyright Copyright (c) contributors to Project Ocre, +# which has been established as Project Ocre a Series of LF Projects, LLC +# +# SPDX-License-Identifier: Apache-2.0 import sys sys.path.append("../..") diff --git a/tests_hw/groups/flashValidation/flash_validation_hello_world.py b/tests_hw/groups/flashValidation/flash_validation_hello_world.py index 9e8babe6..11904208 100755 --- a/tests_hw/groups/flashValidation/flash_validation_hello_world.py +++ b/tests_hw/groups/flashValidation/flash_validation_hello_world.py @@ -1,4 +1,8 @@ #!/usr/bin/env python3 +# @copyright Copyright (c) contributors to Project Ocre, +# which has been established as Project Ocre a Series of LF Projects, LLC +# +# SPDX-License-Identifier: Apache-2.0 import serial import time diff --git a/tests_hw/groups/mini/testcase.py b/tests_hw/groups/mini/testcase.py index 0bffe90d..2de891d6 100755 --- a/tests_hw/groups/mini/testcase.py +++ b/tests_hw/groups/mini/testcase.py @@ -1,4 +1,8 @@ #!/usr/bin/env python3 +# @copyright Copyright (c) contributors to Project Ocre, +# which has been established as Project Ocre a Series of LF Projects, LLC +# +# SPDX-License-Identifier: Apache-2.0 import sys sys.path.append("../..") diff --git a/tests_hw/groups/supervisor-helloWorld/clean.py b/tests_hw/groups/supervisor-helloWorld/clean.py index 907bc04c..cab24cd0 100755 --- a/tests_hw/groups/supervisor-helloWorld/clean.py +++ b/tests_hw/groups/supervisor-helloWorld/clean.py @@ -1,4 +1,8 @@ #!/usr/bin/env python3 +# @copyright Copyright (c) contributors to Project Ocre, +# which has been established as Project Ocre a Series of LF Projects, LLC +# +# SPDX-License-Identifier: Apache-2.0 import sys sys.path.append("../..") diff --git a/tests_hw/groups/supervisor-helloWorld/setup.py b/tests_hw/groups/supervisor-helloWorld/setup.py index 4f3df8a0..b44f20bc 100755 --- a/tests_hw/groups/supervisor-helloWorld/setup.py +++ b/tests_hw/groups/supervisor-helloWorld/setup.py @@ -1,4 +1,8 @@ #!/usr/bin/env python3 +# @copyright Copyright (c) contributors to Project Ocre, +# which has been established as Project Ocre a Series of LF Projects, LLC +# +# SPDX-License-Identifier: Apache-2.0 import sys sys.path.append("../..") diff --git a/tests_hw/groups/supervisor-helloWorld/testcase.py b/tests_hw/groups/supervisor-helloWorld/testcase.py index b981bf76..55fd7ae1 100755 --- a/tests_hw/groups/supervisor-helloWorld/testcase.py +++ b/tests_hw/groups/supervisor-helloWorld/testcase.py @@ -1,4 +1,8 @@ #!/usr/bin/env python3 +# @copyright Copyright (c) contributors to Project Ocre, +# which has been established as Project Ocre a Series of LF Projects, LLC +# +# SPDX-License-Identifier: Apache-2.0 import sys sys.path.append("../..") diff --git a/tests_hw/testlib.py b/tests_hw/testlib.py index 883efa2c..97a5ccc9 100644 --- a/tests_hw/testlib.py +++ b/tests_hw/testlib.py @@ -1,3 +1,8 @@ +# @copyright Copyright (c) contributors to Project Ocre, +# which has been established as Project Ocre a Series of LF Projects, LLC +# +# SPDX-License-Identifier: Apache-2.0 + import serial import sys import pexpect From f7c877c6b1256e7bf5f90364808af2d1fbba1467 Mon Sep 17 00:00:00 2001 From: SorinO Date: Wed, 4 Mar 2026 11:33:55 +0200 Subject: [PATCH 6/7] scripts: modify comment and folders to exclude Signed-off-by: SorinO --- scripts/check_license_banner_conf_files.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/scripts/check_license_banner_conf_files.sh b/scripts/check_license_banner_conf_files.sh index ec8003f5..04b95354 100644 --- a/scripts/check_license_banner_conf_files.sh +++ b/scripts/check_license_banner_conf_files.sh @@ -4,7 +4,7 @@ # # SPDX-License-Identifier: Apache-2.0 -# Checks all C/C++ files for license banner +# Checks license banner in all files that use '#' comment syntax set -e @@ -45,13 +45,10 @@ ERROR_FOUND=0 for file in $(find . -type f \( -name 'CMakeLists.txt' -o -name '*.yaml' \ -o -name '*.yml' -o -name '*.awk' -o -name '*.conf' -o -name 'Kconfig*' \ -o -name '.gitignore' -o -name '.gitmodules' -o -name '*.sh' -o -name '*.cmake' -o -name '*.py' \) \ - ! -name 'utlist.h' \ ! -path './tests/Unity/*' \ ! -path './build/*' \ ! -path './wasm-micro-runtime/*' \ ! -path './ocre-sdk/*' \ - ! -path './src/shell/sha256/*' \ - ! -path './src/runtime/wamr-wasip1/ocre_api/utils/*' \ | sort); do if ! check_license_banner "$file"; then From 5f9d109fbc8ef9c7f890e636bd05054306bf90a0 Mon Sep 17 00:00:00 2001 From: SorinO Date: Wed, 4 Mar 2026 12:32:18 +0200 Subject: [PATCH 7/7] scripts(yaml_linter): disable comments-indentation and line-length rules Signed-off-by: SorinO --- scripts/yml_linter_rules.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/scripts/yml_linter_rules.yml b/scripts/yml_linter_rules.yml index fbd2432f..0753defb 100644 --- a/scripts/yml_linter_rules.yml +++ b/scripts/yml_linter_rules.yml @@ -6,9 +6,7 @@ extends: default rules: - line-length: - max: 150 - level: warning + line-length: disable indentation: spaces: 2 document-start: disable @@ -18,3 +16,4 @@ rules: empty-lines: max: 1 truthy: {check-keys: false} + comments-indentation: disable