From d42df24ef9c6895ae42ec93a4c821755def370f9 Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Fri, 5 Jan 2024 15:21:32 +0200 Subject: [PATCH 1/7] fix deps check all command --- multiversx_sdk_cli/cli_deps.py | 17 ++++++++++++++--- multiversx_sdk_cli/dependencies/__init__.py | 7 +++++-- multiversx_sdk_cli/dependencies/install.py | 8 ++++---- multiversx_sdk_cli/tests/test_cli_deps.py | 6 ++++++ 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/multiversx_sdk_cli/cli_deps.py b/multiversx_sdk_cli/cli_deps.py index 095eb5ce..f03e997f 100644 --- a/multiversx_sdk_cli/cli_deps.py +++ b/multiversx_sdk_cli/cli_deps.py @@ -3,6 +3,7 @@ from multiversx_sdk_cli import cli_shared, config, dependencies, errors from multiversx_sdk_cli.dependencies.install import get_deps_dict +from multiversx_sdk_cli.dependencies.modules import DependencyModule logger = logging.getLogger("cli.deps") @@ -34,7 +35,17 @@ def install(args: Any): def check(args: Any): name: str = args.name - module = dependencies.get_module_by_key(name) + if name == "all": + all_dependencies = dependencies.get_all_deps() + + for dependency in all_dependencies: + check_module_is_installed(dependency) + else: + module = dependencies.get_module_by_key(name) + check_module_is_installed(module) + + +def check_module_is_installed(module: DependencyModule) -> None: tag_to_check: str = config.get_dependency_tag(module.key) resolution: str = config.get_dependency_resolution(module.key) resolution = resolution if resolution else "HOST" @@ -43,7 +54,7 @@ def check(args: Any): installed = module.is_installed(tag_to_check) if installed: - logger.info(f"[{name} {tag_to_check}] is installed.") + logger.info(f"[{module.key} {tag_to_check}] is installed.") return - raise errors.DependencyMissing(name, tag_to_check) + raise errors.DependencyMissing(module.key, tag_to_check) diff --git a/multiversx_sdk_cli/dependencies/__init__.py b/multiversx_sdk_cli/dependencies/__init__.py index fc15e09a..c21f5006 100644 --- a/multiversx_sdk_cli/dependencies/__init__.py +++ b/multiversx_sdk_cli/dependencies/__init__.py @@ -1,3 +1,6 @@ -from multiversx_sdk_cli.dependencies.install import install_module, get_module_directory, get_module_by_key, get_golang +from multiversx_sdk_cli.dependencies.install import (get_all_deps, get_golang, + get_module_by_key, + get_module_directory, + install_module) -__all__ = ["install_module", "get_module_directory", "get_module_by_key", "get_golang"] +__all__ = ["install_module", "get_module_directory", "get_module_by_key", "get_golang", "get_all_deps"] diff --git a/multiversx_sdk_cli/dependencies/install.py b/multiversx_sdk_cli/dependencies/install.py index 64945e4f..0ca7d900 100644 --- a/multiversx_sdk_cli/dependencies/install.py +++ b/multiversx_sdk_cli/dependencies/install.py @@ -13,7 +13,7 @@ def install_module(key: str, overwrite: bool = False): if key == 'all': - modules = _get_all_deps() + modules = get_all_deps() else: modules = [get_module_by_key(key)] @@ -29,7 +29,7 @@ def get_module_directory(key: str) -> Path: def get_module_by_key(key: str) -> DependencyModule: - matches = [module for module in _get_all_deps() if module.key == key or key in module.aliases] + matches = [module for module in get_all_deps() if module.key == key or key in module.aliases] if len(matches) != 1: raise errors.UnknownDependency(key) @@ -39,7 +39,7 @@ def get_module_by_key(key: str) -> DependencyModule: def get_deps_dict() -> Dict[str, DependencyModule]: deps: Dict[str, DependencyModule] = dict() - for module in _get_all_deps(): + for module in get_all_deps(): deps[module.key] = module for alias in module.aliases: deps[alias] = module @@ -47,7 +47,7 @@ def get_deps_dict() -> Dict[str, DependencyModule]: return deps -def _get_all_deps() -> List[DependencyModule]: +def get_all_deps() -> List[DependencyModule]: return [ Rust(key="rust"), GolangModule(key="golang"), diff --git a/multiversx_sdk_cli/tests/test_cli_deps.py b/multiversx_sdk_cli/tests/test_cli_deps.py index 0f06bdab..c0191081 100644 --- a/multiversx_sdk_cli/tests/test_cli_deps.py +++ b/multiversx_sdk_cli/tests/test_cli_deps.py @@ -51,3 +51,9 @@ def test_deps_install_testwallets(): def test_deps_check_testwallets(): return_code = main(["deps", "check", "testwallets"]) assert return_code == 0 + + +@pytest.mark.skip_on_windows +def test_deps_install_all(): + return_code = main(["deps", "install", "all"]) + assert return_code == 0 From 3306bc1f15784b68ea72f848827c06e1f9c1327b Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Fri, 5 Jan 2024 18:58:40 +0200 Subject: [PATCH 2/7] fix deps check all and remove latest tags --- multiversx_sdk_cli/cli_deps.py | 33 +++++++++----- multiversx_sdk_cli/config.py | 43 ++----------------- multiversx_sdk_cli/dependencies/modules.py | 24 +---------- multiversx_sdk_cli/errors.py | 16 +++++-- .../report/features/twiggy_paths_check.py | 2 +- multiversx_sdk_cli/tests/test_cli_deps.py | 6 +++ multiversx_sdk_cli/tests/test_modules.py | 25 ----------- multiversx_sdk_cli/utils.py | 21 --------- 8 files changed, 48 insertions(+), 122 deletions(-) delete mode 100644 multiversx_sdk_cli/tests/test_modules.py diff --git a/multiversx_sdk_cli/cli_deps.py b/multiversx_sdk_cli/cli_deps.py index f03e997f..08c75622 100644 --- a/multiversx_sdk_cli/cli_deps.py +++ b/multiversx_sdk_cli/cli_deps.py @@ -1,5 +1,5 @@ import logging -from typing import Any +from typing import Any, List, Tuple from multiversx_sdk_cli import cli_shared, config, dependencies, errors from multiversx_sdk_cli.dependencies.install import get_deps_dict @@ -35,26 +35,39 @@ def install(args: Any): def check(args: Any): name: str = args.name + if name == "all": all_dependencies = dependencies.get_all_deps() + missing_dependencies: List[Tuple[str, str]] = [] for dependency in all_dependencies: - check_module_is_installed(dependency) + tag_to_check: str = config.get_dependency_tag(dependency.key) + is_installed = check_module_is_installed(dependency, tag_to_check) + + if not is_installed: + missing_dependencies.append((dependency.key, tag_to_check)) + + if len(missing_dependencies): + raise errors.DependenciesMissing(missing_dependencies) + return + else: module = dependencies.get_module_by_key(name) - check_module_is_installed(module) + tag_to_check: str = config.get_dependency_tag(module.key) + is_installed = check_module_is_installed(module, tag_to_check) + if is_installed: + logger.info(f"[{module.key} {tag_to_check}] is installed.") + return -def check_module_is_installed(module: DependencyModule) -> None: - tag_to_check: str = config.get_dependency_tag(module.key) + raise errors.DependencyMissing(module.key, tag_to_check) + + +def check_module_is_installed(module: DependencyModule, tag_to_check: str) -> bool: resolution: str = config.get_dependency_resolution(module.key) resolution = resolution if resolution else "HOST" logger.info(f"Checking dependency: module = {module.key}, tag = {tag_to_check}, resolution = {resolution}") installed = module.is_installed(tag_to_check) - if installed: - logger.info(f"[{module.key} {tag_to_check}] is installed.") - return - - raise errors.DependencyMissing(module.key, tag_to_check) + return installed diff --git a/multiversx_sdk_cli/config.py b/multiversx_sdk_cli/config.py index f518664d..b5b65054 100644 --- a/multiversx_sdk_cli/config.py +++ b/multiversx_sdk_cli/config.py @@ -2,8 +2,6 @@ from pathlib import Path from typing import Any, Dict, List -import semver - from multiversx_sdk_cli import errors, utils from multiversx_sdk_cli.ux import show_warning @@ -146,7 +144,6 @@ def _guard_valid_config_deletion(name: str): def get_defaults() -> Dict[str, Any]: return { "dependencies.vmtools.tag": "v1.4.60", - "dependencies.mx_sdk_rs.tag": "latest", "dependencies.vmtools.urlTemplate.linux": "https://github.com/multiversx/mx-chain-vm-go/archive/{TAG}.tar.gz", "dependencies.vmtools.urlTemplate.osx": "https://github.com/multiversx/mx-chain-vm-go/archive/{TAG}.tar.gz", "dependencies.vmtools.urlTemplate.windows": "https://github.com/multiversx/mx-chain-vm-go/archive/{TAG}.tar.gz", @@ -156,9 +153,9 @@ def get_defaults() -> Dict[str, Any]: "dependencies.golang.urlTemplate.linux": "https://golang.org/dl/{TAG}.linux-amd64.tar.gz", "dependencies.golang.urlTemplate.osx": "https://golang.org/dl/{TAG}.darwin-amd64.tar.gz", "dependencies.golang.urlTemplate.windows": "https://golang.org/dl/{TAG}.windows-amd64.zip", - "dependencies.twiggy.tag": "latest", - "dependencies.sc-meta.tag": "latest", - "dependencies.testwallets.tag": "latest", + "dependencies.twiggy.tag": "", + "dependencies.sc-meta.tag": "", + "dependencies.testwallets.tag": "v1.0.0", "dependencies.testwallets.urlTemplate.linux": "https://github.com/multiversx/mx-sdk-testwallets/archive/{TAG}.tar.gz", "dependencies.testwallets.urlTemplate.osx": "https://github.com/multiversx/mx-sdk-testwallets/archive/{TAG}.tar.gz", "dependencies.testwallets.urlTemplate.windows": "https://github.com/multiversx/mx-sdk-testwallets/archive/{TAG}.tar.gz", @@ -254,42 +251,8 @@ def determine_final_args(argv: List[str], config_args: Dict[str, Any]) -> List[s def get_dependency_directory(key: str, tag: str) -> Path: parent_directory = get_dependency_parent_directory(key) - if tag == 'latest': - if not parent_directory.is_dir(): - return parent_directory / tag - tag = get_latest_semver_from_directory(parent_directory) - return parent_directory / tag def get_dependency_parent_directory(key: str) -> Path: return SDK_PATH / key - - -def get_latest_semver_from_directory(directory: Path) -> str: - subdirs = [subdir.name for subdir in directory.iterdir()] - try: - return get_latest_semver(subdirs) - except IndexError: - raise Exception(f'no versions found in {directory}') - - -def get_latest_semver(versions: List[str]) -> str: - semantic_versions = parse_strings_to_semver(versions) - latest_version = sorted(semantic_versions).pop() - return 'v' + str(latest_version) - - -def parse_strings_to_semver(version_strings: List[str]) -> List[semver.VersionInfo]: - versions = [] - for version_string in version_strings: - try: - # Omit the 'v' prefix of the version string - version_string = version_string[1:] - version = semver.VersionInfo.parse(version_string) - except ValueError: - continue - - versions.append(version) - - return versions diff --git a/multiversx_sdk_cli/dependencies/modules.py b/multiversx_sdk_cli/dependencies/modules.py index 0f2d6af3..59d09741 100644 --- a/multiversx_sdk_cli/dependencies/modules.py +++ b/multiversx_sdk_cli/dependencies/modules.py @@ -26,9 +26,6 @@ def install(self, overwrite: bool) -> None: # We install the default tag tag = config.get_dependency_tag(self.key) - if tag == 'latest': - tag = self.get_latest_release() - logger.info(f"install: key={self.key}, tag={tag}, overwrite={overwrite}") if self._should_skip(tag, overwrite): @@ -60,9 +57,6 @@ def is_installed(self, tag: str) -> bool: def get_env(self) -> Dict[str, str]: raise NotImplementedError() - def get_latest_release(self) -> str: - raise NotImplementedError() - def get_resolution(self) -> DependencyResolution: return get_dependency_resolution(self.key) @@ -135,14 +129,6 @@ def _get_download_url(self, tag: str) -> str: url = url.replace("{TAG}", tag) return url - def get_latest_release(self) -> str: - if self.repo_name is None or self.organisation is None: - raise ValueError(f'{self.key}: repo_name or organisation not specified') - - org_repo = f'{self.organisation}/{self.repo_name}' - tag = utils.query_latest_release_tag(org_repo) - return tag - def _get_archive_path(self, tag: str) -> Path: tools_folder = Path(workstation.get_tools_folder()) archive = tools_folder / f"{self.key}.{tag}.{self.archive_type}" @@ -252,9 +238,6 @@ def get_env(self) -> Dict[str, str]: def get_gopath(self) -> Path: return self.get_parent_directory() / "GOPATH" - def get_latest_release(self) -> str: - raise errors.UnsupportedConfigurationValue("Golang tag must always be explicit, not latest") - class Rust(DependencyModule): def is_installed(self, tag: str) -> bool: @@ -338,7 +321,7 @@ def _install_sc_meta(self): tag = config.get_dependency_tag("sc-meta") args = ["cargo", "install", "multiversx-sc-meta", "--locked"] - if tag != "latest": + if tag != "": args.extend(["--version", tag]) myprocess.run_process(args) @@ -354,7 +337,7 @@ def _install_twiggy(self): tag = config.get_dependency_tag("twiggy") args = ["cargo", "install", "twiggy"] - if tag != "latest": + if tag != "": args.extend(["--version", tag]) myprocess.run_process(args) @@ -383,9 +366,6 @@ def get_directory(self, tag: str) -> Path: def get_env(self) -> Dict[str, str]: return dict(os.environ) - def get_latest_release(self) -> str: - raise errors.UnsupportedConfigurationValue("Rust tag must either be explicit, empty or 'nightly'") - class TestWalletsModule(StandaloneModule): def __init__(self, key: str): diff --git a/multiversx_sdk_cli/errors.py b/multiversx_sdk_cli/errors.py index cd3efb56..139b3c26 100644 --- a/multiversx_sdk_cli/errors.py +++ b/multiversx_sdk_cli/errors.py @@ -1,6 +1,6 @@ from pathlib import Path -from typing import Any, Union +from typing import Any, List, Tuple, Union class KnownError(Exception): @@ -49,6 +49,16 @@ def __init__(self, name: str, tag: str): super().__init__(f"Dependency missing: {name} {tag}") +class DependenciesMissing(KnownError): + def __init__(self, dependencies: List[Tuple[str, str]]): + message = "Dependencies missing: \n" + + for dependency in dependencies: + message += f"{dependency[0]} {dependency[1]}\n" + + super().__init__(message.rstrip("\n")) + + class UnknownDependency(KnownError): def __init__(self, name: str): super().__init__(f"Unknown dependency: {name}") @@ -80,8 +90,8 @@ def __init__(self, action_or_item: str, platform: str): class BuildError(KnownError): - def __init__(self, message, inner=None): - super().__init__(f"Build error: {message}.", inner) + def __init__(self, message: str): + super().__init__(f"Build error: {message}.") class UnknownArgumentFormat(KnownError): diff --git a/multiversx_sdk_cli/projects/report/features/twiggy_paths_check.py b/multiversx_sdk_cli/projects/report/features/twiggy_paths_check.py index 4603e597..8d8cbab3 100644 --- a/multiversx_sdk_cli/projects/report/features/twiggy_paths_check.py +++ b/multiversx_sdk_cli/projects/report/features/twiggy_paths_check.py @@ -1,7 +1,7 @@ import logging from pathlib import Path -from multiversx_sdk_cli import config, dependencies, myprocess, utils +from multiversx_sdk_cli import dependencies, myprocess, utils from multiversx_sdk_cli.errors import BadFile from multiversx_sdk_cli.projects.report.features.report_option import \ ReportFeature diff --git a/multiversx_sdk_cli/tests/test_cli_deps.py b/multiversx_sdk_cli/tests/test_cli_deps.py index c0191081..762e3d24 100644 --- a/multiversx_sdk_cli/tests/test_cli_deps.py +++ b/multiversx_sdk_cli/tests/test_cli_deps.py @@ -57,3 +57,9 @@ def test_deps_check_testwallets(): def test_deps_install_all(): return_code = main(["deps", "install", "all"]) assert return_code == 0 + + +@pytest.mark.skip_on_windows +def test_deps_check_all(): + return_code = main(["deps", "check", "all"]) + assert return_code == 0 diff --git a/multiversx_sdk_cli/tests/test_modules.py b/multiversx_sdk_cli/tests/test_modules.py deleted file mode 100644 index 22bfa200..00000000 --- a/multiversx_sdk_cli/tests/test_modules.py +++ /dev/null @@ -1,25 +0,0 @@ -import pytest -import semver - -from multiversx_sdk_cli.config import get_latest_semver - - -def test_semver_parsing(): - v = semver.VersionInfo.parse('1.2.3') - assert (v.major, v.minor, v.patch) == (1, 2, 3) - - v = semver.VersionInfo.parse('1.2.0-beta.3') - assert (v.major, v.minor, v.patch) == (1, 2, 0) - assert v.prerelease == 'beta.3' - - -def test_semver_sorting(): - versions = ['master', 'development', 'v1.2.3', 'v1.3.19', 'v0.1.1-beta.2'] - latest = get_latest_semver(versions) - assert latest == 'v1.3.19' - - -def test_latest_semver_raises_for_empty_list(): - versions = [] - with pytest.raises(IndexError): - get_latest_semver(versions) diff --git a/multiversx_sdk_cli/utils.py b/multiversx_sdk_cli/utils.py index 4cfbccb9..f2af91ef 100644 --- a/multiversx_sdk_cli/utils.py +++ b/multiversx_sdk_cli/utils.py @@ -218,27 +218,6 @@ def parse_keys(bls_public_keys): return parsed_keys, len(keys) -def query_latest_release_tag(repo: str) -> str: - """ - Queries the Github API to retrieve the latest released tag of the specified - repository. The repository must be of the form 'organisation/project'. - """ - url = f'https://api.github.com/repos/{repo}/releases/latest' - - github_api_token = multiversx_sdk_cli.config.get_value('github_api_token') - headers = dict() - if github_api_token != '': - headers['Authorization'] = f'token {github_api_token}' - - session = requests_cache.CachedSession('mxpy_requests_cache', use_cache_dir=True, cache_control=True) - response = session.get(url, headers=headers) - response.raise_for_status() - - release = response.json() - latest_release_tag: str = release['tag_name'] - return latest_release_tag - - def log_explorer(chain: str, name: str, path: str, details: str): networks = { "1": ("MultiversX Mainnet Explorer", "https://explorer.multiversx.com"), From fca22c99cc0c00197b3d016c1f96b95009865c67 Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Mon, 8 Jan 2024 14:43:59 +0200 Subject: [PATCH 3/7] fix check of Rust version --- multiversx_sdk_cli/cli_deps.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/multiversx_sdk_cli/cli_deps.py b/multiversx_sdk_cli/cli_deps.py index 08c75622..17929353 100644 --- a/multiversx_sdk_cli/cli_deps.py +++ b/multiversx_sdk_cli/cli_deps.py @@ -4,6 +4,7 @@ from multiversx_sdk_cli import cli_shared, config, dependencies, errors from multiversx_sdk_cli.dependencies.install import get_deps_dict from multiversx_sdk_cli.dependencies.modules import DependencyModule +from multiversx_sdk_cli.myprocess import run_process logger = logging.getLogger("cli.deps") @@ -50,7 +51,25 @@ def check(args: Any): if len(missing_dependencies): raise errors.DependenciesMissing(missing_dependencies) return + if name == "rust": + module = dependencies.get_module_by_key(name) + tag_to_check: str = config.get_dependency_tag(module.key) + + is_installed = check_module_is_installed(module, tag_to_check) + if is_installed: + actual_rust = _get_actual_installed_rust_version() + + if tag_to_check in actual_rust: + logger.info(f"[{module.key} {tag_to_check}] is installed.") + return + if "command not found" in actual_rust: + logger.warning("You have installed Rust without using `rustup`.") + return + else: + logger.warning(f"The Rust version you have installed does not match the recommended version.\nInstalled [{actual_rust}], expected [{tag_to_check}].") + return + raise errors.DependencyMissing(module.key, tag_to_check) else: module = dependencies.get_module_by_key(name) tag_to_check: str = config.get_dependency_tag(module.key) @@ -71,3 +90,9 @@ def check_module_is_installed(module: DependencyModule, tag_to_check: str) -> bo installed = module.is_installed(tag_to_check) return installed + + +def _get_actual_installed_rust_version() -> str: + args = ["rustup", "default"] + output = run_process(args, dump_to_stdout=False) + return output.rstrip("\n") From 45375a9065682e215b159d9fc7bcdc13acfd289c Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Tue, 9 Jan 2024 12:10:43 +0200 Subject: [PATCH 4/7] refactoring and fixes --- multiversx_sdk_cli/cli_deps.py | 32 ++-------------------- multiversx_sdk_cli/dependencies/modules.py | 23 ++++++++++++++-- 2 files changed, 23 insertions(+), 32 deletions(-) diff --git a/multiversx_sdk_cli/cli_deps.py b/multiversx_sdk_cli/cli_deps.py index 17929353..bf93c8e0 100644 --- a/multiversx_sdk_cli/cli_deps.py +++ b/multiversx_sdk_cli/cli_deps.py @@ -4,7 +4,6 @@ from multiversx_sdk_cli import cli_shared, config, dependencies, errors from multiversx_sdk_cli.dependencies.install import get_deps_dict from multiversx_sdk_cli.dependencies.modules import DependencyModule -from multiversx_sdk_cli.myprocess import run_process logger = logging.getLogger("cli.deps") @@ -51,35 +50,16 @@ def check(args: Any): if len(missing_dependencies): raise errors.DependenciesMissing(missing_dependencies) return - if name == "rust": - module = dependencies.get_module_by_key(name) - tag_to_check: str = config.get_dependency_tag(module.key) - - is_installed = check_module_is_installed(module, tag_to_check) - if is_installed: - actual_rust = _get_actual_installed_rust_version() - - if tag_to_check in actual_rust: - logger.info(f"[{module.key} {tag_to_check}] is installed.") - return - if "command not found" in actual_rust: - logger.warning("You have installed Rust without using `rustup`.") - return - else: - logger.warning(f"The Rust version you have installed does not match the recommended version.\nInstalled [{actual_rust}], expected [{tag_to_check}].") - return - - raise errors.DependencyMissing(module.key, tag_to_check) else: module = dependencies.get_module_by_key(name) tag_to_check: str = config.get_dependency_tag(module.key) is_installed = check_module_is_installed(module, tag_to_check) - if is_installed: + if is_installed and name != "rust": logger.info(f"[{module.key} {tag_to_check}] is installed.") return - - raise errors.DependencyMissing(module.key, tag_to_check) + elif not is_installed: + raise errors.DependencyMissing(module.key, tag_to_check) def check_module_is_installed(module: DependencyModule, tag_to_check: str) -> bool: @@ -90,9 +70,3 @@ def check_module_is_installed(module: DependencyModule, tag_to_check: str) -> bo installed = module.is_installed(tag_to_check) return installed - - -def _get_actual_installed_rust_version() -> str: - args = ["rustup", "default"] - output = run_process(args, dump_to_stdout=False) - return output.rstrip("\n") diff --git a/multiversx_sdk_cli/dependencies/modules.py b/multiversx_sdk_cli/dependencies/modules.py index 59d09741..55a2f2f1 100644 --- a/multiversx_sdk_cli/dependencies/modules.py +++ b/multiversx_sdk_cli/dependencies/modules.py @@ -253,7 +253,24 @@ def is_installed(self, tag: str) -> bool: logger.info(f"which twiggy: {which_twiggy}") dependencies = [which_rustc, which_cargo, which_sc_meta, which_wasm_opt, which_twiggy] - return all(dependency is not None for dependency in dependencies) + installed = all(dependency is not None for dependency in dependencies) + + if installed: + actual_version_installed = self._get_actual_installed_version() + + if tag in actual_version_installed: + logger.info(f"[{self.key} {tag}] is installed.") + elif "Command 'rustup' not found" in actual_version_installed: + show_warning("You have installed Rust without using `rustup`.") + else: + show_warning(f"The Rust version you have installed does not match the recommended version.\nInstalled [{actual_version_installed}], expected [{tag}].") + + return installed + + def _get_actual_installed_version(self) -> str: + args = ["rustup", "default"] + output = myprocess.run_process(args, dump_to_stdout=False) + return output.strip() def install(self, overwrite: bool) -> None: self._check_install_env(apply_correction=overwrite) @@ -321,7 +338,7 @@ def _install_sc_meta(self): tag = config.get_dependency_tag("sc-meta") args = ["cargo", "install", "multiversx-sc-meta", "--locked"] - if tag != "": + if tag: args.extend(["--version", tag]) myprocess.run_process(args) @@ -337,7 +354,7 @@ def _install_twiggy(self): tag = config.get_dependency_tag("twiggy") args = ["cargo", "install", "twiggy"] - if tag != "": + if tag: args.extend(["--version", tag]) myprocess.run_process(args) From 57cace9b7d43ea58c9350031519b7b7cf4c47ec9 Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Tue, 9 Jan 2024 14:07:19 +0200 Subject: [PATCH 5/7] change if statement to check if rustup exists --- multiversx_sdk_cli/dependencies/modules.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/multiversx_sdk_cli/dependencies/modules.py b/multiversx_sdk_cli/dependencies/modules.py index 55a2f2f1..f1e4ff6b 100644 --- a/multiversx_sdk_cli/dependencies/modules.py +++ b/multiversx_sdk_cli/dependencies/modules.py @@ -260,7 +260,7 @@ def is_installed(self, tag: str) -> bool: if tag in actual_version_installed: logger.info(f"[{self.key} {tag}] is installed.") - elif "Command 'rustup' not found" in actual_version_installed: + elif "not found" in actual_version_installed: show_warning("You have installed Rust without using `rustup`.") else: show_warning(f"The Rust version you have installed does not match the recommended version.\nInstalled [{actual_version_installed}], expected [{tag}].") From 11f0f0d155737622dd4be469f67ea9d95627caf6 Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Wed, 17 Jan 2024 14:55:50 +0200 Subject: [PATCH 6/7] source cargo after installing rust --- multiversx_sdk_cli/dependencies/modules.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/multiversx_sdk_cli/dependencies/modules.py b/multiversx_sdk_cli/dependencies/modules.py index f1e4ff6b..7e814dad 100644 --- a/multiversx_sdk_cli/dependencies/modules.py +++ b/multiversx_sdk_cli/dependencies/modules.py @@ -333,6 +333,9 @@ def _install_rust(self, tag: str) -> None: logger.info("Installing rust.") myprocess.run_process(args) + args = ["source", "~/.cargo/env"] + myprocess.run_process(args) + def _install_sc_meta(self): logger.info("Installing multiversx-sc-meta.") tag = config.get_dependency_tag("sc-meta") From 1ece80adfc2485fc8ef31091620d76e4b2db60d5 Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Wed, 17 Jan 2024 15:24:23 +0200 Subject: [PATCH 7/7] add cargo in env --- multiversx_sdk_cli/dependencies/modules.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/multiversx_sdk_cli/dependencies/modules.py b/multiversx_sdk_cli/dependencies/modules.py index 7e814dad..3f21dbd2 100644 --- a/multiversx_sdk_cli/dependencies/modules.py +++ b/multiversx_sdk_cli/dependencies/modules.py @@ -333,9 +333,6 @@ def _install_rust(self, tag: str) -> None: logger.info("Installing rust.") myprocess.run_process(args) - args = ["source", "~/.cargo/env"] - myprocess.run_process(args) - def _install_sc_meta(self): logger.info("Installing multiversx-sc-meta.") tag = config.get_dependency_tag("sc-meta") @@ -344,13 +341,13 @@ def _install_sc_meta(self): if tag: args.extend(["--version", tag]) - myprocess.run_process(args) + myprocess.run_process(args, env=self.get_cargo_env()) def _install_wasm_opt(self): logger.info("Installing wasm-opt. This may take a while.") tag = config.get_dependency_tag("wasm-opt") args = ["cargo", "install", "wasm-opt", "--version", tag] - myprocess.run_process(args) + myprocess.run_process(args, env=self.get_cargo_env()) def _install_twiggy(self): logger.info("Installing twiggy.") @@ -360,7 +357,7 @@ def _install_twiggy(self): if tag: args.extend(["--version", tag]) - myprocess.run_process(args) + myprocess.run_process(args, env=self.get_cargo_env()) def _get_installer_url(self) -> str: if workstation.is_windows(): @@ -386,6 +383,13 @@ def get_directory(self, tag: str) -> Path: def get_env(self) -> Dict[str, str]: return dict(os.environ) + def get_cargo_env(self) -> Dict[str, str]: + env = self.get_env() + cargo = Path("~/.cargo/bin").expanduser() + path = env["PATH"] + env["PATH"] = f"{str(cargo)}:{path}" + return env + class TestWalletsModule(StandaloneModule): def __init__(self, key: str):