diff --git a/.bumpversion.cfg b/.bumpversion.cfg index f683001f..39ae22d4 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -20,4 +20,3 @@ values = [bumpversion:file:setup.py] search = version="{current_version}", replace = version="{new_version}", - diff --git a/.circleci/config.yml b/.circleci/config.yml index 0f1436c0..bbc90296 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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: diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yaml similarity index 100% rename from .github/ISSUE_TEMPLATE/bug_report.yml rename to .github/ISSUE_TEMPLATE/bug_report.yaml diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yaml similarity index 100% rename from .github/ISSUE_TEMPLATE/config.yml rename to .github/ISSUE_TEMPLATE/config.yaml diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yaml similarity index 100% rename from .github/ISSUE_TEMPLATE/feature_request.yml rename to .github/ISSUE_TEMPLATE/feature_request.yaml diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 2ff2e071..3691f6b9 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -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//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-->]() \ No newline at end of file +![Put a link to a cute animal picture inside the parenthesis-->](<>) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..58f9e1d8 --- /dev/null +++ b/.pre-commit-config.yaml @@ -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/ diff --git a/.readthedocs.yml b/.readthedocs.yaml similarity index 100% rename from .readthedocs.yml rename to .readthedocs.yaml diff --git a/Makefile b/Makefile index 60ed00e4..28d7fa46 100644 --- a/Makefile +++ b/Makefile @@ -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 tests - black tests setup.py - $(MAKE) lint + pre-commit run --all-files --show-diff-on-failure test: pytest tests diff --git a/README.md b/README.md index 5acd94db..fa56f2e3 100644 --- a/README.md +++ b/README.md @@ -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 virtualenv -p python3 venv . venv/bin/activate python -m pip install -e ".[dev]" +pre-commit install ``` ### Release setup diff --git a/docs/index.rst b/docs/index.rst index 472a482a..89815efa 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -11,7 +11,7 @@ Contents release_notes - + Indices and tables ------------------ diff --git a/newsfragments/README.md b/newsfragments/README.md index 7c8981fa..177d6492 100644 --- a/newsfragments/README.md +++ b/newsfragments/README.md @@ -8,15 +8,15 @@ relevant to people working on the code itself.) Each file should be named like `..rst`, where `` is an issue number, and `` 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` diff --git a/newsfragments/validate_files.py b/newsfragments/validate_files.py index bc68bfe5..02b0e3ef 100755 --- a/newsfragments/validate_files.py +++ b/newsfragments/validate_files.py @@ -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: diff --git a/setup.py b/setup.py index 859008ec..5efcc3cd 100644 --- a/setup.py +++ b/setup.py @@ -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"] ) diff --git a/tox.ini b/tox.ini index cdb3560c..cf23aa2e 100644 --- a/tox.ini +++ b/tox.ini @@ -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 --config-file {toxinidir}/mypy.ini - flake8 {toxinidir}/ {toxinidir}/tests - isort --check-only --diff {toxinidir}/ {toxinidir}/tests - pydocstyle --explain {toxinidir}/ {toxinidir}/tests - black --check {toxinidir}/ {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]