Skip to content

Commit

Permalink
feat!: Handle 0.7 breaking changes and updates [APE-1608] (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
NotPeopling2day authored Dec 19, 2023
1 parent 9e9f30e commit 7d08472
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 26 deletions.
19 changes: 12 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
rev: v4.5.0
hooks:
- id: check-yaml

Expand All @@ -10,22 +10,27 @@ repos:
- id: isort

- repo: https://github.com/psf/black
rev: 22.3.0
rev: 23.12.0
hooks:
- id: black
name: black

- repo: https://gitlab.com/pycqa/flake8
rev: 4.0.1
- repo: https://github.com/pycqa/flake8
rev: 6.1.0
hooks:
- id: flake8

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.971
rev: v1.7.1
hooks:
- id: mypy
additional_dependencies: [types-PyYAML, types-requests]
additional_dependencies: [types-setuptools, pydantic]

- repo: https://github.com/executablebooks/mdformat
rev: 0.7.17
hooks:
- id: mdformat
additional_dependencies: [mdformat-gfm, mdformat-frontmatter]

default_language_version:
python: python3.9
python: python3
8 changes: 5 additions & 3 deletions ape_chainstack/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from ape import plugins

from .providers import ETH_NETWORKS, Chainstack
from .providers import Chainstack
from .utils import NETWORKS


@plugins.register(plugins.ProviderPlugin)
def providers():
for network_name in ETH_NETWORKS:
yield "ethereum", network_name, Chainstack
for ecosystem_name in NETWORKS:
for network_name in NETWORKS[ecosystem_name]:
yield ecosystem_name, network_name, Chainstack
13 changes: 4 additions & 9 deletions ape_chainstack/providers.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
import os

from ape.api import Web3Provider
from ape.exceptions import ContractLogicError, ProviderError, VirtualMachineError
from ape_ethereum.provider import Web3Provider
from web3 import HTTPProvider, Web3
from web3.exceptions import ContractLogicError as Web3ContractLogicError
from web3.middleware import geth_poa_middleware

ETH_NETWORKS = [
"mainnet",
"ropsten",
"rinkeby",
"goerli",
]
from .utils import NETWORKS

_ENVIRONMENT_VARIABLE_NAMES = [f"CHAINSTACK_{network.upper()}_URL" for network in ETH_NETWORKS]
_ENVIRONMENT_VARIABLE_NAMES = [f"CHAINSTACK_{network.upper()}_URL" for network in NETWORKS]


class ChainstackProviderError(ProviderError):
Expand Down Expand Up @@ -61,7 +56,7 @@ def disconnect(self):
self._web3 = None
return super().disconnect()

def get_virtual_machine_error(self, exception: Exception) -> VirtualMachineError:
def get_virtual_machine_error(self, exception: Exception, **kwargs) -> VirtualMachineError:
if not hasattr(exception, "args") or not len(exception.args):
return VirtualMachineError(base_err=exception)

Expand Down
17 changes: 17 additions & 0 deletions ape_chainstack/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from typing import Dict, List

API_KEY_ENV_KEY_MAP = {
"base": "BASE_CHAINSTACK_API_KEY",
"ethereum": "ETH_CHAINSTACK_API_KEY",
"gnosis": "GNOSIS_CHAINSTACK_API_KEY",
"optimism": "OPTIMISM_CHAINSTACK_API_KEY",
"polygon": "POLYGON_CHAINSTACK_API_KEY",
}

NETWORKS: Dict[str, List[str]] = {
"base": ["mainnet", "goerli", "sepolia"],
"ethereum": ["mainnet", "ropsten", "rinkeby", "goerli", "sepolia"],
"gnosis": ["mainnet", "chiado"],
"optimism": ["mainnet", "goerli", "sepolia"],
"polygon": ["mainnet"],
}
19 changes: 12 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@
"hypothesis>=6.2.0,<7.0", # Strategy-based fuzzer
],
"lint": [
"black>=22.6.0,<23.0", # auto-formatter and linter
"mypy>=0.971,<1.0", # Static type analyzer
"flake8>=4.0.1,<5.0", # Style linter
"flake8-breakpoint>=1.1.0,<2.0.0", # detect breakpoints left in code
"flake8-print>=4.0.0,<5.0.0", # detect print statements left in code
"isort>=5.10.1,<6.0", # Import sorting linter
"black>=23.12.0,<24", # Auto-formatter and linter
"mypy>=1.7.1,<2", # Static type analyzer
"types-setuptools", # Needed for mypy type shed
"flake8>=6.1.0,<7", # Style linter
"flake8-breakpoint>=1.1.0,<2", # Detect breakpoints left in code
"flake8-print>=5.0.0,<6", # Detect print statements left in code
"isort>=5.10.1,<6", # Import sorting linter
"mdformat>=0.7.17", # Auto-formatter for markdown
"mdformat-gfm>=0.3.5", # Needed for formatting GitHub-flavored markdown
"mdformat-frontmatter>=0.4.1", # Needed for frontmatters-style headers in issue templates
"mdformat-pyproject>=0.0.1", # Allows configuring in pyproject.toml
],
"release": [ # `release` GitHub Action job uses this
"setuptools", # Installation tool
Expand Down Expand Up @@ -55,7 +60,7 @@
url="https://github.com/ApeWorX/ape-chainstack",
include_package_data=True,
install_requires=[
"eth-ape>=0.5.0,<0.6",
"eth-ape>=0.7.0,<0.8",
],
python_requires=">=3.8,<4",
extras_require=extras_require,
Expand Down

0 comments on commit 7d08472

Please sign in to comment.