|
19 | 19 | from requests import HTTPError |
20 | 20 |
|
21 | 21 | import hermes.commands.init.util.slim_click as sc |
| 22 | +from hermes.commands import marketplace |
22 | 23 | from hermes.commands.base import HermesCommand, HermesPlugin |
23 | 24 | from hermes.commands.init.util import (connect_github, connect_gitlab, |
24 | 25 | connect_zenodo, git_info) |
@@ -58,15 +59,10 @@ class HermesInitFolderInfo: |
58 | 59 | def __init__(self): |
59 | 60 | self.absolute_path: str = "" |
60 | 61 | self.has_git_folder: bool = False |
61 | | - # self.has_multiple_remotes: bool = False |
62 | | - # self.git_remote_url: str = "" |
63 | | - # self.git_base_url: str = "" |
64 | | - # self.used_git_hoster: GitHoster = GitHoster.Empty |
65 | 62 | self.has_hermes_toml: bool = False |
66 | 63 | self.has_gitignore: bool = False |
67 | 64 | self.has_citation_cff: bool = False |
68 | 65 | self.has_readme: bool = False |
69 | | - # self.current_branch: str = "" |
70 | 66 | self.current_dir: str = "" |
71 | 67 | self.dir_list: list[str] = [] |
72 | 68 | self.dir_folders: list[str] = [] |
@@ -180,6 +176,7 @@ def __init__(self, parser: argparse.ArgumentParser): |
180 | 176 | } |
181 | 177 | self.plugin_relevant_commands = ["harvest", "deposit"] |
182 | 178 | self.builtin_plugins: dict[str: HermesPlugin] = get_builtin_plugins(self.plugin_relevant_commands) |
| 179 | + self.selected_plugins: list[marketplace.PluginInfo] = [] |
183 | 180 |
|
184 | 181 | def init_command_parser(self, command_parser: argparse.ArgumentParser) -> None: |
185 | 182 | command_parser.add_argument('--template-branch', nargs=1, default="", |
@@ -217,7 +214,10 @@ def __call__(self, args: argparse.Namespace) -> None: |
217 | 214 | self.test_initialization() |
218 | 215 |
|
219 | 216 | sc.echo(f"Starting to initialize HERMES in {self.folder_info.absolute_path}") |
220 | | - sc.max_steps = 7 |
| 217 | + sc.max_steps = 8 |
| 218 | + |
| 219 | + sc.next_step("Configure HERMES plugins") |
| 220 | + self.choose_plugins() |
221 | 221 |
|
222 | 222 | sc.next_step("Configure deposition platform and setup method") |
223 | 223 | self.choose_deposit_platform() |
@@ -595,6 +595,38 @@ def connect_deposit_platform(self) -> None: |
595 | 595 | connect_zenodo.setup(using_sandbox=True) |
596 | 596 | self.create_zenodo_token() |
597 | 597 |
|
| 598 | + def choose_plugins(self): |
| 599 | + """User chooses the plugins he wants to use.""" |
| 600 | + plugin_infos: list[marketplace.PluginInfo] = marketplace.get_plugin_infos() |
| 601 | + plugins_builtin: list[marketplace.PluginInfo] = list(filter(lambda p: p.builtin, plugin_infos)) |
| 602 | + plugins_available: list[marketplace.PluginInfo] = list(filter(lambda p: not p.builtin, plugin_infos)) |
| 603 | + plugins_selected: list[marketplace.PluginInfo] = [] |
| 604 | + sc.echo("The following plugins are already builtin:") |
| 605 | + for info in plugins_builtin: |
| 606 | + sc.echo(str(info), formatting=sc.Formats.OKGREEN) |
| 607 | + sc.echo("") |
| 608 | + while True: |
| 609 | + if plugins_selected: |
| 610 | + sc.echo("The following plugins are going to be installed:") |
| 611 | + for info in plugins_selected: |
| 612 | + sc.echo(str(info), formatting=sc.Formats.OKCYAN) |
| 613 | + sc.echo("") |
| 614 | + if plugins_available: |
| 615 | + sc.echo("The following plugins are available for installation:") |
| 616 | + for info in plugins_available: |
| 617 | + sc.echo(str(info), formatting=sc.Formats.WARNING, no_log=True) |
| 618 | + sc.echo("") |
| 619 | + else: |
| 620 | + self.selected_plugins = plugins_selected |
| 621 | + break |
| 622 | + choice = sc.choose("Do you want to add a plugin?", ["No"] + [p.name for p in plugins_available]) |
| 623 | + if choice == 0: |
| 624 | + self.selected_plugins = plugins_selected |
| 625 | + break |
| 626 | + else: |
| 627 | + chosen_plugin = plugins_available.pop(choice - 1) |
| 628 | + plugins_selected.append(chosen_plugin) |
| 629 | + |
598 | 630 | def no_git_setup(self, start_question: str = "") -> None: |
599 | 631 | """Makes the init for a gitless project (basically just creating hermes.toml)""" |
600 | 632 | if start_question == "": |
|
0 commit comments