1- import sys
1+ import logging
22import pathlib
3- import requests
43import subprocess
4+ import sys
5+
6+ import requests
57
68from cvm .services .cache_service import CacheService
79from cvm .services .github_service import GitHubService
8- import logging
910
1011
1112class ComposerService :
@@ -39,7 +40,7 @@ def cached_version_exists(tag_name: str) -> bool:
3940 :return: Bool
4041 '''
4142
42- cache_path = CacheService .CACHE_DIR / tag_name
43+ cache_path = CacheService .CACHE_DIR / tag_name / 'composer'
4344 return cache_path .exists ()
4445
4546 def _get_setup_path (self ) -> pathlib .Path :
@@ -56,24 +57,25 @@ def _get_setup_path(self) -> pathlib.Path:
5657 setup_path .write_bytes (r .content )
5758 return setup_path
5859
59- def install_version (self , tag_name : str ) -> bool :
60+ def install_version (self , tag_name : str , quiet = False ) -> pathlib . Path :
6061 if not self .tag_exists (tag_name ):
6162 logging .error ("Tag {} does not exist." .format (tag_name ))
6263 sys .exit (1 )
6364
6465 setup_path = self ._get_setup_path ()
65- cache_path = CacheService .get_cache_folder (tag_name )
66+ cache_path = CacheService .make_cache_folder (tag_name )
67+
68+ if ComposerService .cached_version_exists (tag_name ):
69+ return cache_path
6670
6771 cmd = ['php' , str (setup_path ), f'--install-dir={ str (cache_path )} ' , '--filename=composer' , f'--version={ tag_name } ' ]
6872 result = subprocess .run (cmd , stdout = subprocess .PIPE , check = True )
69- print (result .stdout .decode ('utf-8' ))
70-
71- return True
73+ if not quiet :
74+ print (result .stdout .decode ('utf-8' ))
7275
73- def use_version (self , tag_name : str , check_exists : bool = True ) -> bool :
74- if check_exists and not ComposerService .cached_version_exists (tag_name ):
75- return False
76+ return cache_path
7677
77- # TODO: Use cached version if exists
78+ def use_version (self , tag_name : str ) -> str :
79+ install_path = self .install_version (tag_name , quiet = True )
7880
79- return True
81+ return str ( install_path )
0 commit comments