Skip to content
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

Throw error if Rust is not installed for contract operations: new, build, clean #376

Merged
merged 2 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ jobs:
shell: bash
run: |
python3 -m multiversx_sdk_cli.cli deps install testwallets
python3 -m multiversx_sdk_cli.cli deps install rust
- name: Run unit tests
shell: bash
run: |
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ jobs:
- name: Setup test dependencies
run: |
python3 -m multiversx_sdk_cli.cli deps install testwallets
python3 -m multiversx_sdk_cli.cli deps install rust
- name: Run unit tests
run: |
export PYTHONPATH=.
Expand Down
5 changes: 5 additions & 0 deletions multiversx_sdk_cli/cli_contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
trigger_contract_verification
from multiversx_sdk_cli.contracts import SmartContract, query_contract
from multiversx_sdk_cli.cosign_transaction import cosign_transaction
from multiversx_sdk_cli.dependency_checker import check_if_rust_is_installed
from multiversx_sdk_cli.docker import is_docker_installed, run_docker
from multiversx_sdk_cli.errors import DockerMissingError, NoWalletProvided
from multiversx_sdk_cli.interfaces import IAddress
Expand Down Expand Up @@ -279,11 +280,13 @@ def get_project_paths(args: Any) -> List[Path]:


def clean(args: Any):
check_if_rust_is_installed()
project_path = args.path
projects.clean_project(Path(project_path))


def build(args: Any):
check_if_rust_is_installed()
project_paths = [Path(args.path)]
arg_list = cli_shared.convert_args_object_to_args_list(args)

Expand All @@ -292,11 +295,13 @@ def build(args: Any):


def do_report(args: Any):
check_if_rust_is_installed()
args_dict = args.__dict__
projects.do_report(args, args_dict)


def run_tests(args: Any):
check_if_rust_is_installed()
project_paths = get_project_paths(args)
for project in project_paths:
projects.run_tests(project, args)
Expand Down
11 changes: 11 additions & 0 deletions multiversx_sdk_cli/dependency_checker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from multiversx_sdk_cli import config, errors, ux
from multiversx_sdk_cli.dependencies.modules import Rust


def check_if_rust_is_installed():
RUST_MODULE_KEY = "rust"
rust_module = Rust(RUST_MODULE_KEY)
if not rust_module.is_installed(""):
tag = config.get_dependency_tag(RUST_MODULE_KEY)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If not required, perhaps use "" instead?

ux.show_critical_error("Rust is not installed on your machine. Run `mxpy deps install rust --overwrite` and try again.")
raise errors.DependencyMissing(RUST_MODULE_KEY, tag)
4 changes: 2 additions & 2 deletions multiversx_sdk_cli/projects/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import List, Union

from multiversx_sdk_cli import myprocess
from multiversx_sdk_cli.dependencies.install import install_module
from multiversx_sdk_cli.dependency_checker import check_if_rust_is_installed

logger = logging.getLogger("projects.templates")

Expand Down Expand Up @@ -33,7 +33,7 @@ def create_from_template(self) -> None:

def _ensure_dependencies_installed(self):
logger.info("Checking if the necessarry dependencies are installed.")
install_module("rust")
check_if_rust_is_installed()

def _prepare_args_to_list_templates(self) -> List[str]:
args = ["sc-meta", "templates"]
Expand Down
Loading