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

feat: allow contract.source_path from non local project #2068

Merged
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
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
Loading