-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Install rust globally #331
Changes from 4 commits
a5b0c84
7250ffa
69fba5e
0bb5667
5295378
2845d07
6906afa
cad2cbd
47c897e
7ef887f
6c22bac
e9542fe
67defe7
45e9698
362cb9b
edb1c59
0c9aaa9
d7681dd
87df9d4
84ce195
b3c6a0c
3cbff95
c597e34
485bfaf
d5999e9
837b794
39f1b77
177d263
648cb4c
340e5e1
fc8609a
8eea743
ad585ea
851bd30
d2af8f5
d8bb7a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
myprocess, utils, workstation) | ||
from multiversx_sdk_cli.dependencies.resolution import ( | ||
DependencyResolution, get_dependency_resolution) | ||
from multiversx_sdk_cli.ux import show_warning | ||
|
||
logger = logging.getLogger("modules") | ||
|
||
|
@@ -34,7 +35,6 @@ | |
logger.info("Already exists. Skip install.") | ||
return | ||
|
||
self._guard_cannot_install_on_host() | ||
self.uninstall(tag) | ||
self._do_install(tag) | ||
|
||
|
@@ -66,10 +66,6 @@ | |
def get_resolution(self) -> DependencyResolution: | ||
return get_dependency_resolution(self.key) | ||
|
||
def _guard_cannot_install_on_host(self): | ||
if self.get_resolution() == DependencyResolution.Host: | ||
raise errors.KnownError(f"Installation of {self.key} on the host machine is not supported. Perhaps set 'dependencies.{self.key}.resolution' to 'SDK' in config?") | ||
|
||
|
||
class StandaloneModule(DependencyModule): | ||
def __init__(self, | ||
|
@@ -256,6 +252,29 @@ | |
|
||
|
||
class Rust(DependencyModule): | ||
def is_installed(self, tag: str) -> bool: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've thought about it, but the other modules need the parameter. I think. We can further look into this. |
||
which_rustc = shutil.which("rustc") | ||
which_cargo = shutil.which("cargo") | ||
logger.info(f"which rustc: {which_rustc}") | ||
logger.info(f"which cargo: {which_cargo}") | ||
|
||
return which_rustc is not None and which_cargo is not None | ||
|
||
def install(self, tag: str, overwrite: bool) -> None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed, here we completely override the function |
||
# Fallback to default tag if not provided | ||
tag = tag or config.get_dependency_tag(self.key) | ||
|
||
logger.info(f"install: key={self.key}, tag={tag}, overwrite={overwrite}") | ||
|
||
if overwrite: | ||
logger.info("Overwriting the current rust version...") | ||
elif self._is_installed_and_set_to_nightly(): | ||
return | ||
|
||
self._do_install(tag) | ||
self._install_sc_meta() | ||
self._post_install(tag) | ||
|
||
def _do_install(self, tag: str) -> None: | ||
installer_url = self._get_installer_url() | ||
installer_path = self._get_installer_path() | ||
|
@@ -273,6 +292,11 @@ | |
|
||
myprocess.run_process(args) | ||
|
||
def _install_sc_meta(self): | ||
logger.info("Installing multiversx-sc-meta") | ||
args = ["cargo", "install", "multiversx-sc-meta"] | ||
myprocess.run_process(args) | ||
|
||
def _get_installer_url(self) -> str: | ||
if workstation.is_windows(): | ||
return "https://win.rustup.rs" | ||
|
@@ -290,13 +314,20 @@ | |
if os.path.isdir(directory): | ||
shutil.rmtree(directory) | ||
|
||
def is_installed(self, tag: str) -> bool: | ||
which_rustc = shutil.which("rustc") | ||
which_cargo = shutil.which("cargo") | ||
logger.info(f"which rustc: {which_rustc}") | ||
logger.info(f"which cargo: {which_cargo}") | ||
def _is_installed_and_set_to_nightly(self) -> bool: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function seems to be a clone of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed. Removed it. |
||
# the method parameter is not used in this specific module | ||
is_rust_installed = self.is_installed("") | ||
|
||
return which_rustc is not None and which_cargo is not None | ||
if not is_rust_installed: | ||
return is_rust_installed | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can say |
||
else: | ||
self._recommend_default_rust_version() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, let's move this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Additionally, you can directly inline the implementation of Can also stay as it is. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved it inside the |
||
return True | ||
|
||
def _recommend_default_rust_version(self): | ||
module = dependencies.get_module_by_key("rust") | ||
default_tag: str = config.get_dependency_tag(module.key) | ||
Check warning on line 329 in multiversx_sdk_cli/dependencies/modules.py GitHub Actions / runner / mypy
|
||
show_warning(f"We recommend using rust {default_tag}. If you'd like to overwrite your current version please run `mxpy deps install rust --overwrite`.") | ||
|
||
def get_directory(self, tag: str) -> Path: | ||
tools_folder = workstation.get_tools_folder() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import shutil | ||
|
||
import pytest | ||
|
||
from multiversx_sdk_cli.cli import main | ||
from multiversx_sdk_cli.config import get_dependency_tag | ||
|
||
|
||
def test_deps_install_rust(): | ||
default_tag = get_dependency_tag("rust") | ||
return_code = main(["deps", "install", "rust", "--tag", default_tag, "--overwrite"]) | ||
if return_code: | ||
assert False | ||
else: | ||
assert True | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can be Also, maybe do an assert for existence of some files in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
|
||
|
||
@pytest.mark.skip_on_windows | ||
def test_deps_install_vmtools(): | ||
return_code = main(["deps", "install", "vmtools"]) | ||
if return_code: | ||
assert False | ||
else: | ||
assert True | ||
|
||
|
||
def test_deps_check_rust(): | ||
return_code = main(["deps", "check", "rust"]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This unit test can be merged into the first one, |
||
if return_code: | ||
assert False | ||
else: | ||
assert True | ||
|
||
|
||
@pytest.mark.skip_on_windows | ||
def test_check_sc_meta(): | ||
which_sc_meta = shutil.which("sc-meta") | ||
if which_sc_meta: | ||
assert True | ||
elif which_sc_meta is None: | ||
assert False | ||
|
||
|
||
@pytest.mark.skip_on_windows | ||
def test_deps_check_vmtools(): | ||
return_code = main(["deps", "check", "vmtools"]) | ||
if return_code: | ||
assert False | ||
else: | ||
assert True | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unit test can be merged into the other one, which installs |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some unrelated whitespace changes in this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll blame it on the formatter.