Skip to content

Commit

Permalink
perf: utils same
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Oct 31, 2024
1 parent 1a47b9b commit caaa6fe
Showing 1 changed file with 112 additions and 73 deletions.
185 changes: 112 additions & 73 deletions src/ape/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,76 +1,115 @@
from abc import abstractmethod

from ape.utils.abi import (
LogInputABICollection,
Struct,
StructParser,
is_array,
is_dynamic_sized_type,
is_named_tuple,
is_struct,
returns_array,
)
from ape.utils.basemodel import (
BaseInterface,
BaseInterfaceModel,
ExtraAttributesMixin,
ExtraModelAttributes,
ManagerAccessMixin,
injected_before_use,
only_raise_attribute_error,
)
from ape.utils.misc import (
DEFAULT_LIVE_NETWORK_BASE_FEE_MULTIPLIER,
DEFAULT_LOCAL_TRANSACTION_ACCEPTANCE_TIMEOUT,
DEFAULT_TRANSACTION_ACCEPTANCE_TIMEOUT,
EMPTY_BYTES32,
LOCAL_NETWORK_NAME,
SOURCE_EXCLUDE_PATTERNS,
ZERO_ADDRESS,
add_padding_to_strings,
as_our_module,
cached_property,
extract_nested_value,
gas_estimation_error_message,
get_current_timestamp_ms,
get_package_version,
is_evm_precompile,
is_zero_hex,
load_config,
log_instead_of_fail,
nonreentrant,
pragma_str_to_specifier_set,
raises_not_implemented,
run_until_complete,
singledispatchmethod,
to_int,
)
from ape.utils.os import (
clean_path,
create_tempdir,
expand_environment_variables,
extract_archive,
get_all_files_in_directory,
get_full_extension,
get_package_path,
get_relative_path,
in_tempdir,
path_match,
run_in_tempdir,
use_temp_sys_path,
)
from ape.utils.process import JoinableQueue, spawn
from ape.utils.rpc import USER_AGENT, RPCHeaders, allow_disconnected, stream_response
from ape.utils.testing import (
DEFAULT_NUMBER_OF_TEST_ACCOUNTS,
DEFAULT_TEST_ACCOUNT_BALANCE,
DEFAULT_TEST_CHAIN_ID,
DEFAULT_TEST_HD_PATH,
DEFAULT_TEST_MNEMONIC,
GeneratedDevAccount,
generate_dev_accounts,
)
from ape.utils.trace import USER_ASSERT_TAG, TraceStyles, parse_coverage_tables, parse_gas_table
def __getattr__(name: str):
if name == "abstractmethod":
from abc import abstractmethod

return abstractmethod

elif name in (
"LogInputABICollection",
"Struct",
"StructParser",
"is_array",
"is_dynamic_sized_type",
"is_named_tuple",
"is_struct",
"returns_array",
):
import ape.utils.abi as abi_module

return getattr(abi_module, name)

elif name in (
"BaseInterface",
"BaseInterfaceModel",
"ExtraAttributesMixin",
"ExtraModelAttributes",
"ManagerAccessMixin",
"injected_before_use",
"only_raise_attribute_error",
):
import ape.utils.basemodel as basemodel_module

return getattr(basemodel_module, name)

elif name in (
"DEFAULT_LIVE_NETWORK_BASE_FEE_MULTIPLIER",
"DEFAULT_LOCAL_TRANSACTION_ACCEPTANCE_TIMEOUT",
"DEFAULT_TRANSACTION_ACCEPTANCE_TIMEOUT",
"EMPTY_BYTES32",
"LOCAL_NETWORK_NAME",
"SOURCE_EXCLUDE_PATTERNS",
"ZERO_ADDRESS",
"add_padding_to_strings",
"as_our_module",
"cached_property",
"extract_nested_value",
"gas_estimation_error_message",
"get_current_timestamp_ms",
"get_package_version",
"is_evm_precompile",
"is_zero_hex",
"load_config",
"log_instead_of_fail",
"nonreentrant",
"pragma_str_to_specifier_set",
"raises_not_implemented",
"run_until_complete",
"singledispatchmethod",
"to_int",
):
import ape.utils.misc as misc_module

return getattr(misc_module, name)

elif name in (
"clean_path",
"create_tempdir",
"expand_environment_variables",
"extract_archive",
"get_all_files_in_directory",
"get_full_extension",
"get_package_path",
"get_relative_path",
"in_tempdir",
"path_match",
"run_in_tempdir",
"use_temp_sys_path",
):
import ape.utils.os as os_module

return getattr(os_module, name)

elif name in ("JoinableQueue", "spawn"):
import ape.utils.process as process_module

return getattr(process_module, name)

elif name in ("USER_AGENT", "RPCHeaders", "allow_disconnected", "stream_response"):
import ape.utils.rpc as rpc_module

return getattr(rpc_module, name)

elif name in (
"DEFAULT_NUMBER_OF_TEST_ACCOUNTS",
"DEFAULT_TEST_ACCOUNT_BALANCE",
"DEFAULT_TEST_CHAIN_ID",
"DEFAULT_TEST_HD_PATH",
"DEFAULT_TEST_MNEMONIC",
"GeneratedDevAccount",
"generate_dev_accounts",
):
import ape.utils.testing as testing_module

return getattr(testing_module, name)

elif name in ("USER_ASSERT_TAG", "TraceStyles", "parse_coverage_tables", "parse_gas_table"):
import ape.utils.trace as trace_module

return getattr(trace_module, name)

else:
raise AttributeError(name)


__all__ = [
"abstractmethod",
Expand Down

0 comments on commit caaa6fe

Please sign in to comment.