From 63a5869a471b7501d08c67380e665bcc07f09ea5 Mon Sep 17 00:00:00 2001 From: Juliya Smith Date: Mon, 9 Dec 2024 14:44:02 -0600 Subject: [PATCH] fix: make chdir make sensE --- src/ape/managers/project.py | 23 +++++++++++++++++++---- tests/functional/test_project.py | 11 +++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/ape/managers/project.py b/src/ape/managers/project.py index 0a665d12e1..c7270aaed7 100644 --- a/src/ape/managers/project.py +++ b/src/ape/managers/project.py @@ -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. @@ -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): """ diff --git a/tests/functional/test_project.py b/tests/functional/test_project.py index 9dc31a7db4..1b794d87c4 100644 --- a/tests/functional/test_project.py +++ b/tests/functional/test_project.py @@ -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