-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Format Python code. Add a GHA workflow using pre-commit to make sure that the Python code is formatted appropriately according to the specified config file. Documentation: https://pre-commit.com/hooks.html
- Loading branch information
1 parent
2ba47ea
commit b8168f1
Showing
3 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: code format | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
pre-commit: | ||
|
||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest] | ||
python-version: ['3.10'] | ||
requires: ['latest'] | ||
|
||
steps: | ||
- name: Check out repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Install and run pre-commit hooks | ||
uses: pre-commit/action@v3.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
default_language_version: | ||
python: python3.10 | ||
|
||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v3.4.0 | ||
hooks: | ||
- id: check-added-large-files | ||
name: check-added-large-files | ||
description: Prevent giant files from being committed. | ||
- id: check-ast | ||
name: check-ast | ||
description: Simply check whether files parse as valid python. | ||
- id: check-case-conflict | ||
- id: check-docstring-first | ||
- id: check-executables-have-shebangs | ||
- id: check-merge-conflict | ||
name: check-merge-conflict | ||
description: Check for files that contain merge conflict strings. | ||
- id: check-toml | ||
- id: check-yaml | ||
exclude: .github/workflows | ||
- id: end-of-file-fixer | ||
- id: mixed-line-ending | ||
- id: trailing-whitespace | ||
|
||
- repo: https://github.com/timothycrosley/isort | ||
rev: 5.12.0 | ||
hooks: | ||
- id: isort | ||
name: isort | ||
args: [--settings-path, ./pyproject.toml] | ||
types: [python] | ||
|
||
- repo: https://github.com/psf/black | ||
rev: 22.12.0 | ||
hooks: | ||
- id: black | ||
name: black | ||
args: [--config, ./pyproject.toml] | ||
types: [python] | ||
|
||
- repo: https://github.com/pycqa/flake8 | ||
rev: 3.9.2 | ||
hooks: | ||
- id: flake8 | ||
name: flake8 | ||
additional_dependencies: [flake8-docstrings==1.6.0] | ||
args: [--config, ./setup.cfg] | ||
types: [python] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
[tool.black] | ||
line-length = 79 | ||
target-version = ["py310"] | ||
exclude =''' | ||
( | ||
/( | ||
\.eggs # exclude a few common directories in the | ||
| \.git # root of the project | ||
| \.hg | ||
| \.mypy_cache | ||
| \.tox | ||
| \.venv | ||
| _build | ||
| buck-out | ||
| build | ||
| dist | ||
)/ | ||
| data # also separately exclude project-specific files | ||
# and folders in the root of the project | ||
) | ||
''' | ||
|
||
[tool.isort] | ||
profile = "black" | ||
line_length = 79 | ||
|