|
| 1 | +# "Check Python" workflow (Task) |
| 2 | + |
| 3 | +Workflow file: [check-python-task.yml](check-python-task.yml) |
| 4 | + |
| 5 | +Run [flake8](https://flake8.pycqa.org/) and [black](https://github.com/psf/black) on the Python files of the repository. |
| 6 | + |
| 7 | +This is the version of the workflow for projects using the [Task](https://taskfile.dev/#/) task runner tool. |
| 8 | + |
| 9 | +## Installation |
| 10 | + |
| 11 | +### 1. Add configuration files |
| 12 | + |
| 13 | +Copy the configuration files listed in the [**Assets**](#assets) section below into the project's repository. |
| 14 | + |
| 15 | +If the project already contains a [`pyproject.toml`](https://www.python.org/dev/peps/pep-0518/) file, then merge them. |
| 16 | + |
| 17 | +### 2. Install tool dependencies |
| 18 | + |
| 19 | +The tool dependencies of this workflow are managed by [Poetry](https://python-poetry.org/). |
| 20 | + |
| 21 | +Install Poetry by following these instructions:<br /> |
| 22 | +https://python-poetry.org/docs/#installation |
| 23 | + |
| 24 | +If your project does not already use Poetry, you can initialize the [`pyproject.toml`](https://python-poetry.org/docs/pyproject/) file using these commands: |
| 25 | + |
| 26 | +``` |
| 27 | +poetry init --python="^3.9" --dev-dependency="black@^21.5b0" --dev-dependency="flake8@^3.9.2" --dev-dependency="pep8-naming@^0.11.1" |
| 28 | +poetry install |
| 29 | +``` |
| 30 | + |
| 31 | +If already using Poetry, add the tool using this command: |
| 32 | + |
| 33 | +``` |
| 34 | +poetry add --dev "black@^21.5b0" "flake8@^3.9.2" "pep8-naming@^0.11.1" |
| 35 | +``` |
| 36 | + |
| 37 | +Make sure to commit the resulting `pyproject.toml` and `poetry.lock` files. |
| 38 | + |
| 39 | +### 3. Configuration |
| 40 | + |
| 41 | +Add the following to `pyproject.toml`: |
| 42 | + |
| 43 | +```toml |
| 44 | +[tool.black] |
| 45 | +line-length = 120 |
| 46 | +``` |
| 47 | + |
| 48 | +## Assets |
| 49 | + |
| 50 | +- [`.flake8`](assets/check-python/.flake8) - flake8 configuration file. |
| 51 | + - Install to: repository root |
| 52 | +- [`Taskfile.yml`](assets/check-python-task/Taskfile.yml] - Python linting and formatting tasks. |
| 53 | + - Install to: repository root (or add the tasks into the existing `Taskfile.yml`) |
| 54 | +- [`Taskfile.yml`](assets/shared/Taskfile.yml] - Installation task. |
| 55 | + - Add the `poetry:install-deps` task into the existing `Taskfile.yml` |
| 56 | + |
| 57 | +The code style defined in `pyproject.toml` and `.flake8` is the official standardized style to be used in all Arduino tooling projects and should not be modified. |
| 58 | + |
| 59 | +## Readme badge |
| 60 | + |
| 61 | +Markdown badge: |
| 62 | + |
| 63 | +```markdown |
| 64 | +[](https://github.com/REPO_OWNER/REPO_NAME/actions/workflows/check-python-task.yml) |
| 65 | +``` |
| 66 | + |
| 67 | +Replace the `REPO_OWNER` and `REPO_NAME` placeholders in the URLs with the final repository owner and name ([example](https://raw.githubusercontent.com/arduino-libraries/ArduinoIoTCloud/master/README.md)). |
| 68 | + |
| 69 | +--- |
| 70 | + |
| 71 | +Asciidoc badge: |
| 72 | + |
| 73 | +```adoc |
| 74 | +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-python-task.yml/badge.svg["Check Python status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-python-task.yml"] |
| 75 | +``` |
| 76 | + |
| 77 | +Define the `{repository-owner}` and `{repository-name}` attributes and use them throughout the readme ([example](https://raw.githubusercontent.com/arduino-libraries/WiFiNINA/master/README.adoc)). |
| 78 | + |
| 79 | +## Commit message |
| 80 | + |
| 81 | +``` |
| 82 | +Add CI workflow to lint and check formatting of Python files |
| 83 | + |
| 84 | +On every push and pull request that affects relevant files, and periodically, run flake8 to check the Python files of |
| 85 | +the repository for issues and black to check formatting. |
| 86 | + |
| 87 | +The .flake8 file is used to configure flake8: |
| 88 | +https://flake8.pycqa.org/en/latest/user/configuration.html |
| 89 | +``` |
| 90 | +
|
| 91 | +## PR message |
| 92 | +
|
| 93 | +```markdown |
| 94 | +On every push and pull request that affects relevant files, and periodically, run [`flake8`](https://flake8.pycqa.org/) to check the Python files of the repository for issues and [black](https://github.com/psf/black) to check formatting. |
| 95 | +
|
| 96 | +The `.flake8` file is used to configure `flake8`: |
| 97 | +https://flake8.pycqa.org/en/latest/user/configuration.html |
| 98 | +``` |
0 commit comments