diff --git a/newsfragments/2523.misc.rst b/newsfragments/2523.misc.rst new file mode 100644 index 0000000000..9480d372ff --- /dev/null +++ b/newsfragments/2523.misc.rst @@ -0,0 +1 @@ +Add black linting to the ``web3/tools`` directory. diff --git a/tox.ini b/tox.ini index c7e5d9c3c8..d7b6e524da 100644 --- a/tox.ini +++ b/tox.ini @@ -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 diff --git a/web3/tools/benchmark/main.py b/web3/tools/benchmark/main.py index efef6d8189..a173c76699 100644 --- a/web3/tools/benchmark/main.py +++ b/web3/tools/benchmark/main.py @@ -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: @@ -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 @@ -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 @@ -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) @@ -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", @@ -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) ) diff --git a/web3/tools/benchmark/node.py b/web3/tools/benchmark/node.py index 52eda6a173..60ad44ff87 100644 --- a/web3/tools/benchmark/node.py +++ b/web3/tools/benchmark/node.py @@ -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), diff --git a/web3/tools/benchmark/reporting.py b/web3/tools/benchmark/reporting.py index 3dd0203ad9..058602dfc2 100644 --- a/web3/tools/benchmark/reporting.py +++ b/web3/tools/benchmark/reporting.py @@ -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"], diff --git a/web3/tools/pytest_ethereum/deployer.py b/web3/tools/pytest_ethereum/deployer.py index 6b9eb22b02..7659a3940f 100644 --- a/web3/tools/pytest_ethereum/deployer.py +++ b/web3/tools/pytest_ethereum/deployer.py @@ -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] diff --git a/web3/tools/pytest_ethereum/linker.py b/web3/tools/pytest_ethereum/linker.py index d7385ea857..a5502cfa1b 100644 --- a/web3/tools/pytest_ethereum/linker.py +++ b/web3/tools/pytest_ethereum/linker.py @@ -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)