diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 6a9cbb84..6fee2550 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -1,4 +1,4 @@ -name: Python +name: Python Linting on: push: @@ -7,24 +7,26 @@ on: jobs: build: name: Python Linting - runs-on: ubuntu-20.04 + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v4 + - name: Install Python + uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55 + with: + python-version: '3.13' + - name: Install Python Deps - run: python3 -m pip install flake8 + run: source ci/python.sh && qa_prepare_all - - name: Lint micropython/modules_py + - name: Lint MicroPython Examples shell: bash - run: | - python3 -m flake8 --show-source --ignore E501 micropython/modules_py + run: source ci/python.sh && qa_examples_check - - name: Lint micropython/examples + - name: Lint MicroPython Modules shell: bash - run: | - python3 -m flake8 --show-source --ignore E501 micropython/examples + run: source ci/python.sh && qa_modules_check - - name: Lint .py tools in C++ examples + - name: Lint Python Tools shell: bash - run: | - python3 -m flake8 --show-source --ignore E501 examples \ No newline at end of file + run: source ci/python.sh && qa_tools_check \ No newline at end of file diff --git a/ci/python.sh b/ci/python.sh new file mode 100644 index 00000000..fe69a41e --- /dev/null +++ b/ci/python.sh @@ -0,0 +1,60 @@ +# Include: +# F = Pyflakes +# Q = Quotes +# E/W = pycodestyle (Whitespace, Line lengths etc) +# B - flake8-bugbear = Unused loop variables, sloppy code +# COM - flake8-commas +# BLE - flake8-blind-except +# C4 - flake8-comprehensions +# ISC - flake8-implicit-str-concat = Implicit string concat, eg: `"hello" "world"` on one line +# ICN - flake8-import-conventions = Import conventions +# PIE - flake8-pie = Misc silliness, catches range with a 0 start argument +# RET - flake8-return = Enforces straight-forward code around return statements +# SLF - flake8-self +# ARG - flake8-unused-arguments + +# Ignore: +# E501 - "line too long". How narrow is your screen!? +# E402 - "module level import not at top of file". Needs must! +# COM812 - "Add trailing comma". These are a little obnoxious and weird. +# ICN001 - "numpy should be imported as np". No. No it should not. + +QA_INCLUDE="F,Q,W,E,B,COM,BLE,C4,ISC,ICN,PIE,RSE,RET,SLF,ARG" +QA_IGNORE="E501,E402,COM812,ICN001" +QA_EXCLUDE="micropython/examples/common/lib/tinyweb/server.py,micropython/examples/pico_wireless/*" + +function qa_prepare_all { + pip install ruff +} + +function qa_check { + ruff check --select "$QA_INCLUDE" --ignore "$QA_IGNORE" --exclude "$QA_EXCLUDE" "$1" +} + +function qa_fix { + ruff check --select "$QA_INCLUDE" --ignore "$QA_IGNORE" --exclude "$QA_EXCLUDE" --fix "$1" +} + +function qa_examples_check { + qa_check micropython/examples +} + +function qa_examples_fix { + qa_fix micropython/examples +} + +function qa_modules_check { + qa_check micropython/modules_py +} + +function qa_modules_fix { + qa_fix micropython/modules_py +} + +function qa_tools_check { + qa_check examples +} + +function qa_tools_fix { + qa_fix examples +} \ No newline at end of file