-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathcli_deps.py
79 lines (57 loc) · 2.73 KB
/
cli_deps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import logging
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
from multiversx_sdk_cli.dependencies.modules import DependencyModule
logger = logging.getLogger("cli.deps")
def setup_parser(subparsers: Any) -> Any:
parser = cli_shared.add_group_subparser(subparsers, "deps", "Manage dependencies or multiversx-sdk modules")
subparsers = parser.add_subparsers()
choices = ["all"] + list(get_deps_dict().keys())
sub = cli_shared.add_command_subparser(
subparsers, "deps", "install", "Install dependencies or multiversx-sdk modules."
)
sub.add_argument("name", choices=choices, help="the dependency to install")
sub.add_argument(
"--overwrite",
action="store_true",
default=False,
help="whether to overwrite an existing installation",
)
sub.set_defaults(func=install)
sub = cli_shared.add_command_subparser(subparsers, "deps", "check", "Check whether a dependency is installed.")
sub.add_argument("name", choices=choices, help="the dependency to check")
sub.set_defaults(func=check)
parser.epilog = cli_shared.build_group_epilog(subparsers)
return subparsers
def install(args: Any):
name: str = args.name
overwrite: bool = args.overwrite
dependencies.install_module(name, overwrite)
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:
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
module = dependencies.get_module_by_key(name)
tag_to_check = 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
elif not is_installed:
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)
return installed