Configure pre-commit https://pre-commit.com/ and some documentation on tools (#761)

* Add basic https://pre-commit.com/ config

* Move Black config up to a -dev requirements

* Some documentation on Black
adapted from RLO equivalent, by Vitaly Kurin

* We now use the Black default line length

* Use requirements-dev.txt
This commit is contained in:
Colin Gravill 2021-05-14 15:01:09 +01:00 коммит произвёл GitHub
Родитель 7813569fa9
Коммит 54499a6374
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 48 добавлений и 2 удалений

2
.github/workflows/pythonchecks.yml поставляемый
Просмотреть файл

@ -23,7 +23,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install black==19.10b0 flake8
python -m pip install -r requirements-dev.txt
# if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
# - name: Lint with flake8

14
.pre-commit-config.yaml Normal file
Просмотреть файл

@ -0,0 +1,14 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
# - repo: https://github.com/pre-commit/pre-commit-hooks
# rev: v3.2.0
# hooks:
# - id: trailing-whitespace
# - id: end-of-file-fixer
# - id: check-yaml
# - id: check-added-large-files
- repo: https://github.com/psf/black
rev: 19.10b0
hooks:
- id: black

2
requirements-dev.txt Normal file
Просмотреть файл

@ -0,0 +1,2 @@
pre-commit==2.12.1
black==19.10b0

Просмотреть файл

@ -3,4 +3,3 @@ sexpdata==0.0.3
numpy==1.20.2
jax==0.1.57
editdistance==0.5.3
black==19.10b0

31
tools.md Normal file
Просмотреть файл

@ -0,0 +1,31 @@
# Tools
`knossos` has various continuous-integration (CI) tests in place to ensure code quality and correctness, including formatting. The following tools may make it easier to comply with these checks locally before checking in code and failing the various CI tests. They are not automatically integrated into the workflow.
## VSCode
`knossos` uses [black](https://github.com/psf/black) for formatting. Note we currently use the default black line length of `88`. You may find the following settings useful. To use, copy them into `.vscode/settings.json` (don't commit them, they are covered by .gitignored) or your user settings:
```json
"python.formatting.provider": "black",
"editor.formatOnSave": true,
```
## [Pre-commit](https://github.com/pre-commit)
Pre-commit is a package manager for various git hooks that process files and can help with consistency and correctness. It is configured in [.pre-commit-config.yaml](.pre-commit-config.yaml) . If any changes are made, you will need to re-stage the relevant files and try again.
Per-user, to setup, run
```bash
pip install --requirement .\requirements-dev.txt
pre-commit install
```
Usually pre-commit will only be run on staged files. The first run will take a bit of time, but subsequent runs should be relatively fast.
You can apply pre-commit and hooks to all files using
```bash
pre-commit run --all-files
```