Skip to content

Commit

Permalink
feat: import members to brownie_patch package (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobTheBuidler authored Apr 10, 2024
1 parent 7d6ae0a commit b9eb0b0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
6 changes: 3 additions & 3 deletions dank_mids/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

from contextlib import suppress

from dank_mids.brownie_patch import DankContractCall, DankContractMethod, DankContractTx, DankOverloadedMethod
from dank_mids.controller import instances
from dank_mids.helpers import setup_dank_w3, setup_dank_w3_from_sync
Expand All @@ -7,7 +9,7 @@

__all__ = ["dank_middleware", "BlockSemaphore", "setup_dank_w3", "setup_dank_w3_from_sync"]

try:
with suppress(ImportError):
from dank_mids.brownie_patch import Contract, dank_eth, dank_web3, patch_contract
from web3.eth import AsyncEth as _AsyncEth
# aliased for cleanliness and convenience
Expand All @@ -16,8 +18,6 @@

__all__ += ["Contract", "dank_web3", "web3", "dank_eth", "eth", "patch_contract"]

except ImportError:
pass

def _configure_concurrent_future_work_queue_size():
import concurrent.futures.process as _cfp
Expand Down
12 changes: 9 additions & 3 deletions dank_mids/brownie_patch/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@

from contextlib import suppress

from dank_mids.helpers import setup_dank_w3_from_sync
from dank_mids.brownie_patch.types import DankContractCall, DankContractMethod, DankContractTx, DankOverloadedMethod

__all__ = ["DankContractCall", "DankContractMethod", "DankContractTx", "DankOverloadedMethod"]

# If using dank_mids wih brownie, and brownie is connected when this file executes, you will get a 'dank_w3' async web3 instance with Dank Middleware here.
try:
with suppress(ImportError)
from brownie import network, web3

if network.is_connected():
from dank_mids.brownie_patch.contract import Contract, patch_contract
from web3.eth import AsyncEth as _AsyncEth

dank_web3 = setup_dank_w3_from_sync(web3)
dank_eth: _AsyncEth = dank_web3.eth
except ImportError:
pass

__all__ += ["Contract", "patch_contract", "dank_web3", "dank_eth"]

0 comments on commit b9eb0b0

Please sign in to comment.