diff --git a/softpack_core/schemas/environment.py b/softpack_core/schemas/environment.py index 92cd64f..48f662d 100644 --- a/softpack_core/schemas/environment.py +++ b/softpack_core/schemas/environment.py @@ -775,9 +775,7 @@ def delete(cls, name: str, path: str) -> DeleteResponse: # type: ignore tree_oid = artifacts.delete_environment(name, path) artifacts.commit_and_push(tree_oid, "delete environment") - index = cls.env_index_from_path(str(Path(path, name))) - if index is not None: - del Environment.environments[index] + Environment.update_cache(Path(path, name)) return DeleteEnvironmentSuccess( message="Successfully deleted the environment" @@ -964,20 +962,9 @@ async def write_artifacts( error="".join(format_exception_only(type(e), e)) ) - @classmethod - def env_index_from_path(cls, folder_path: str) -> Optional[int]: - """Return the index of a folder_path from the list of environments.""" - return next( - ( - i - for i, env in enumerate(Environment.environments) - if str(env.full_path()) == folder_path - ), - None, - ) - @classmethod def update_cache(cls, folder_path: str | Path) -> None: + """Regenerate the cached environment specified by the path.""" index = cls.env_index_from_path(str(folder_path)) path = Path(folder_path) env = Environment.get_env(path.parent, path.name) @@ -990,6 +977,18 @@ def update_cache(cls, folder_path: str | Path) -> None: else: del Environment.environments[index] + @classmethod + def env_index_from_path(cls, folder_path: str) -> Optional[int]: + """Return the index of a folder_path from the list of environments.""" + return next( + ( + i + for i, env in enumerate(Environment.environments) + if str(env.full_path()) == folder_path + ), + None, + ) + @classmethod async def update_from_module( cls, file: bytes, module_path: str, environment_path: str