Skip to content

Commit

Permalink
feat: allow source_path from non local project (#2068)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed May 7, 2024
1 parent b2ded34 commit 534952b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/ape/api/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ def deploy(
self.project_manager.track_deployment(instance)
self.provider.network.publish_contract(address)

instance.base_path = contract.base_path or self.project_manager.contracts_folder
return instance

def declare(self, contract: "ContractContainer", *args, **kwargs) -> ReceiptAPI:
Expand Down
23 changes: 7 additions & 16 deletions src/ape/contracts/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,7 @@ def poll_logs(

class ContractTypeWrapper(ManagerAccessMixin):
contract_type: ContractType
base_path: Optional[Path] = None

@property
def selector_identifiers(self) -> Dict[str, str]:
Expand All @@ -747,7 +748,7 @@ def identifier_lookup(self) -> Dict[str, ABI_W_SELECTOR_T]:
"""
return self.contract_type.identifier_lookup

@cached_property
@property
def source_path(self) -> Optional[Path]:
"""
Returns the path to the local contract if determined that this container
Expand All @@ -757,23 +758,12 @@ def source_path(self) -> Optional[Path]:
source ID as one in the current project. That does not necessarily mean
they are the same contract, however.
"""
contract_name = self.contract_type.name
source_id = self.contract_type.source_id
if not (contract_name and source_id):
if not (source_id := self.contract_type.source_id):
return None

contract_container = self.project_manager._get_contract(contract_name)
if not (
contract_container
and contract_container.contract_type.source_id
and self.contract_type.source_id
):
return None

if source_id == contract_container.contract_type.source_id:
return self.project_manager.contracts_folder / source_id
else:
return None
base = self.base_path or self.project_manager.contracts_folder
path = base / source_id
return path if path.is_file() else None

def decode_input(self, calldata: bytes) -> Tuple[str, Dict[str, Any]]:
"""
Expand Down Expand Up @@ -1420,6 +1410,7 @@ def deploy(self, *args, publish: bool = False, **kwargs) -> ContractInstance:
self.project_manager.track_deployment(instance)
self.provider.network.publish_contract(address)

instance.base_path = self.base_path or self.project_manager.contracts_folder
return instance

def _cache_wrap(self, function: Callable) -> ReceiptAPI:
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/test_contract_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def test_source_path_in_project(project_with_contract):
contract = project_with_contract.contracts["Contract"]
contract_container = project_with_contract.get_contract("Contract")
expected = contracts_folder / contract.source_id

assert contract_container.source_path is not None
assert contract_container.source_path.is_file()
assert contract_container.source_path == expected

Expand Down

0 comments on commit 534952b

Please sign in to comment.