Skip to content

Commit e99f40a

Browse files
committed
Add support for 'latest' tags where applicable
1 parent 64aa70a commit e99f40a

6 files changed

Lines changed: 68 additions & 15 deletions

File tree

erdpy/config.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,28 +146,28 @@ def get_defaults() -> Dict[str, Any]:
146146
"proxy": "https://testnet-gateway.elrond.com",
147147
"chainID": "T",
148148
"txVersion": "1",
149-
"dependencies.arwentools.tag": "v1.1.2",
150-
"dependencies.elrond_wasm_rs.tag": "v0.12.0",
149+
"dependencies.arwentools.tag": "latest",
150+
"dependencies.elrond_wasm_rs.tag": "latest",
151151
"dependencies.arwentools.urlTemplate.linux": "https://github.com/ElrondNetwork/arwen-wasm-vm/archive/{TAG}.tar.gz",
152152
"dependencies.arwentools.urlTemplate.osx": "https://github.com/ElrondNetwork/arwen-wasm-vm/archive/{TAG}.tar.gz",
153153
"dependencies.llvm.tag": "v9-19feb",
154154
"dependencies.llvm.urlTemplate.linux": "https://ide.elrond.com/vendor-llvm/{TAG}/linux-amd64.tar.gz?t=19feb",
155155
"dependencies.llvm.urlTemplate.osx": "https://ide.elrond.com/vendor-llvm/{TAG}/darwin-amd64.tar.gz?t=19feb",
156-
"dependencies.rust.tag": "",
156+
"dependencies.rust.tag": "nightly",
157157
"dependencies.nodejs.tag": "v12.18.3",
158158
"dependencies.nodejs.urlTemplate.linux": "https://nodejs.org/dist/{TAG}/node-{TAG}-linux-x64.tar.gz",
159159
"dependencies.nodejs.urlTemplate.osx": "https://nodejs.org/dist/{TAG}/node-{TAG}-darwin-x64.tar.gz",
160-
"dependencies.elrond_go.tag": "master",
160+
"dependencies.elrond_go.tag": "latest",
161161
"dependencies.elrond_go.urlTemplate.linux": "https://github.com/ElrondNetwork/elrond-go/archive/{TAG}.tar.gz",
162162
"dependencies.elrond_go.urlTemplate.osx": "https://github.com/ElrondNetwork/elrond-go/archive/{TAG}.tar.gz",
163163
"dependencies.elrond_go.url": "https://github.com/ElrondNetwork/elrond-go/archive/{TAG}.tar.gz",
164-
"dependencies.elrond_proxy_go.tag": "master",
164+
"dependencies.elrond_proxy_go.tag": "latest",
165165
"dependencies.elrond_proxy_go.urlTemplate.linux": "https://github.com/ElrondNetwork/elrond-proxy-go/archive/{TAG}.tar.gz",
166166
"dependencies.elrond_proxy_go.urlTemplate.osx": "https://github.com/ElrondNetwork/elrond-proxy-go/archive/{TAG}.tar.gz",
167167
"dependencies.golang.tag": "go1.15.2",
168168
"dependencies.golang.urlTemplate.linux": "https://golang.org/dl/{TAG}.linux-amd64.tar.gz",
169169
"dependencies.golang.urlTemplate.osx": "https://golang.org/dl/{TAG}.darwin-amd64.tar.gz",
170-
"dependencies.mcl_signer.tag": "v1.0.0",
170+
"dependencies.mcl_signer.tag": "latest",
171171
"dependencies.mcl_signer.urlTemplate.linux": "https://github.com/ElrondNetwork/elrond-sdk-go-tools/releases/download/{TAG}/mcl_signer_{TAG}_ubuntu-latest.tar.gz",
172172
"dependencies.mcl_signer.urlTemplate.osx": "https://github.com/ElrondNetwork/elrond-sdk-go-tools/releases/download/{TAG}/mcl_signer_{TAG}_macos-latest.tar.gz",
173173
}

erdpy/dependencies/install.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ def get_all_deps() -> List[DependencyModule]:
4444
ArwenToolsModule(key="arwentools"),
4545
Rust(key="rust"),
4646
NodejsModule(key="nodejs", aliases=[]),
47-
StandaloneModule(key="elrond_go"),
48-
StandaloneModule(key="elrond_proxy_go"),
47+
StandaloneModule(key="elrond_go", repo_name="elrond-go", organisation="ElrondNetwork"),
48+
StandaloneModule(key="elrond_proxy_go", repo_name="elrond-proxy-go", organisation="ElrondNetwork"),
4949
GolangModule(key="golang"),
5050
MclSignerModule(key="mcl_signer")
5151
]

erdpy/dependencies/modules.py

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import os
33
import shutil
44
from os import path
5-
from typing import Dict, List
5+
from typing import Dict, List, Optional
66
from pathlib import Path
77

88
from 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

5963
class 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

199222
class 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

220246
class 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

270299
class 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)

erdpy/errors.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ def __init__(self, name: str):
130130
super().__init__(f"This configuration name is protected: {name}.")
131131

132132

133+
class UnsupportedConfigurationValue(KnownError):
134+
pass
135+
136+
133137
class UnknownDerivationFunction(KnownError):
134138
def __init__(self):
135139
super().__init__("Unknown key derivation function.")

erdpy/projects/templates_config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22

33
from erdpy import config
44
from erdpy.projects.templates_repository import TemplatesRepository
5+
from erdpy.utils import query_latest_release_tag
56

67

78
def get_templates_repositories():
89
timestamp = int(time.time())
910
examples_rs_tag = config.get_dependency_tag('elrond_wasm_rs')
11+
12+
if examples_rs_tag == 'latest':
13+
examples_rs_tag = query_latest_release_tag('ElrondNetwork/elrond-wasm-rs')
14+
1015
examples_rs_tag_no_v = remove_initial_v_from_version(examples_rs_tag)
1116

1217
return [

erdpy/utils.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
import shutil
77
import stat
88
import sys
9+
import requests
910
import tarfile
1011
import zipfile
1112
from pathlib import Path
12-
from typing import Any, AnyStr, List, Union, Optional, cast, IO, Dict
13+
from typing import Any, List, Union, Optional, cast, IO, Dict
1314

1415
import toml
1516

@@ -225,6 +226,18 @@ def parse_keys(bls_public_keys):
225226
return parsed_keys, len(keys)
226227

227228

229+
def query_latest_release_tag(repo: str) -> str:
230+
"""
231+
Queries the Github API to retrieve the latest released tag of the specified
232+
repository. The repository must be of the form 'organisation/project'.
233+
"""
234+
url = f'https://api.github.com/repos/{repo}/releases/latest'
235+
response = requests.get(url)
236+
response.raise_for_status()
237+
latest_release_tag = str(response.json()['tag_name'])
238+
return latest_release_tag
239+
240+
228241
# https://code.visualstudio.com/docs/python/debugging
229242
def breakpoint():
230243
import debugpy

0 commit comments

Comments
 (0)