mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-12 16:10:57 +00:00
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:
@ -20,4 +20,3 @@ values =
|
|||||||
[bumpversion:file:setup.py]
|
[bumpversion:file:setup.py]
|
||||||
search = version="{current_version}",
|
search = version="{current_version}",
|
||||||
replace = version="{new_version}",
|
replace = version="{new_version}",
|
||||||
|
|
||||||
|
|||||||
@ -25,6 +25,9 @@ common: &common
|
|||||||
command: |
|
command: |
|
||||||
python -m pip install --upgrade pip
|
python -m pip install --upgrade pip
|
||||||
python -m pip install tox
|
python -m pip install tox
|
||||||
|
- run:
|
||||||
|
name: install pre-commit
|
||||||
|
command: python -m pip install --progress-bar=off pre-commit
|
||||||
- run:
|
- run:
|
||||||
name: run tox
|
name: run tox
|
||||||
command: python -m tox run -r
|
command: python -m tox run -r
|
||||||
@ -102,12 +105,6 @@ jobs:
|
|||||||
environment:
|
environment:
|
||||||
TOXENV: py311-core
|
TOXENV: py311-core
|
||||||
|
|
||||||
py37-lint:
|
|
||||||
<<: *common
|
|
||||||
docker:
|
|
||||||
- image: cimg/python:3.7
|
|
||||||
environment:
|
|
||||||
TOXENV: py37-lint
|
|
||||||
py38-lint:
|
py38-lint:
|
||||||
<<: *common
|
<<: *common
|
||||||
docker:
|
docker:
|
||||||
|
|||||||
9
.github/pull_request_template.md
vendored
9
.github/pull_request_template.md
vendored
@ -6,12 +6,13 @@ Closes #
|
|||||||
### How was it fixed?
|
### How was it fixed?
|
||||||
|
|
||||||
### Todo:
|
### 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
|
#### Cute Animal Picture
|
||||||
|
|
||||||
![Put a link to a cute animal picture inside the parenthesis-->]()
|

|
||||||
|
|||||||
37
.pre-commit-config.yaml
Normal file
37
.pre-commit-config.yaml
Normal 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/
|
||||||
10
Makefile
10
Makefile
@ -5,8 +5,7 @@ CURRENT_SIGN_SETTING := $(shell git config commit.gpgSign)
|
|||||||
help:
|
help:
|
||||||
@echo "clean-build - remove build artifacts"
|
@echo "clean-build - remove build artifacts"
|
||||||
@echo "clean-pyc - remove Python file artifacts"
|
@echo "clean-pyc - remove Python file artifacts"
|
||||||
@echo "lint - check style with mypy, flake8, isort, pydocstyle, and black"
|
@echo "lint - fix linting issues with pre-commit
|
||||||
@echo "lint-roll - automatically fix problems with flake8 and black"
|
|
||||||
@echo "test - run tests quickly with the default Python"
|
@echo "test - run tests quickly with the default Python"
|
||||||
@echo "docs - generate docs and open in browser (linux-docs for version on linux)"
|
@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/"
|
@echo "notes - consume towncrier newsfragments/ and update release notes in docs/"
|
||||||
@ -27,12 +26,7 @@ clean-pyc:
|
|||||||
find . -name '__pycache__' -exec rm -rf {} +
|
find . -name '__pycache__' -exec rm -rf {} +
|
||||||
|
|
||||||
lint:
|
lint:
|
||||||
tox run -e lint
|
pre-commit run --all-files --show-diff-on-failure
|
||||||
|
|
||||||
lint-roll:
|
|
||||||
isort <MODULE_NAME> tests
|
|
||||||
black <MODULE_NAME> tests setup.py
|
|
||||||
$(MAKE) lint
|
|
||||||
|
|
||||||
test:
|
test:
|
||||||
pytest tests
|
pytest tests
|
||||||
|
|||||||
@ -24,9 +24,13 @@ for information on how we do:
|
|||||||
|
|
||||||
- Testing
|
- Testing
|
||||||
- Pull Requests
|
- Pull Requests
|
||||||
- Code Style
|
|
||||||
- Documentation
|
- 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
|
### Development Environment Setup
|
||||||
|
|
||||||
You can set up your dev environment with:
|
You can set up your dev environment with:
|
||||||
@ -37,6 +41,7 @@ cd <REPO_NAME>
|
|||||||
virtualenv -p python3 venv
|
virtualenv -p python3 venv
|
||||||
. venv/bin/activate
|
. venv/bin/activate
|
||||||
python -m pip install -e ".[dev]"
|
python -m pip install -e ".[dev]"
|
||||||
|
pre-commit install
|
||||||
```
|
```
|
||||||
|
|
||||||
### Release setup
|
### Release setup
|
||||||
|
|||||||
@ -11,7 +11,7 @@ Contents
|
|||||||
|
|
||||||
<MODULE_NAME>
|
<MODULE_NAME>
|
||||||
release_notes
|
release_notes
|
||||||
|
|
||||||
|
|
||||||
Indices and tables
|
Indices and tables
|
||||||
------------------
|
------------------
|
||||||
|
|||||||
@ -8,15 +8,15 @@ relevant to people working on the code itself.)
|
|||||||
Each file should be named like `<ISSUE>.<TYPE>.rst`, where
|
Each file should be named like `<ISSUE>.<TYPE>.rst`, where
|
||||||
`<ISSUE>` is an issue number, and `<TYPE>` is one of:
|
`<ISSUE>` is an issue number, and `<TYPE>` is one of:
|
||||||
|
|
||||||
* `breaking`
|
- `breaking`
|
||||||
* `bugfix`
|
- `bugfix`
|
||||||
* `deprecation`
|
- `deprecation`
|
||||||
* `docs`
|
- `docs`
|
||||||
* `feature`
|
- `feature`
|
||||||
* `internal`
|
- `internal`
|
||||||
* `misc`
|
- `misc`
|
||||||
* `performance`
|
- `performance`
|
||||||
* `removal`
|
- `removal`
|
||||||
|
|
||||||
So for example: `123.feature.rst`, `456.bugfix.rst`
|
So for example: `123.feature.rst`, `456.bugfix.rst`
|
||||||
|
|
||||||
|
|||||||
@ -31,7 +31,6 @@ if num_args == 1:
|
|||||||
assert sys.argv[1] in ("is-empty",)
|
assert sys.argv[1] in ("is-empty",)
|
||||||
|
|
||||||
for fragment_file in THIS_DIR.iterdir():
|
for fragment_file in THIS_DIR.iterdir():
|
||||||
|
|
||||||
if fragment_file.name in ALLOWED_FILES:
|
if fragment_file.name in ALLOWED_FILES:
|
||||||
continue
|
continue
|
||||||
elif num_args == 0:
|
elif num_args == 0:
|
||||||
|
|||||||
38
setup.py
38
setup.py
@ -1,44 +1,34 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from setuptools import (
|
from setuptools import (
|
||||||
setup,
|
|
||||||
find_packages,
|
find_packages,
|
||||||
|
setup,
|
||||||
)
|
)
|
||||||
|
|
||||||
extras_require = {
|
extras_require = {
|
||||||
"test": [
|
"dev": [
|
||||||
"pytest>=7.0.0",
|
"build>=0.9.0",
|
||||||
"pytest-xdist>=2.4.0",
|
"bumpversion>=0.5.3",
|
||||||
],
|
"ipython",
|
||||||
"lint": [
|
"pre-commit>=3.4.0",
|
||||||
"flake8==6.0.0", # flake8 claims semver but adds new warnings at minor releases, leave it pinned.
|
"pytest-watch>=4.1.0",
|
||||||
"flake8-bugbear==23.3.23", # flake8-bugbear does not follow semver, leave it pinned.
|
"tox>=4.0.0",
|
||||||
"isort>=5.10.1",
|
"twine",
|
||||||
"mypy==0.971", # mypy does not follow semver, leave it pinned.
|
"wheel",
|
||||||
"pydocstyle>=6.0.0",
|
|
||||||
"black>=23",
|
|
||||||
],
|
],
|
||||||
"docs": [
|
"docs": [
|
||||||
"sphinx>=6.0.0",
|
"sphinx>=6.0.0",
|
||||||
"sphinx_rtd_theme>=1.0.0",
|
"sphinx_rtd_theme>=1.0.0",
|
||||||
"towncrier>=21,<22",
|
"towncrier>=21,<22",
|
||||||
],
|
],
|
||||||
"dev": [
|
"test": [
|
||||||
"bumpversion>=0.5.3",
|
"pytest>=7.0.0",
|
||||||
"pytest-watch>=4.1.0",
|
"pytest-xdist>=2.4.0",
|
||||||
"tox>=4.0.0",
|
|
||||||
"build>=0.9.0",
|
|
||||||
"wheel",
|
|
||||||
"twine",
|
|
||||||
"ipython",
|
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
extras_require["dev"] = (
|
extras_require["dev"] = (
|
||||||
extras_require["dev"]
|
extras_require["dev"] + extras_require["docs"] + extras_require["test"]
|
||||||
+ extras_require["test"]
|
|
||||||
+ extras_require["lint"]
|
|
||||||
+ extras_require["docs"]
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
17
tox.ini
17
tox.ini
@ -1,7 +1,7 @@
|
|||||||
[tox]
|
[tox]
|
||||||
envlist=
|
envlist=
|
||||||
py{37,38,39,310,311}-core
|
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
|
py{37,38,39,310,311}-wheel
|
||||||
py311-wheel-windows
|
py311-wheel-windows
|
||||||
docs
|
docs
|
||||||
@ -36,26 +36,19 @@ basepython=
|
|||||||
extras=
|
extras=
|
||||||
test
|
test
|
||||||
docs
|
docs
|
||||||
allowlist_externals=make
|
allowlist_externals=make,pre-commit
|
||||||
|
|
||||||
[common-lint]
|
[common-lint]
|
||||||
basepython=python
|
basepython=python
|
||||||
extras=lint
|
deps=pre-commit
|
||||||
allowlist_externals=black
|
|
||||||
commands=
|
commands=
|
||||||
mypy -p <MODULE_NAME> --config-file {toxinidir}/mypy.ini
|
pre-commit run --all-files --show-diff-on-failure
|
||||||
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
|
|
||||||
|
|
||||||
[testenv:lint]
|
[testenv:lint]
|
||||||
basepython: python
|
basepython: python
|
||||||
extras: {[common-lint]extras}
|
|
||||||
commands: {[common-lint]commands}
|
commands: {[common-lint]commands}
|
||||||
|
|
||||||
[testenv:py{37,38,39,310,311}-lint]
|
[testenv:py{38,39,310,311}-lint]
|
||||||
extras: {[common-lint]extras}
|
|
||||||
commands: {[common-lint]commands}
|
commands: {[common-lint]commands}
|
||||||
|
|
||||||
[testenv:py{37,38,39,310,311}-wheel]
|
[testenv:py{37,38,39,310,311}-wheel]
|
||||||
|
|||||||
Reference in New Issue
Block a user