Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: lazy load style on api, utils, and types #2360

Merged
merged 5 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 59 additions & 2 deletions docs/methoddocs/utils.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,65 @@
# ape.utils

## ABI

```{eval-rst}
.. automodule:: ape.utils.abi
:members:
:show-inheritance:
```

## Basemodel

```{eval-rst}
.. automodule:: ape.utils.basemodel
:members:
:show-inheritance:
```

## Miscellaneous

```{eval-rst}
.. automodule:: ape.utils.misc
:members:
:show-inheritance:
```

## OS

```{eval-rst}
.. automodule:: ape.utils.os
:members:
:show-inheritance:
```

## Process

```{eval-rst}
.. automodule:: ape.utils.process
:members:
:show-inheritance:
```

## RPC

```{eval-rst}
.. automodule:: ape.utils.rpc
:members:
:show-inheritance:
```

## Testing

```{eval-rst}
.. automodule:: ape.utils.testing
:members:
:show-inheritance:
```

## Trace

```{eval-rst}
.. automodule:: ape.utils
.. automodule:: ape.utils.trace
:members:
:show-inheritance:
:exclude-members: abstractmethod, dataclass, __init__
```
100 changes: 76 additions & 24 deletions src/ape/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,79 @@
from .accounts import (
AccountAPI,
AccountContainerAPI,
ImpersonatedAccount,
TestAccountAPI,
TestAccountContainerAPI,
)
from .address import Address
from .compiler import CompilerAPI
from .config import ConfigDict, ConfigEnum, PluginConfig
from .convert import ConverterAPI
from .explorers import ExplorerAPI
from .networks import (
EcosystemAPI,
ForkedNetworkAPI,
NetworkAPI,
ProviderContextManager,
create_network_type,
)
from .projects import DependencyAPI, ProjectAPI
from .providers import BlockAPI, ProviderAPI, SubprocessProvider, TestProviderAPI, UpstreamProvider
from .query import QueryAPI, QueryType
from .trace import TraceAPI
from .transactions import ReceiptAPI, TransactionAPI
def __getattr__(name: str):
if name in (
"AccountAPI",
"AccountContainerAPI",
"ImpersonatedAccount",
"TestAccountAPI",
"TestAccountContainerAPI",
):
import ape.api.accounts as accounts_module

return getattr(accounts_module, name)

elif name in ("Address",):
import ape.api.address as address_module

return getattr(address_module, name)

elif name in ("CompilerAPI",):
import ape.api.compiler as compiler_module

return getattr(compiler_module, name)

elif name in ("ConfigDict", "ConfigEnum", "PluginConfig"):
import ape.api.config as config_module

return getattr(config_module, name)

elif name in ("ConverterAPI",):
import ape.api.convert as convert_module

return getattr(convert_module, name)

elif name in ("ExplorerAPI",):
import ape.api.explorers as explorer_module

return getattr(explorer_module, name)

elif name in ("BlockAPI, ProviderAPI, SubprocessProvider, TestProviderAPI, UpstreamProvider"):
import ape.api.providers as provider_module

return getattr(provider_module, name)

elif name in (
"EcosystemAPI",
"ForkedNetworkAPI",
"NetworkAPI",
"ProviderContextManager",
"create_network_type",
):
import ape.api.networks as network_module

return getattr(network_module, name)

elif name in ("DependencyAPI", "ProjectAPI"):
import ape.api.projects as project_module

return getattr(project_module, name)

elif name in ("QueryAPI", "QueryType"):
import ape.api.query as query_module

return getattr(query_module, name)

elif name in ("TraceAPI",):
import ape.api.trace as trace_module

return getattr(trace_module, name)

elif name in ("ReceiptAPI", "TransactionAPI"):
import ape.api.transactions as tx_module

return getattr(tx_module, name)

else:
raise AttributeError(name)


__all__ = [
"AccountAPI",
Expand Down
133 changes: 94 additions & 39 deletions src/ape/types/__init__.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,97 @@
from eth_pydantic_types import HexBytes
from ethpm_types import (
ABI,
Bytecode,
Checksum,
Compiler,
ContractType,
PackageManifest,
PackageMeta,
Source,
)
from ethpm_types.source import Closure

from ape.types.address import AddressType, RawAddress
from ape.types.basic import HexInt, _LazySequence
from ape.types.coverage import (
ContractCoverage,
ContractSourceCoverage,
CoverageProject,
CoverageReport,
CoverageStatement,
)
from ape.types.events import ContractLog, ContractLogContainer, LogFilter, MockContractLog
from ape.types.gas import AutoGasLimit, GasLimit
from ape.types.signatures import MessageSignature, SignableMessage, TransactionSignature
from ape.types.trace import ContractFunctionPath, ControlFlow, GasReport, SourceTraceback
from ape.types.units import CurrencyValue, CurrencyValueComparable
from ape.types.vm import BlockID, ContractCode, SnapshotID
from ape.utils.basemodel import (
BaseInterface,
BaseInterfaceModel,
BaseModel,
ExtraAttributesMixin,
ExtraModelAttributes,
ManagerAccessMixin,
get_attribute_with_extras,
get_item_with_extras,
only_raise_attribute_error,
)
def __getattr__(name: str):
if name in ("HexBytes",):
from eth_pydantic_types import HexBytes

return HexBytes

elif name in (
"ABI",
"Bytecode",
"Checksum",
"Compiler",
"ContractType",
"PackageManifest",
"PackageMeta",
"Source",
):
import ethpm_types

return getattr(ethpm_types, name)

elif name in ("Closure",):
from ethpm_types.source import Closure

return Closure

elif name in ("AddressType", "RawAddress"):
import ape.types.address as address_module

return getattr(address_module, name)

elif name in ("HexInt", "_LazySequence"):
import ape.types.basic as basic_module

return getattr(basic_module, name)

elif name in (
"ContractCoverage",
"ContractSourceCoverage",
"CoverageProject",
"CoverageReport",
"CoverageStatement",
):
import ape.types.coverage as coverage_module

return getattr(coverage_module, name)

elif name in ("ContractLog", "ContractLogContainer", "LogFilter", "MockContractLog"):
import ape.types.events as events_module

return getattr(events_module, name)

elif name in ("AutoGasLimit", "GasLimit"):
import ape.types.gas as gas_module

return getattr(gas_module, name)

elif name in ("MessageSignature", "SignableMessage", "TransactionSignature"):
import ape.types.signatures as sig_module

return getattr(sig_module, name)

elif name in ("ContractFunctionPath", "ControlFlow", "GasReport", "SourceTraceback"):
import ape.types.trace as trace_module

return getattr(trace_module, name)

elif name in ("CurrencyValue", "CurrencyValueComparable"):
import ape.types.units as units_module

return getattr(units_module, name)

elif name in ("BlockID", "ContractCode", "SnapshotID"):
import ape.types.vm as vm_module

return getattr(vm_module, name)

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

return getattr(basemodel_module, name)

else:
raise AttributeError(name)


__all__ = [
"_LazySequence",
Expand Down
Loading
Loading