Skip to content

Commit

Permalink
feat: support web3.py dependencies (#97)
Browse files Browse the repository at this point in the history
Co-authored-by: antazoey <jules@apeworx.io>
  • Loading branch information
NotPeopling2day and antazoey authored Dec 6, 2024
1 parent 278b1be commit db57e9b
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 10 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Docs

on:
push:
branches: [main]
release:
types: [released]
pull_request:
types: [opened, synchronize]

jobs:
docs:
runs-on: ubuntu-latest

permissions:
contents: write

steps:
- uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.10"

- name: Ape Docs
uses: apeworx/sphinx-ape@main
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
28 changes: 28 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,34 @@ pre-commit install

Committing will now automatically run the local hooks and ensure that your commit passes all lint checks.

## Running the docs locally

First, make sure you have the docs-related tooling installed:

```bash
pip install -e .'[doc]'
```

Then, run the following from the root project directory:

```bash
sphinx-ape build .
```

For the best viewing experience, use a local server:

```bash
sphinx-ape serve .
```

Then, open your browser to `127.0.0.1:1337` and click the `ape` directory link.

You can also use the `--open` flag to automatically open the docs:

```bash
sphinx-ape serve . --open
```

## Pull Requests

Pull requests are welcomed! Please adhere to the following:
Expand Down
8 changes: 6 additions & 2 deletions ape_infura/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
from web3.exceptions import ContractLogicError as Web3ContractLogicError
from web3.exceptions import ExtraDataLengthError
from web3.gas_strategies.rpc import rpc_gas_price_strategy
from web3.middleware import geth_poa_middleware

try:
from web3.middleware import ExtraDataToPOAMiddleware # type: ignore
except ImportError:
from web3.middleware import geth_poa_middleware as ExtraDataToPOAMiddleware # type: ignore
from web3.middleware.validation import MAX_EXTRADATA_LENGTH

_API_KEY_ENVIRONMENT_VARIABLE_NAMES = ("WEB3_INFURA_PROJECT_ID", "WEB3_INFURA_API_KEY")
Expand Down Expand Up @@ -135,7 +139,7 @@ def connect(self):
self._web3 = _create_web3(http_provider)

if self._needs_poa_middleware:
self._web3.middleware_onion.inject(geth_poa_middleware, layer=0)
self._web3.middleware_onion.inject(ExtraDataToPOAMiddleware, layer=0)

self._web3.eth.set_gas_price_strategy(rpc_gas_price_strategy)

Expand Down
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
extensions = ["sphinx_ape"]
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.. dynamic-toc-tree::
2 changes: 2 additions & 0 deletions docs/userguides/quickstart.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
```{include} ../../README.md
```
9 changes: 3 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,7 @@
"mdformat-pyproject>=0.0.2", # Allows configuring in pyproject.toml
],
"doc": [
"myst-parser>=1.0.0,<2", # Parse markdown docs
"sphinx-click>=4.4.0,<5", # For documenting CLI
"Sphinx>=6.1.3,<7", # Documentation generator
"sphinx_rtd_theme>=1.2.0,<2", # Readthedocs.org theme
"sphinxcontrib-napoleon>=0.7", # Allow Google-style documentation
"sphinx-plausible>=0.1.2,<0.2",
"sphinx-ape",
],
"release": [ # `release` GitHub Action job uses this
"setuptools>=75.6.0", # Installation tool
Expand Down Expand Up @@ -81,6 +76,8 @@
include_package_data=True,
install_requires=[
"eth-ape>=0.8.1,<0.9",
"web3>=6.20.1,<8",
"requests>=2.28.1,<3",
],
python_requires=">=3.9,<4",
extras_require=extras_require,
Expand Down
8 changes: 6 additions & 2 deletions tests/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
import websocket # type: ignore
from ape import networks
from web3.exceptions import ExtraDataLengthError
from web3.middleware import geth_poa_middleware

try:
from web3.middleware import ExtraDataToPOAMiddleware # type: ignore
except ImportError:
from web3.middleware import geth_poa_middleware as ExtraDataToPOAMiddleware # type: ignore

from ape_infura.provider import _WEBSOCKET_CAPABLE_NETWORKS, Infura, _get_session

Expand Down Expand Up @@ -116,7 +120,7 @@ def test_dynamic_poa_check(mocker):
patch = mocker.patch("ape_infura.provider._create_web3")
patch.return_value = mock_web3
infura.connect()
mock_web3.middleware_onion.inject.assert_called_once_with(geth_poa_middleware, layer=0)
mock_web3.middleware_onion.inject.assert_called_once_with(ExtraDataToPOAMiddleware, layer=0)


def test_api_secret():
Expand Down

0 comments on commit db57e9b

Please sign in to comment.