Skip to content

Commit

Permalink
refactor: split up ape.types modules (ApeWorX#2337)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Oct 23, 2024
1 parent 86118f2 commit a257cac
Show file tree
Hide file tree
Showing 61 changed files with 763 additions and 703 deletions.
7 changes: 5 additions & 2 deletions src/ape/api/accounts.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from abc import abstractmethod
from collections.abc import Iterator
from functools import cached_property
from pathlib import Path
Expand All @@ -24,8 +25,10 @@
TransactionError,
)
from ape.logging import logger
from ape.types import AddressType, MessageSignature, SignableMessage
from ape.utils import BaseInterfaceModel, abstractmethod, raises_not_implemented
from ape.types.address import AddressType
from ape.types.signatures import MessageSignature, SignableMessage
from ape.utils.basemodel import BaseInterfaceModel
from ape.utils.misc import raises_not_implemented

if TYPE_CHECKING:
from ape.contracts import ContractContainer, ContractInstance
Expand Down
9 changes: 7 additions & 2 deletions src/ape/api/address.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
from abc import abstractmethod
from functools import cached_property
from typing import TYPE_CHECKING, Any

from eth_pydantic_types import HexBytes

from ape.exceptions import ConversionError
from ape.types import AddressType, ContractCode, CurrencyValue
from ape.utils import BaseInterface, abstractmethod, cached_property, log_instead_of_fail
from ape.types.address import AddressType
from ape.types.units import CurrencyValue
from ape.types.vm import ContractCode
from ape.utils.basemodel import BaseInterface
from ape.utils.misc import log_instead_of_fail

if TYPE_CHECKING:
from ape.api.transactions import ReceiptAPI, TransactionAPI
Expand Down
4 changes: 2 additions & 2 deletions src/ape/api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@

from ape.exceptions import ConfigError
from ape.logging import logger
from ape.types import AddressType
from ape.utils import clean_path
from ape.types.address import AddressType
from ape.utils.basemodel import (
ExtraAttributesMixin,
ExtraModelAttributes,
Expand All @@ -23,6 +22,7 @@
only_raise_attribute_error,
)
from ape.utils.misc import load_config
from ape.utils.os import clean_path

ConfigItemType = TypeVar("ConfigItemType")

Expand Down
9 changes: 5 additions & 4 deletions src/ape/api/explorers.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from abc import abstractmethod
from typing import Optional

from ethpm_types import ContractType

from ape.api import networks
from ape.types import AddressType
from ape.utils import BaseInterfaceModel, abstractmethod
from ape.api.networks import NetworkAPI
from ape.types.address import AddressType
from ape.utils.basemodel import BaseInterfaceModel


class ExplorerAPI(BaseInterfaceModel):
Expand All @@ -14,7 +15,7 @@ class ExplorerAPI(BaseInterfaceModel):
"""

name: str # Plugin name
network: networks.NetworkAPI
network: NetworkAPI

@abstractmethod
def get_address_url(self, address: AddressType) -> str:
Expand Down
8 changes: 5 additions & 3 deletions src/ape/api/networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
)
from eth_pydantic_types import HexBytes
from eth_utils import keccak, to_int
from ethpm_types import BaseModel, ContractType
from ethpm_types import ContractType
from ethpm_types.abi import ABIType, ConstructorABI, EventABI, MethodABI
from pydantic import model_validator

Expand All @@ -26,10 +26,12 @@
SignatureError,
)
from ape.logging import logger
from ape.types import AutoGasLimit, ContractLog, GasLimit
from ape.types.address import AddressType, RawAddress
from ape.types.events import ContractLog
from ape.types.gas import AutoGasLimit, GasLimit
from ape.utils.basemodel import (
BaseInterfaceModel,
BaseModel,
ExtraAttributesMixin,
ExtraModelAttributes,
ManagerAccessMixin,
Expand Down Expand Up @@ -419,7 +421,7 @@ def encode_transaction(
"""

@abstractmethod
def decode_logs(self, logs: Sequence[dict], *events: EventABI) -> Iterator["ContractLog"]:
def decode_logs(self, logs: Sequence[dict], *events: EventABI) -> Iterator[ContractLog]:
"""
Decode any contract logs that match the given event ABI from the raw log data.
Expand Down
10 changes: 8 additions & 2 deletions src/ape/api/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import sys
import time
import warnings
from abc import abstractmethod
from collections.abc import Iterable, Iterator
from functools import cached_property
from logging import FileHandler, Formatter, Logger, getLogger
from pathlib import Path
from signal import SIGINT, SIGTERM, signal
Expand All @@ -33,15 +35,19 @@
VirtualMachineError,
)
from ape.logging import LogLevel, logger
from ape.types import AddressType, BlockID, ContractCode, ContractLog, HexInt, LogFilter, SnapshotID
from ape.utils import BaseInterfaceModel, JoinableQueue, abstractmethod, cached_property, spawn
from ape.types.address import AddressType
from ape.types.basic import HexInt
from ape.types.events import ContractLog, LogFilter
from ape.types.vm import BlockID, ContractCode, SnapshotID
from ape.utils.basemodel import BaseInterfaceModel
from ape.utils.misc import (
EMPTY_BYTES32,
_create_raises_not_implemented_error,
log_instead_of_fail,
raises_not_implemented,
to_int,
)
from ape.utils.process import JoinableQueue, spawn
from ape.utils.rpc import RPCHeaders

if TYPE_CHECKING:
Expand Down
8 changes: 4 additions & 4 deletions src/ape/api/query.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from abc import abstractmethod
from collections.abc import Iterator, Sequence
from functools import cache
from functools import cache, cached_property
from typing import Any, Optional, Union

from ethpm_types.abi import EventABI, MethodABI
from pydantic import NonNegativeInt, PositiveInt, model_validator

from ape.api.transactions import ReceiptAPI, TransactionAPI
from ape.logging import logger
from ape.types import AddressType
from ape.utils import BaseInterface, BaseInterfaceModel, abstractmethod, cached_property
from ape.utils.basemodel import BaseModel
from ape.types.address import AddressType
from ape.utils.basemodel import BaseInterface, BaseInterfaceModel, BaseModel

QueryType = Union[
"BlockQuery",
Expand Down
3 changes: 1 addition & 2 deletions src/ape/api/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from collections.abc import Iterator, Sequence
from typing import IO, Any, Optional

from ape.types import ContractFunctionPath
from ape.types.trace import GasReport
from ape.types.trace import ContractFunctionPath, GasReport
from ape.utils.basemodel import BaseInterfaceModel


Expand Down
27 changes: 10 additions & 17 deletions src/ape/api/transactions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import sys
import time
from abc import abstractmethod
from collections.abc import Iterator
from datetime import datetime
from functools import cached_property
from typing import IO, TYPE_CHECKING, Any, NoReturn, Optional, Union

from eth_pydantic_types import HexBytes, HexStr
Expand All @@ -20,23 +22,14 @@
TransactionNotFoundError,
)
from ape.logging import logger
from ape.types import (
AddressType,
AutoGasLimit,
ContractLogContainer,
HexInt,
SourceTraceback,
TransactionSignature,
)
from ape.utils import (
BaseInterfaceModel,
ExtraAttributesMixin,
ExtraModelAttributes,
abstractmethod,
cached_property,
log_instead_of_fail,
raises_not_implemented,
)
from ape.types.address import AddressType
from ape.types.basic import HexInt
from ape.types.events import ContractLogContainer
from ape.types.gas import AutoGasLimit
from ape.types.signatures import TransactionSignature
from ape.types.trace import SourceTraceback
from ape.utils.basemodel import BaseInterfaceModel, ExtraAttributesMixin, ExtraModelAttributes
from ape.utils.misc import log_instead_of_fail, raises_not_implemented

if TYPE_CHECKING:
from ape.api.providers import BlockAPI
Expand Down
2 changes: 1 addition & 1 deletion src/ape/cli/choices.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
NetworkNotFoundError,
ProviderNotFoundError,
)
from ape.types import _LazySequence
from ape.types.basic import _LazySequence
from ape.utils.basemodel import ManagerAccessMixin

_ACCOUNT_TYPE_FILTER = Union[
Expand Down
20 changes: 9 additions & 11 deletions src/ape/contracts/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import difflib
import types
from collections.abc import Callable, Iterator
from functools import partial
from functools import cached_property, partial, singledispatchmethod
from itertools import islice
from pathlib import Path
from typing import Any, Optional, Union
Expand All @@ -14,14 +14,15 @@
from ethpm_types.contract_type import ABI_W_SELECTOR_T, ContractType
from IPython.lib.pretty import for_type

from ape.api import AccountAPI, Address, ReceiptAPI, TransactionAPI
from ape.api.address import BaseAddress
from ape.api.accounts import AccountAPI
from ape.api.address import Address, BaseAddress
from ape.api.query import (
ContractCreation,
ContractEventQuery,
extract_fields,
validate_and_expand_columns,
)
from ape.api.transactions import ReceiptAPI, TransactionAPI
from ape.exceptions import (
ApeAttributeError,
ArgumentsLengthError,
Expand All @@ -34,20 +35,17 @@
MissingDeploymentBytecodeError,
)
from ape.logging import get_rich_console, logger
from ape.types import AddressType, ContractLog, LogFilter, MockContractLog
from ape.utils import (
BaseInterfaceModel,
ManagerAccessMixin,
cached_property,
log_instead_of_fail,
singledispatchmethod,
)
from ape.types.address import AddressType
from ape.types.events import ContractLog, LogFilter, MockContractLog
from ape.utils.abi import StructParser, _enrich_natspec
from ape.utils.basemodel import (
BaseInterfaceModel,
ExtraAttributesMixin,
ExtraModelAttributes,
ManagerAccessMixin,
_assert_not_ipython_check,
get_attribute_with_extras,
log_instead_of_fail,
only_raise_attribute_error,
)

Expand Down
4 changes: 3 additions & 1 deletion src/ape/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
from ape.api.trace import TraceAPI
from ape.api.transactions import ReceiptAPI, TransactionAPI
from ape.managers.project import ProjectManager
from ape.types import AddressType, BlockID, SnapshotID, SourceTraceback
from ape.types.address import AddressType
from ape.types.trace import SourceTraceback
from ape.types.vm import BlockID, SnapshotID


FailedTxn = Union["TransactionAPI", "ReceiptAPI"]
Expand Down
6 changes: 4 additions & 2 deletions src/ape/managers/accounts.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import contextlib
from collections.abc import Generator, Iterator
from contextlib import AbstractContextManager as ContextManager
from functools import cached_property, singledispatchmethod
from typing import Optional, Union

from eth_utils import is_hex
Expand All @@ -14,8 +15,9 @@
)
from ape.exceptions import AccountsError, ConversionError
from ape.managers.base import BaseManager
from ape.types import AddressType
from ape.utils import ManagerAccessMixin, cached_property, log_instead_of_fail, singledispatchmethod
from ape.types.address import AddressType
from ape.utils.basemodel import ManagerAccessMixin
from ape.utils.misc import log_instead_of_fail

_DEFAULT_SENDERS: list[AccountAPI] = []

Expand Down
16 changes: 6 additions & 10 deletions src/ape/managers/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from collections.abc import Collection, Iterator
from concurrent.futures import ThreadPoolExecutor
from contextlib import contextmanager
from functools import partial
from functools import partial, singledispatchmethod
from pathlib import Path
from statistics import mean, median
from typing import IO, Optional, Union, cast
Expand Down Expand Up @@ -40,15 +40,11 @@
)
from ape.logging import get_rich_console, logger
from ape.managers.base import BaseManager
from ape.types import AddressType, GasReport, SnapshotID, SourceTraceback
from ape.utils import (
BaseInterfaceModel,
is_evm_precompile,
is_zero_hex,
log_instead_of_fail,
nonreentrant,
singledispatchmethod,
)
from ape.types.address import AddressType
from ape.types.trace import GasReport, SourceTraceback
from ape.types.vm import SnapshotID
from ape.utils.basemodel import BaseInterfaceModel
from ape.utils.misc import is_evm_precompile, is_zero_hex, log_instead_of_fail, nonreentrant


class BlockContainer(BaseManager):
Expand Down
8 changes: 5 additions & 3 deletions src/ape/managers/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from collections.abc import Iterable, Sequence
from datetime import datetime, timedelta, timezone
from decimal import Decimal
from functools import cached_property
from typing import Any, Union

from dateutil.parser import parse
Expand All @@ -17,12 +18,13 @@
)
from ethpm_types import ConstructorABI, EventABI, MethodABI

from ape.api import ConverterAPI, TransactionAPI
from ape.api.address import BaseAddress
from ape.api.convert import ConverterAPI
from ape.api.transactions import TransactionAPI
from ape.exceptions import ConversionError
from ape.logging import logger
from ape.types import AddressType
from ape.utils import cached_property, log_instead_of_fail
from ape.types.address import AddressType
from ape.utils.misc import log_instead_of_fail

from .base import BaseManager

Expand Down
2 changes: 1 addition & 1 deletion src/ape/pytest/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from _pytest.config import Config as PytestConfig

from ape.types import ContractFunctionPath
from ape.types.trace import ContractFunctionPath
from ape.utils.basemodel import ManagerAccessMixin


Expand Down
9 changes: 2 additions & 7 deletions src/ape/pytest/coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,8 @@
from ape.logging import logger
from ape.managers.project import ProjectManager
from ape.pytest.config import ConfigWrapper
from ape.types import (
ContractFunctionPath,
ControlFlow,
CoverageProject,
CoverageReport,
SourceTraceback,
)
from ape.types.coverage import CoverageProject, CoverageReport
from ape.types.trace import ContractFunctionPath, ControlFlow, SourceTraceback
from ape.utils.basemodel import ManagerAccessMixin
from ape.utils.misc import get_current_timestamp_ms
from ape.utils.os import get_full_extension, get_relative_path
Expand Down
2 changes: 1 addition & 1 deletion src/ape/pytest/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from ape.managers.networks import NetworkManager
from ape.managers.project import ProjectManager
from ape.pytest.config import ConfigWrapper
from ape.types import SnapshotID
from ape.types.vm import SnapshotID
from ape.utils.basemodel import ManagerAccessMixin
from ape.utils.rpc import allow_disconnected

Expand Down
Loading

0 comments on commit a257cac

Please sign in to comment.