From db57e9b7f23061c73f80453b13fffcbfad8b5ec4 Mon Sep 17 00:00:00 2001 From: NotPeopling2day <32708219+NotPeopling2day@users.noreply.github.com> Date: Fri, 6 Dec 2024 09:32:27 -0500 Subject: [PATCH] feat: support web3.py dependencies (#97) Co-authored-by: antazoey --- .github/workflows/docs.yaml | 29 +++++++++++++++++++++++++++++ CONTRIBUTING.md | 28 ++++++++++++++++++++++++++++ ape_infura/provider.py | 8 ++++++-- docs/conf.py | 1 + docs/index.rst | 1 + docs/userguides/quickstart.md | 2 ++ setup.py | 9 +++------ tests/test_provider.py | 8 ++++++-- 8 files changed, 76 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/docs.yaml create mode 100644 docs/conf.py create mode 100644 docs/index.rst create mode 100644 docs/userguides/quickstart.md diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml new file mode 100644 index 0000000..70f1547 --- /dev/null +++ b/.github/workflows/docs.yaml @@ -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 }} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7a3e18f..e01fb15 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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: diff --git a/ape_infura/provider.py b/ape_infura/provider.py index 9a49d19..e4ac721 100644 --- a/ape_infura/provider.py +++ b/ape_infura/provider.py @@ -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") @@ -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) diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 0000000..9181c1d --- /dev/null +++ b/docs/conf.py @@ -0,0 +1 @@ +extensions = ["sphinx_ape"] diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 0000000..b559066 --- /dev/null +++ b/docs/index.rst @@ -0,0 +1 @@ +.. dynamic-toc-tree:: diff --git a/docs/userguides/quickstart.md b/docs/userguides/quickstart.md new file mode 100644 index 0000000..c7719d8 --- /dev/null +++ b/docs/userguides/quickstart.md @@ -0,0 +1,2 @@ +```{include} ../../README.md +``` diff --git a/setup.py b/setup.py index e4a8f09..6be267c 100644 --- a/setup.py +++ b/setup.py @@ -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 @@ -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, diff --git a/tests/test_provider.py b/tests/test_provider.py index a578f8c..9269621 100644 --- a/tests/test_provider.py +++ b/tests/test_provider.py @@ -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 @@ -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():