Skip to content

Commit

Permalink
Add black to web3/tools
Browse files Browse the repository at this point in the history
  • Loading branch information
kclowes committed Jun 22, 2022
1 parent b2cc975 commit 59c9786
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 23 deletions.
1 change: 1 addition & 0 deletions newsfragments/2523.misc.rst
@@ -0,0 +1 @@
Add black linting to the ``web3/tools`` directory.
2 changes: 1 addition & 1 deletion tox.ini
Expand Up @@ -64,7 +64,7 @@ basepython=python
extras=linter
commands=
flake8 {toxinidir}/web3 {toxinidir}/ens {toxinidir}/ethpm {toxinidir}/tests --exclude {toxinidir}/ethpm/ethpm-spec
black {toxinidir}/ethpm {toxinidir}/web3/auto {toxinidir}/web3/utils {toxinidir}/web3/_utils {toxinidir}/web3/beacon {toxinidir}/web3/gas_strategies {toxinidir}/web3/scripts {toxinidir}/web3/providers {toxinidir}/web3/middleware {toxinidir}/web3/__init__.py {toxinidir}/web3/constants.py {toxinidir}/web3/datastructures.py {toxinidir}/web3/exceptions.py {toxinidir}/web3/geth.py {toxinidir}/web3/iban.py {toxinidir}/web3/logs.py {toxinidir}/web3/main.py {toxinidir}/web3/manager.py {toxinidir}/web3/method.py {toxinidir}/web3/module.py {toxinidir}/web3/net.py {toxinidir}/web3/parity.py {toxinidir}/web3/pm.py {toxinidir}/web3/testing.py {toxinidir}/web3/types.py {toxinidir}/web3/version.py --exclude {toxinidir}/ethpm/ethpm-spec --check
black {toxinidir}/ethpm {toxinidir}/web3/auto {toxinidir}/web3/utils {toxinidir}/web3/_utils {toxinidir}/web3/beacon {toxinidir}/web3/gas_strategies {toxinidir}/web3/scripts {toxinidir}/web3/providers {toxinidir}/web3/middleware {toxinidir}/web3/tools {toxinidir}/web3/__init__.py {toxinidir}/web3/constants.py {toxinidir}/web3/datastructures.py {toxinidir}/web3/exceptions.py {toxinidir}/web3/geth.py {toxinidir}/web3/iban.py {toxinidir}/web3/logs.py {toxinidir}/web3/main.py {toxinidir}/web3/manager.py {toxinidir}/web3/method.py {toxinidir}/web3/module.py {toxinidir}/web3/net.py {toxinidir}/web3/parity.py {toxinidir}/web3/pm.py {toxinidir}/web3/testing.py {toxinidir}/web3/types.py {toxinidir}/web3/version.py --exclude {toxinidir}/ethpm/ethpm-spec --check
isort --recursive --check-only --diff {toxinidir}/web3/ {toxinidir}/ens/ {toxinidir}/ethpm/ {toxinidir}/tests/
mypy -p web3 -p ethpm -p ens --config-file {toxinidir}/mypy.ini

Expand Down
47 changes: 31 additions & 16 deletions web3/tools/benchmark/main.py
Expand Up @@ -48,11 +48,14 @@
Wei,
)

KEYFILE_PW = 'web3py-test'
KEYFILE_PW = "web3py-test"

parser = argparse.ArgumentParser()
parser.add_argument(
"--num-calls", type=int, default=10, help="The number of RPC calls to make",
"--num-calls",
type=int,
default=10,
help="The number of RPC calls to make",
)

# TODO - layers to test:
Expand All @@ -65,7 +68,7 @@ def build_web3_http(endpoint_uri: str) -> Web3:
wait_for_http(endpoint_uri)
_w3 = Web3(
HTTPProvider(endpoint_uri),
middlewares=[gas_price_strategy_middleware, buffered_gas_estimate_middleware]
middlewares=[gas_price_strategy_middleware, buffered_gas_estimate_middleware],
)
return _w3

Expand All @@ -74,7 +77,10 @@ async def build_async_w3_http(endpoint_uri: str) -> Web3:
await wait_for_aiohttp(endpoint_uri)
_w3 = Web3(
AsyncHTTPProvider(endpoint_uri), # type: ignore
middlewares=[async_gas_price_strategy_middleware, async_buffered_gas_estimate_middleware],
middlewares=[
async_gas_price_strategy_middleware,
async_buffered_gas_estimate_middleware,
],
modules={"eth": AsyncEth},
)
return _w3
Expand Down Expand Up @@ -121,7 +127,9 @@ def main(logger: logging.Logger, num_calls: int) -> None:
for process in built_fixture:
w3_http = build_web3_http(fixture.endpoint_uri)
loop = asyncio.get_event_loop()
async_w3_http = loop.run_until_complete(build_async_w3_http(fixture.endpoint_uri))
async_w3_http = loop.run_until_complete(
build_async_w3_http(fixture.endpoint_uri)
)
# TODO: swap out w3_http for the async_w3_http once GethPersonal module is async
async_unlocked_acct = loop.run_until_complete(
async_unlocked_account(w3_http, async_w3_http.eth)
Expand All @@ -137,16 +145,20 @@ def main(logger: logging.Logger, num_calls: int) -> None:
{
"name": "eth_sendTransaction",
"params": {},
"exec": lambda: w3_http.eth.send_transaction({
'to': '0xd3CdA913deB6f67967B99D67aCDFa1712C293601',
'from': unlocked_account(w3_http),
'value': Wei(12345),
}),
"async_exec": lambda: async_w3_http.eth.send_transaction({
'to': '0xd3CdA913deB6f67967B99D67aCDFa1712C293601',
'from': async_unlocked_acct,
'value': Wei(12345)
}),
"exec": lambda: w3_http.eth.send_transaction(
{
"to": "0xd3CdA913deB6f67967B99D67aCDFa1712C293601",
"from": unlocked_account(w3_http),
"value": Wei(12345),
}
),
"async_exec": lambda: async_w3_http.eth.send_transaction(
{
"to": "0xd3CdA913deB6f67967B99D67aCDFa1712C293601",
"from": async_unlocked_acct,
"value": Wei(12345),
}
),
},
{
"name": "eth_blockNumber",
Expand All @@ -165,7 +177,10 @@ def main(logger: logging.Logger, num_calls: int) -> None:
def benchmark(method: Dict[str, Any]) -> None:
outcomes: Dict[str, Union[str, float]] = defaultdict(lambda: "N/A")
outcomes["name"] = method["name"]
outcomes["HTTPProvider"] = sync_benchmark(method["exec"], num_calls,)
outcomes["HTTPProvider"] = sync_benchmark(
method["exec"],
num_calls,
)
outcomes["AsyncHTTPProvider"] = loop.run_until_complete(
async_benchmark(method["async_exec"], num_calls)
)
Expand Down
4 changes: 3 additions & 1 deletion web3/tools/benchmark/node.py
Expand Up @@ -101,7 +101,9 @@ def _geth_process(
str(genesis_file),
)
check_output(
init_datadir_command, stdin=PIPE, stderr=PIPE,
init_datadir_command,
stdin=PIPE,
stderr=PIPE,
)
proc = Popen(
self._geth_command_arguments(datadir),
Expand Down
5 changes: 4 additions & 1 deletion web3/tools/benchmark/reporting.py
Expand Up @@ -20,7 +20,10 @@ def print_header(logger: Logger, num_calls: int) -> None:
logger.info("-" * 112)


def print_entry(logger: Logger, method_benchmarks: Dict[str, Any],) -> None:
def print_entry(
logger: Logger,
method_benchmarks: Dict[str, Any],
) -> None:
logger.info(
"|{:^26}|{:^20.10}|{:^20.10}|{:^20.10}|{:^20.10}|".format(
method_benchmarks["name"],
Expand Down
4 changes: 1 addition & 3 deletions web3/tools/pytest_ethereum/deployer.py
Expand Up @@ -30,9 +30,7 @@ def __init__(self, package: Package) -> None:
self.package = package
self.strategies = {} # type: Dict[str, Callable[[Package], Package]]

def deploy(
self, contract_type: ContractName, *args: Any, **kwargs: Any
) -> Package:
def deploy(self, contract_type: ContractName, *args: Any, **kwargs: Any) -> Package:
factory = self.package.get_contract_factory(contract_type)
if contract_type in self.strategies:
strategy = self.strategies[contract_type]
Expand Down
5 changes: 4 additions & 1 deletion web3/tools/pytest_ethereum/linker.py
Expand Up @@ -59,7 +59,10 @@ def deploy(

@curry
def _deploy(
contract_name: ContractName, args: Any, transaction: Dict[str, Any], package: Package
contract_name: ContractName,
args: Any,
transaction: Dict[str, Any],
package: Package,
) -> Package:
# Deploy new instance
factory = package.get_contract_factory(contract_name)
Expand Down

0 comments on commit 59c9786

Please sign in to comment.