-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(py-sdk): add support for release detection and deployments
- Loading branch information
Showing
3 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from typing import Any | ||
|
||
from ape.contracts import ContractInstance | ||
from ape.types import AddressType, BaseInterfaceModel | ||
from pydantic import field_validator | ||
|
||
from .exceptions import NoFactoryAvailable | ||
from .manager import StreamManager | ||
from .package import MANIFEST | ||
|
||
|
||
class StreamFactory(BaseInterfaceModel): | ||
address: AddressType | ||
|
||
def __init__(self, address=None, /, *args, **kwargs): | ||
if address is not None: | ||
kwargs["address"] = address | ||
|
||
elif len(MANIFEST.StreamFactory.deployments) == 0: | ||
raise NoFactoryAvailable() | ||
|
||
else: | ||
kwargs["address"] = MANIFEST.StreamFactory.deployments[-1] | ||
|
||
super().__init__(*args, **kwargs) | ||
|
||
def __hash__(self) -> int: | ||
return self.address.__hash__() | ||
|
||
@field_validator("address", mode="before") | ||
def normalize_address(cls, value: Any) -> AddressType: | ||
return cls.conversion_manager.convert(value, AddressType) | ||
|
||
@property | ||
def contract(self) -> ContractInstance: | ||
return MANIFEST.StreamFactory.at(self.address) | ||
|
||
def get_deployment(self, deployer: Any) -> StreamManager: | ||
# TODO: Add product selection to the factory using `product=` kwarg (defaults to empty) | ||
return StreamManager(self.contract.deployments(deployer)) | ||
|
||
|
||
class Releases: | ||
def __getitem__(self, release: int) -> StreamFactory: | ||
if ( | ||
len(MANIFEST.StreamFactory.deployments) < release | ||
or len(MANIFEST.StreamFactory.deployments) == 0 | ||
): | ||
raise IndexError("release index out of range") from NoFactoryAvailable() | ||
|
||
return StreamFactory(MANIFEST.StreamFactory.deployments[release]) | ||
|
||
@property | ||
def latest(self) -> StreamFactory: | ||
return StreamFactory() | ||
|
||
|
||
releases = Releases() |