Skip to content

Commit

Permalink
fix: make chdir make sensE
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Dec 9, 2024
1 parent 8a37ce8 commit 63a5869
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/ape/managers/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -2569,7 +2569,7 @@ def clean(self):
self.sources._path_cache = None
self._clear_cached_config()

def chdir(self, path: Path) -> "LocalProject":
def chdir(self, path: Path):
"""
Change the local project to the new path.
Expand All @@ -2583,9 +2583,24 @@ def chdir(self, path: Path) -> "LocalProject":
return # Already there!

os.chdir(path)
new_local_project = LocalProject(path)
ManagerAccessMixin.local_project._cache = new_local_project
return new_local_project

# Clear cached properties.
for prop in (
"path",
"_deduced_contracts_folder",
"project_api",
"contracts",
"interfaces_folder",
"sources",
):
self.__dict__.pop(prop, None)

# Re-initialize
self._session_source_change_check = set()
self._config_override = {}
self._base_path = Path(path).resolve()
self.manifest_path = self._base_path / ".build" / "__local__.json"
self._manifest = self.load_manifest()

def reload_config(self):
"""
Expand Down
11 changes: 11 additions & 0 deletions tests/functional/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -1053,3 +1053,14 @@ def test_instance_map(self, project, vyper_contract_instance, mock_sepolia):
return

assert False, "Failed to find expected URI"


def test_chdir(project):
original_path = project.path
with create_tempdir() as new_path:
project.chdir(new_path)
assert project.path == new_path

# Undo.
project.chdir(original_path)
assert project.path == original_path

0 comments on commit 63a5869

Please sign in to comment.