Add pre commit (#103)

* add pre-commit

* run pre-commit

* skip lint on README.md as it breaks template filling
This commit is contained in:
Paul Robinson
2023-10-04 13:32:07 -06:00
committed by GitHub
parent efcb97c348
commit 7099bbaaa4
15 changed files with 82 additions and 67 deletions

View File

@ -20,4 +20,3 @@ values =
[bumpversion:file:setup.py]
search = version="{current_version}",
replace = version="{new_version}",

View File

@ -25,6 +25,9 @@ common: &common
command: |
python -m pip install --upgrade pip
python -m pip install tox
- run:
name: install pre-commit
command: python -m pip install --progress-bar=off pre-commit
- run:
name: run tox
command: python -m tox run -r
@ -102,12 +105,6 @@ jobs:
environment:
TOXENV: py311-core
py37-lint:
<<: *common
docker:
- image: cimg/python:3.7
environment:
TOXENV: py37-lint
py38-lint:
<<: *common
docker:

View File

@ -6,12 +6,13 @@ Closes #
### How was it fixed?
### Todo:
- [ ] Clean up commit history
- [ ] Add or update documentation related to these changes
- \[ \] Clean up commit history
- [ ] Add entry to the [release notes](https://github.com/ethereum/<REPO_NAME>/blob/main/newsfragments/README.md)
- \[ \] Add or update documentation related to these changes
- \[ \] Add entry to the [release notes](https://github.com/ethereum/%3CREPO_NAME%3E/blob/main/newsfragments/README.md)
#### Cute Animal Picture
![Put a link to a cute animal picture inside the parenthesis-->]()
![Put a link to a cute animal picture inside the parenthesis-->](<>)

37
.pre-commit-config.yaml Normal file
View File

@ -0,0 +1,37 @@
exclude: '.project-template|docs/conf.py'
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
hooks:
- id: check-yaml
- id: check-toml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 23.9.1
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
- id: flake8
additional_dependencies:
- flake8-bugbear==23.9.16
exclude: setup.py
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/pycqa/pydocstyle
rev: 6.3.0
hooks:
- id: pydocstyle
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.17
hooks:
- id: mdformat
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.5.1
hooks:
- id: mypy
exclude: tests/

View File

@ -5,8 +5,7 @@ CURRENT_SIGN_SETTING := $(shell git config commit.gpgSign)
help:
@echo "clean-build - remove build artifacts"
@echo "clean-pyc - remove Python file artifacts"
@echo "lint - check style with mypy, flake8, isort, pydocstyle, and black"
@echo "lint-roll - automatically fix problems with flake8 and black"
@echo "lint - fix linting issues with pre-commit
@echo "test - run tests quickly with the default Python"
@echo "docs - generate docs and open in browser (linux-docs for version on linux)"
@echo "notes - consume towncrier newsfragments/ and update release notes in docs/"
@ -27,12 +26,7 @@ clean-pyc:
find . -name '__pycache__' -exec rm -rf {} +
lint:
tox run -e lint
lint-roll:
isort <MODULE_NAME> tests
black <MODULE_NAME> tests setup.py
$(MAKE) lint
pre-commit run --all-files --show-diff-on-failure
test:
pytest tests

View File

@ -24,9 +24,13 @@ for information on how we do:
- Testing
- Pull Requests
- Code Style
- Documentation
We use [pre-commit](https://pre-commit.com/) to maintain consistent code style. Once
installed, it will run automatically with every commit. You can also run it manually
with `make lint`. If you need to make a commit that skips the `pre-commit` checks, you
can do so with `git commit --no-verify`.
### Development Environment Setup
You can set up your dev environment with:
@ -37,6 +41,7 @@ cd <REPO_NAME>
virtualenv -p python3 venv
. venv/bin/activate
python -m pip install -e ".[dev]"
pre-commit install
```
### Release setup

View File

@ -11,7 +11,7 @@ Contents
<MODULE_NAME>
release_notes
Indices and tables
------------------

View File

@ -8,15 +8,15 @@ relevant to people working on the code itself.)
Each file should be named like `<ISSUE>.<TYPE>.rst`, where
`<ISSUE>` is an issue number, and `<TYPE>` is one of:
* `breaking`
* `bugfix`
* `deprecation`
* `docs`
* `feature`
* `internal`
* `misc`
* `performance`
* `removal`
- `breaking`
- `bugfix`
- `deprecation`
- `docs`
- `feature`
- `internal`
- `misc`
- `performance`
- `removal`
So for example: `123.feature.rst`, `456.bugfix.rst`

View File

@ -31,7 +31,6 @@ if num_args == 1:
assert sys.argv[1] in ("is-empty",)
for fragment_file in THIS_DIR.iterdir():
if fragment_file.name in ALLOWED_FILES:
continue
elif num_args == 0:

View File

@ -1,44 +1,34 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from setuptools import (
setup,
find_packages,
setup,
)
extras_require = {
"test": [
"pytest>=7.0.0",
"pytest-xdist>=2.4.0",
],
"lint": [
"flake8==6.0.0", # flake8 claims semver but adds new warnings at minor releases, leave it pinned.
"flake8-bugbear==23.3.23", # flake8-bugbear does not follow semver, leave it pinned.
"isort>=5.10.1",
"mypy==0.971", # mypy does not follow semver, leave it pinned.
"pydocstyle>=6.0.0",
"black>=23",
"dev": [
"build>=0.9.0",
"bumpversion>=0.5.3",
"ipython",
"pre-commit>=3.4.0",
"pytest-watch>=4.1.0",
"tox>=4.0.0",
"twine",
"wheel",
],
"docs": [
"sphinx>=6.0.0",
"sphinx_rtd_theme>=1.0.0",
"towncrier>=21,<22",
],
"dev": [
"bumpversion>=0.5.3",
"pytest-watch>=4.1.0",
"tox>=4.0.0",
"build>=0.9.0",
"wheel",
"twine",
"ipython",
"test": [
"pytest>=7.0.0",
"pytest-xdist>=2.4.0",
],
}
extras_require["dev"] = (
extras_require["dev"]
+ extras_require["test"]
+ extras_require["lint"]
+ extras_require["docs"]
extras_require["dev"] + extras_require["docs"] + extras_require["test"]
)

17
tox.ini
View File

@ -1,7 +1,7 @@
[tox]
envlist=
py{37,38,39,310,311}-core
py{37,38,39,310,311}-lint
py{38,39,310,311}-lint
py{37,38,39,310,311}-wheel
py311-wheel-windows
docs
@ -36,26 +36,19 @@ basepython=
extras=
test
docs
allowlist_externals=make
allowlist_externals=make,pre-commit
[common-lint]
basepython=python
extras=lint
allowlist_externals=black
deps=pre-commit
commands=
mypy -p <MODULE_NAME> --config-file {toxinidir}/mypy.ini
flake8 {toxinidir}/<MODULE_NAME> {toxinidir}/tests
isort --check-only --diff {toxinidir}/<MODULE_NAME> {toxinidir}/tests
pydocstyle --explain {toxinidir}/<MODULE_NAME> {toxinidir}/tests
black --check {toxinidir}/<MODULE_NAME> {toxinidir}/docs {toxinidir}/tests {toxinidir}/setup.py
pre-commit run --all-files --show-diff-on-failure
[testenv:lint]
basepython: python
extras: {[common-lint]extras}
commands: {[common-lint]commands}
[testenv:py{37,38,39,310,311}-lint]
extras: {[common-lint]extras}
[testenv:py{38,39,310,311}-lint]
commands: {[common-lint]commands}
[testenv:py{37,38,39,310,311}-wheel]