22import os
33import shutil
44from os import path
5- from typing import Dict , List
5+ from typing import Dict , List , Optional
66from pathlib import Path
77
88from erdpy import config , dependencies , downloader , errors , myprocess , utils , workstation
@@ -22,6 +22,9 @@ def install(self, tag: str, overwrite: bool) -> None:
2222 # Fallback to default tag if not provided
2323 tag = tag or config .get_dependency_tag (self .key )
2424
25+ if tag == 'latest' :
26+ tag = self .get_latest_release ()
27+
2528 logger .debug (f"install: key={ self .key } , tag={ tag } " )
2629
2730 if self ._should_skip (tag , overwrite ):
@@ -31,8 +34,6 @@ def install(self, tag: str, overwrite: bool) -> None:
3134 self .uninstall (tag )
3235 self ._do_install (tag )
3336
34- # Upon installation we update the default tag
35- config .set_dependency_tag (self .key , tag )
3637 self ._post_install (tag )
3738
3839 def _do_install (self , tag : str ) -> None :
@@ -55,15 +56,23 @@ def is_installed(self, tag: str) -> bool:
5556 def get_env (self ) -> Dict [str , str ]:
5657 raise NotImplementedError ()
5758
59+ def get_latest_release (self ) -> str :
60+ raise NotImplementedError ()
61+
5862
5963class StandaloneModule (DependencyModule ):
60- def __init__ (self , key : str , aliases : List [str ] = None , repo_name = None ):
64+ def __init__ (self ,
65+ key : str ,
66+ aliases : List [str ] = None ,
67+ repo_name : Optional [str ] = None ,
68+ organisation : Optional [str ] = None ):
6169 if aliases is None :
6270 aliases = list ()
6371
6472 super ().__init__ (key , aliases )
6573 self .archive_type = "tar.gz"
6674 self .repo_name = repo_name
75+ self .organisation = organisation
6776
6877 def _do_install (self , tag : str ):
6978 self ._download (tag )
@@ -73,7 +82,7 @@ def uninstall(self, tag: str):
7382 if os .path .isdir (self .get_directory (tag )):
7483 shutil .rmtree (self .get_directory (tag ))
7584
76- def is_installed (self , tag : str ):
85+ def is_installed (self , tag : str ) -> bool :
7786 return path .isdir (self .get_directory (tag ))
7887
7988 def _download (self , tag : str ):
@@ -105,6 +114,7 @@ def get_source_directory(self, tag: str):
105114 # the initial 'v'.
106115 if tag .startswith ("v" ):
107116 tag = tag [1 :]
117+ assert isinstance (self .repo_name , str )
108118 source_folder = folder / (self .repo_name + '-' + tag )
109119 return source_folder
110120
@@ -114,13 +124,22 @@ def get_parent_directory(self):
114124
115125 def _get_download_url (self , tag : str ) -> str :
116126 platform = workstation .get_platform ()
127+
117128 url = config .get_dependency_url (self .key , tag , platform )
118129 if url is None :
119130 raise errors .PlatformNotSupported (self .key , platform )
120131
121132 url = url .replace ("{TAG}" , tag )
122133 return url
123134
135+ def get_latest_release (self ) -> str :
136+ if self .repo_name is None or self .organisation is None :
137+ raise ValueError (f'{ self .key } : repo_name or organisation not specified' )
138+
139+ org_repo = f'{ self .organisation } /{ self .repo_name } '
140+ tag = utils .query_latest_release_tag (org_repo )
141+ return tag
142+
124143 def _get_archive_path (self , tag : str ) -> str :
125144 tools_folder = workstation .get_tools_folder ()
126145 archive = path .join (tools_folder , f"{ self .key } .{ tag } .{ self .archive_type } " )
@@ -134,6 +153,7 @@ def __init__(self, key: str, aliases: List[str] = None):
134153
135154 super ().__init__ (key , aliases )
136155 self .repo_name = 'arwen-wasm-vm'
156+ self .organisation = 'ElrondNetwork'
137157
138158 def _post_install (self , tag : str ):
139159 dependencies .install_module ('golang' )
@@ -195,6 +215,9 @@ def get_env(self):
195215 def get_gopath (self ):
196216 return path .join (self .get_parent_directory (), "GOPATH" )
197217
218+ def get_latest_release (self ) -> str :
219+ raise errors .UnsupportedConfigurationValue ("Golang tag must always be explicit, not latest" )
220+
198221
199222class NodejsModule (StandaloneModule ):
200223 def __init__ (self , key : str , aliases : List [str ]):
@@ -216,6 +239,9 @@ def get_env(self):
216239 "PATH" : f"{ bin_folder } :{ os .environ ['PATH' ]} " ,
217240 }
218241
242+ def get_latest_release (self ) -> str :
243+ raise errors .UnsupportedConfigurationValue ("Nodejs tag must always be explicit, not latest" )
244+
219245
220246class Rust (DependencyModule ):
221247 def __init__ (self , key : str , aliases : List [str ] = None ):
@@ -242,7 +268,7 @@ def uninstall(self, tag: str):
242268 if os .path .isdir (directory ):
243269 shutil .rmtree (directory )
244270
245- def is_installed (self , tag : str ):
271+ def is_installed (self , tag : str ) -> bool :
246272 try :
247273 myprocess .run_process (["rustc" , "--version" ], env = self .get_env ())
248274 return True
@@ -266,13 +292,18 @@ def get_env(self):
266292 "CARGO_HOME" : directory
267293 }
268294
295+ def get_latest_release (self ) -> str :
296+ raise errors .UnsupportedConfigurationValue ("Rust tag must either be explicit, empty or 'nightly'" )
297+
269298
270299class MclSignerModule (StandaloneModule ):
271300 def __init__ (self , key : str , aliases : List [str ] = None ):
272301 if aliases is None :
273302 aliases = list ()
274303
275304 super ().__init__ (key , aliases )
305+ self .organisation = 'ElrondNetwork'
306+ self .repo_name = 'elrond-sdk-go-tools'
276307
277308 def _post_install (self , tag : str ):
278309 directory = self .get_directory (tag )
0 commit comments