Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change linting to use pre-commit #3297

Merged
merged 15 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Closes #

- [ ] Clean up commit history
- [ ] Add or update documentation related to these changes
- [ ] Add entry to the [release notes](https://github.com/ethereum/<REPO_NAME>/blob/main/newsfragments/README.md)
- [ ] Add entry to the [release notes](https://github.com/ethereum/web3.py/blob/main/newsfragments/README.md)

#### Cute Animal Picture

Expand Down
16 changes: 0 additions & 16 deletions .isort.cfg

This file was deleted.

59 changes: 59 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
exclude: '.project-template|docs/conf.py|.bumpversion.cfg'
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-yaml
- id: check-toml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
hooks:
- id: pyupgrade
args: [--py38-plus]
- 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/autoflake
rev: v2.2.1
hooks:
- id: autoflake
- 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
additional_dependencies:
- tomli # required until >= python311
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.17
hooks:
- id: mdformat
additional_dependencies:
- mdformat-gfm
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.5.1
hooks:
- id: mypy
exclude: 'tests/|conftest.py'
additional_dependencies:
- pydantic
- types-setuptools
- types-requests
- repo: https://github.com/PrincetonUniversity/blocklint
rev: v0.2.4
hooks:
- id: blocklint
exclude: 'normalization_tests.json|docs/(Makefile|release_notes.rst|web3.eth.rst|ens_overview.rst|abi_types.rst|transactions.rst)'
2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ build:

sphinx:
configuration: docs/conf.py
fail_on_warning: true
fail_on_warning: true

python:
install:
Expand Down
1 change: 1 addition & 0 deletions 3297.internal.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use ``pre-commit`` for linting, run updated lint tools and fix errors
106 changes: 56 additions & 50 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
@@ -1,54 +1,60 @@
methods/*
These files define all methods callable under
web3.db.*
web3.eth.*
web3.net.*
web3.personal.*

Methods and properties are first defined as a dictionary
and then are converted to real functions and attached to the
respective objects. This will make it easier to mirror the
next migrations of the web3.js library. Both types are defined
in method.py and property.py respectively.
methods/\*
These files define all methods callable under
web3.db.\*
web3.eth.\*
web3.net.\*
web3.personal.\*

```
Methods and properties are first defined as a dictionary
and then are converted to real functions and attached to the
respective objects. This will make it easier to mirror the
next migrations of the web3.js library. Both types are defined
in method.py and property.py respectively.
```

RequestManager
Is supplied with one Provider at initialisation which
can be replaced by calling setProvider(). It uses Jsonrpc
to convert the methods into raw payloads and to validate
responses attained with receive().

Has three other methods:

- send(data, timeout=None)
If timeout is None, send blocks until the result is
available, which it then returns.

If the timeout is 0, send returns immediately, only
returning the id of the request, which can be used
to poll with receive() later.

If the timeout is greater than 0, it blocks until
either the result is available or the timeout is
reached, at which point a ValueError is thrown.

send() makes use of the other two functions:

- forward(data)
Forwards the data to the provider and returns the
request id.

- receive(requestid, timeout=0)
Implements the timeout functionality described in send.
If timeout is 0, it returns None if the response was
not available.
Is supplied with one Provider at initialisation which
can be replaced by calling setProvider(). It uses Jsonrpc
to convert the methods into raw payloads and to validate
responses attained with receive().

```
Has three other methods:

- send(data, timeout=None)
If timeout is None, send blocks until the result is
available, which it then returns.

If the timeout is 0, send returns immediately, only
returning the id of the request, which can be used
to poll with receive() later.

If the timeout is greater than 0, it blocks until
either the result is available or the timeout is
reached, at which point a ValueError is thrown.

send() makes use of the other two functions:

- forward(data)
Forwards the data to the provider and returns the
request id.

- receive(requestid, timeout=0)
Implements the timeout functionality described in send.
If timeout is 0, it returns None if the response was
not available.
```

Provider
On initialisation, is started in a separate thread.
Continuously fetches incoming requests from a queue
and appends the responses to another queue. Providers
only receives and returns "raw" requests, JSON validation
and decoding happens in the Request Manager.

As of now there are two implementations:
- RPCProvider
- IPCProvider
On initialisation, is started in a separate thread.
Continuously fetches incoming requests from a queue
and appends the responses to another queue. Providers
only receives and returns "raw" requests, JSON validation
and decoding happens in the Request Manager.

```
As of now there are two implementations:
- RPCProvider
- IPCProvider
```
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Contributing

Thanks for the interest! See the [contributor documentation][contribute]
to get started, and reach out on [Discord][discord] if you get stuck.
to get started, and reach out on [Discord] if you get stuck.
pacrob marked this conversation as resolved.
Show resolved Hide resolved

[contribute]: https://web3py.readthedocs.io/en/latest/contributing.html
[discord]: https://discord.gg/GHryRvPB84
12 changes: 5 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
help:
@echo "clean-build - remove build artifacts"
@echo "clean-pyc - remove Python file artifacts"
@echo "lint - check style with flake8"
@echo "lint - fix linting issues with pre-commit"
@echo "test - run tests quickly with the default Python"
@echo "testall - run tests on every Python version with tox"
@echo "release - package and upload a release"
Expand All @@ -22,12 +22,10 @@ clean-pyc:
find . -name '*~' -exec rm -f {} +

lint:
tox -e lint

lint-roll:
isort web3 ens tests
black web3 ens tests setup.py
$(MAKE) lint
@pre-commit run --all-files --show-diff-on-failure || ( \
echo "\n\n\n * pre-commit should have fixed the errors above. Running again to make sure everything is good..." \
&& pre-commit run --all-files --show-diff-on-failure \
)

test:
pytest tests
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

A Python library for interacting with Ethereum.

- Python 3.8+ support
- Python 3.8+ support

---
______________________________________________________________________

## Quickstart

Expand All @@ -26,6 +26,6 @@ guidelines for [contributing](https://web3py.readthedocs.io/en/latest/contributi
then check out issues that are labeled
[Good First Issue](https://github.com/ethereum/web3.py/issues?q=is%3Aissue+is%3Aopen+label%3A%22Good+First+Issue%22).

---
______________________________________________________________________

#### Questions on implementation or usage? Join the conversation on [discord](https://discord.gg/GHryRvPB84).
15 changes: 7 additions & 8 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import asyncio
import pytest
import pytest_asyncio
import time
import warnings

import pytest_asyncio

from tests.utils import (
PollDelayCounter,
_async_wait_for_block_fixture_logic,
_async_wait_for_transaction_fixture_logic,
)
from web3._utils.threads import (
Timeout,
)
Expand All @@ -15,12 +20,6 @@
EthereumTesterProvider,
)

from tests.utils import (
PollDelayCounter,
_async_wait_for_block_fixture_logic,
_async_wait_for_transaction_fixture_logic,
)


@pytest.fixture()
def sleep_interval():
Expand Down
2 changes: 2 additions & 0 deletions docs/README-osx.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ brew install leveldb
```

> If you are on `>=OSX 10.15 Catalina` you may encounter the following error with the default `ZSH` shell. This can be fixed by wrapping the `[dev]` part in quotes.

```sh
pip install -e .[dev]
zsh: no matches found: .[dev]
```

Run install commands as follows:

```sh
pip install -e .'[dev]'
```
2 changes: 1 addition & 1 deletion docs/README-windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

1. Install all of the package dependencies (TODO)

2. Install `leveldb` (TODO)
1. Install `leveldb` (TODO)
2 changes: 1 addition & 1 deletion docs/_static/css/banner.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
width: auto;
height: auto;
padding: 0;
border-radius: 0;
border-radius: 0;
margin: 12px 0 0 0;
}
2 changes: 1 addition & 1 deletion docs/_static/css/dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -619,4 +619,4 @@ code.docutils.literal.notranslate {
}


/* Literal.Number.Integer.Long */
/* Literal.Number.Integer.Long */
2 changes: 1 addition & 1 deletion docs/_static/css/toggle.css
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ html.transition *:before,
html.transition *:after {
transition: ease-in-out 200ms !important;
transition-delay: 0 !important;
}
}
2 changes: 1 addition & 1 deletion docs/_static/js/toggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ document.addEventListener('DOMContentLoaded', function() {
toggleCssMode(this.checked);
})

});
});
2 changes: 1 addition & 1 deletion docs/_templates/versions.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@
</dd>
</dl>
</div>
</div>
</div>
8 changes: 3 additions & 5 deletions docs/constants.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ Strings

#The Address Zero, which is 20 bytes (40 nibbles) of zero.
web3.constants.ADDRESS_ZERO

#The hexadecimal version of Max uint256.
web3.constants.MAX_INT

#The Hash Zero, which is 32 bytes (64 nibbles) of zero.
web3.constants.HASH_ZERO
web3.constants.HASH_ZERO

Int
***
Expand All @@ -26,5 +26,3 @@ Int

#The amount of Wei in one Ether
web3.constants.WEI_PER_ETHER


4 changes: 2 additions & 2 deletions docs/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,9 @@ version explicitly, like ``make release bump="--new-version 4.0.0-alpha.1 devnum


.. _Python Discord server: https://discord.gg/GHryRvPB84
.. _style guide: https://github.com/ethereum/ethereum-dev-tactical-manual/blob/master/style-guide.md
.. _style guide: https://github.com/ethereum/snake-charmers-tactical-manual/blob/main/style-guide.md
.. _type hints: https://www.python.org/dev/peps/pep-0484/
.. _how to create documentation: https://github.com/ethereum/snake-charmers-tactical-manual/blob/master/documentation.md
.. _how to create documentation: https://github.com/ethereum/snake-charmers-tactical-manual/blob/main/documentation.md
.. _working on pull requests: https://help.github.com/articles/about-pull-requests/
.. _py-geth: https://github.com/ethereum/py-geth
.. _pytest documentation: https://docs.pytest.org/en/latest
Expand Down
2 changes: 0 additions & 2 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1360,5 +1360,3 @@ The script can be run with: ``python ./eventscanner.py <your JSON-RPC API URL>``
print(f"Scanned total {len(result)} Transfer events, in {duration} seconds, total {total_chunks_scanned} chunk scans performed")

run()


2 changes: 1 addition & 1 deletion docs/filters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ The :meth:`web3.eth.Eth.filter` method can be used to set up filters for:
Creating event filters requires that your Ethereum node has an API support enabled for filters.
Note that Infura support for filters does not offer access to `pending` filters.
To get event logs on other stateless nodes please see :class:`web3.contract.ContractEvents`.



Filter Class
Expand Down