Skip to content

Commit

Permalink
GitHub action to check Python code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
zehnm committed Oct 24, 2023
1 parent c7873ac commit e5f0e79
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 0 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/python-code-format.yml
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[project.readme]
file = "README.md"
content-type = "text/markdown; charset=UTF-8"

[tool.isort]
profile = "black"
36 changes: 36 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -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}

0 comments on commit e5f0e79

Please sign in to comment.