44import click
55
66from cycode .cli .models import Document
7- from cycode .cli .utils .path_utils import get_file_dir , join_paths
7+ from cycode .cli .utils .path_utils import get_file_content , get_file_dir , join_paths
88from cycode .cli .utils .shell_executor import shell
99from cycode .cyclient import logger
1010
@@ -39,6 +39,23 @@ def get_manifest_file_path(self, document: Document) -> str:
3939 else document .path
4040 )
4141
42+ def try_restore_dependencies (self , document : Document ) -> Optional [Document ]:
43+ manifest_file_path = self .get_manifest_file_path (document )
44+ restore_file_path = build_dep_tree_path (document .path , self .get_lock_file_name ())
45+
46+ if self .verify_restore_file_already_exist (restore_file_path ):
47+ restore_file_content = get_file_content (restore_file_path )
48+ else :
49+ restore_file_content = execute_command (
50+ self .get_command (manifest_file_path ), manifest_file_path , self .command_timeout
51+ )
52+
53+ return Document (restore_file_path , restore_file_content , self .is_git_diff )
54+
55+ @abstractmethod
56+ def verify_restore_file_already_exist (self , restore_file_path : str ) -> bool :
57+ pass
58+
4259 @abstractmethod
4360 def is_project (self , document : Document ) -> bool :
4461 pass
@@ -50,11 +67,3 @@ def get_command(self, manifest_file_path: str) -> List[str]:
5067 @abstractmethod
5168 def get_lock_file_name (self ) -> str :
5269 pass
53-
54- def try_restore_dependencies (self , document : Document ) -> Optional [Document ]:
55- manifest_file_path = self .get_manifest_file_path (document )
56- return Document (
57- build_dep_tree_path (document .path , self .get_lock_file_name ()),
58- execute_command (self .get_command (manifest_file_path ), manifest_file_path , self .command_timeout ),
59- self .is_git_diff ,
60- )
0 commit comments