diff --git a/.github/workflows/python-code-format.yml b/.github/workflows/python-code-format.yml new file mode 100644 index 0000000..921e340 --- /dev/null +++ b/.github/workflows/python-code-format.yml @@ -0,0 +1,42 @@ +name: Check Python code formatting + +on: + push: + branches: [main, cleanup] + pull_request: + branches: [main] + types: [opened, synchronize, reopened] + schedule: + - cron: "0 5 * * *" + +permissions: + contents: read + +jobs: + test: + runs-on: ubuntu-22.04 + + name: Check Python code formatting + steps: + - uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.11" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + if [ -f test-requirements.txt ]; then pip install -r test-requirements.txt; fi + - name: Analysing the code with pylint + run: | + python -m pylint *.py + - name: Check code formatting with isort + run: | + python -m isort *.py --check --verbose + - name: Check code formatting with black + run: | + python -m black *.py --check --verbose + - name: Lint with flake8 + run: | + python -m flake8 *.py --count --show-source --statistics diff --git a/README.md b/README.md index 263cd64..23d4cda 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,35 @@ Manually install [ucapi](https://github.com/aitatoi/integration-python-library) pip3 install ../integration-python-library/dist/ucapi-$UCAPI_PYTHON_LIB_VERSION-py3-none-any.whl ``` +## Code Style + +- Code line length: 120 +- Use double quotes as default (don't mix and match for simple quoting, checked with pylint). + +Install tooling: +```console +pip3 install -r test-requirements.txt +``` + +### Verify +```console +python -m pylint *.py +python -m flake8 *.py --count --show-source --statistics +python -m isort *.py --check --verbose +python -m black *.py --check --verbose --line-length 120 +``` + +### Format Code +```console +python -m black *.py --line-length 120 +``` + +### Sort Imports + +```console +python -m isort *.py +``` + ## Build self-contained binary After some tests, turns out python stuff on embedded is a nightmare. So we're better off creating a single binary file that has everything in it. diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..f3cd0f3 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,6 @@ +[project.readme] +file = "README.md" +content-type = "text/markdown; charset=UTF-8" + +[tool.isort] +profile = "black" diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..11c0f7e --- /dev/null +++ b/tox.ini @@ -0,0 +1,36 @@ +[flake8] +max_line_length = 120 + +[tox] +envlist = py39,py310,py311,pylint,lint,format +skip_missing_interpreters = True + +[testenv:format] +basepython = python3.11 +deps = + -r{toxinidir}/test-requirements.txt +commands = + python -m isort *.py --check --verbose + python -m black *.py --check --verbose + +[testenv:pylint] +basepython = python3.11 +deps = + -r{toxinidir}/test-requirements.txt +commands=python -m pylint *.py + +[testenv:lint] +basepython = python3.11 +deps = + -r{toxinidir}/test-requirements.txt +commands = + python -m flake8 *.py +; python -m pydocstyle *.py + +;[testenv] +;setenv = +; LANG=en_US.UTF-8 +; PYTHONPATH = {toxinidir} +;deps = +; -r{toxinidir}/test-requirements.txt +;commands=python -m pytest tests --timeout=30 --durations=10 --cov=denonavr --cov-report html {posargs}