Skip to content

Commit

Permalink
remove old-style linting tools, add pre-commit to dev setup
Browse files Browse the repository at this point in the history
  • Loading branch information
pacrob committed Oct 3, 2023
1 parent 3d20065 commit b3313b0
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 82 deletions.
9 changes: 3 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ common: &common
command: |
python -m pip install --upgrade pip
python -m pip install tox
- run:
name: install pre-commit
command: pip install --progress-bar=off pre-commit
- run:
name: run tox
command: python -m tox run -r
Expand Down Expand Up @@ -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:
Expand Down
11 changes: 6 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
exclude: '.project-template/'
repos: # keep versions in sync with setup.py
exclude: '.project-template|docs/conf.py'
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
hooks:
Expand All @@ -8,15 +8,16 @@ repos: # keep versions in sync with setup.py
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 22.10.0
rev: 23.9.1
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
- id: flake8
additional_dependencies:
- flake8-bugbear
- flake8-bugbear==23.9.16
exclude: setup.py
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
Expand All @@ -30,7 +31,7 @@ repos: # keep versions in sync with setup.py
hooks:
- id: mdformat
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.971
rev: v1.5.1
hooks:
- id: mypy
exclude: tests/
2 changes: 1 addition & 1 deletion .project-template/fill_template_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def main():
rtd_name = rtd_input or pypi_name

project_input = input(
f"What is your project name (ex: at the top of the README)? (default: {repo_name}) " # noqa: E501
f"What is your project name (ex: at the top of the README)? (default: {repo_name}) "
)
project_name = project_input or repo_name

Expand Down
10 changes: 2 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand All @@ -27,12 +26,7 @@ clean-pyc:
find . -name '__pycache__' -exec rm -rf {} +

lint:
tox run -e lint

lint-roll:
isort hexbytes tests
black hexbytes tests setup.py
$(MAKE) lint
pre-commit run --all-files --show-diff-on-failure

test:
pytest tests
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Build Status](https://circleci.com/gh/ethereum/hexbytes.svg?style=shield)](https://circleci.com/gh/ethereum/hexbytes)
[![PyPI version](https://badge.fury.io/py/hexbytes.svg)](https://badge.fury.io/py/hexbytes)
[![Python versions](https://img.shields.io/pypi/pyversions/hexbytes.svg)](https://pypi.python.org/pypi/hexbytes)
[![Docs build](https://readthedocs.org/projects/hexbytes/badge/?version=latest)](http://hexbytes.readthedocs.io/en/latest/?badge=latest)
[![Docs build](https://readthedocs.org/projects/hexbytes/badge/?version=latest)](https://hexbytes.readthedocs.io/en/latest/?badge=latest)

Python `bytes` subclass that decodes hex, with a readable console output

Expand Down Expand Up @@ -46,9 +46,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:
Expand All @@ -59,6 +63,7 @@ cd hexbytes
virtualenv -p python3 venv
. venv/bin/activate
python -m pip install -e ".[dev]"
pre-commit install
```

### Release setup
Expand Down
14 changes: 7 additions & 7 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,12 @@
# -- Options for LaTeX output ---------------------------------------------

# latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
# 'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
# 'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
# 'preamble': '',
# # The paper size ('letterpaper' or 'a4paper').
# 'papersize': 'letterpaper',
# # The font size ('10pt', '11pt' or '12pt').
# 'pointsize': '10pt',
# # Additional stuff for the LaTeX preamble.
# 'preamble': '',
# }

# Grouping the document tree into LaTeX files. List of tuples
Expand Down Expand Up @@ -293,7 +293,7 @@

# -- Doctest configuration ----------------------------------------

import doctest # noqa: E402
import doctest

doctest_default_flags = (
0
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Contents

hexbytes
release_notes


Indices and tables
------------------
Expand Down
1 change: 1 addition & 0 deletions newsfragments/35.internal.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Change to using ``pre-commit`` to manage linting tools
18 changes: 9 additions & 9 deletions newsfragments/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
1 change: 0 additions & 1 deletion newsfragments/validate_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
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:
Expand Down
47 changes: 17 additions & 30 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,31 @@
)

extras_require = {
"test": [
"eth_utils>=2.0.0",
"hypothesis>=3.44.24,<=6.31.6",
"pytest>=7.0.0",
"pytest-xdist>=2.4.0",
],
"lint": [ # keep versions in sync with .pre-commit-config.yaml
"flake8==3.9.2", # flake8 claims semver but adds new warnings at minor releases, leave it pinned.
"flake8-bugbear==23.3.12", # flake8-bugbear does not follow semver, leave it pinned.
"isort==5.12.0",
"mypy==1.4.1", # mypy does not follow semver, leave it pinned.
"pydocstyle==6.3.0",
"black==22.10.0",
"mdformat==0.7.17",
],
"docs": [
"sphinx>=5.3.0",
"sphinx_rtd_theme>=1.0.0",
"towncrier>=21,<22",
],
"dev": [
"bumpversion>=0.5.3",
"build>=0.9.0",
"bumpversion>=0.5.3",
"ipython",
"pre-commit>=3.4.0",
"pytest-watch>=4.1.0",
"tox>=4.0.0",
"build>=0.9.0",
"wheel",
"twine",
"ipython",
"wheel",
],
"docs": [
"sphinx>=5.3.0",
"sphinx_rtd_theme>=1.0.0",
"towncrier>=21,<22",
],
"test": [
"eth_utils>=2.0.0",
"hypothesis>=3.44.24,<=6.31.6",
"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"]
)


Expand All @@ -53,9 +40,9 @@

setup(
name="hexbytes",
# *IMPORTANT*: Don't manually change the version here. Use `make bump`, as described in readme # noqa: E501
# *IMPORTANT*: Don't manually change the version here. Use `make bump`, as described in readme
version="0.3.1",
description="""hexbytes: Python `bytes` subclass that decodes hex, with a readable console output""", # noqa: E501
description="""hexbytes: Python `bytes` subclass that decodes hex, with a readable console output""",
long_description=long_description,
long_description_content_type="text/markdown",
author="The Ethereum Foundation",
Expand Down
17 changes: 5 additions & 12 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 hexbytes --config-file {toxinidir}/mypy.ini
flake8 {toxinidir}/hexbytes {toxinidir}/tests
isort --check-only --diff {toxinidir}/hexbytes {toxinidir}/tests
pydocstyle --explain {toxinidir}/hexbytes {toxinidir}/tests
black --check {toxinidir}/hexbytes {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]
Expand Down

0 comments on commit b3313b0

Please sign in to comment.