Skip to content

Commit 5b34b14

Browse files
committed
Small fix & cleaned the dialog
1 parent 1f55229 commit 5b34b14

3 files changed

Lines changed: 17 additions & 8 deletions

File tree

src/hermes/commands/init/base.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def __call__(self, args: argparse.Namespace) -> None:
216216
# Test if init is valid in current folder
217217
self.test_initialization()
218218

219-
sc.echo(f"Starting to initialize HERMES in {self.folder_info.absolute_path} ...")
219+
sc.echo(f"Starting to initialize HERMES in {self.folder_info.absolute_path}")
220220
sc.max_steps = 7
221221

222222
sc.next_step("Configure deposition platform and setup method")
@@ -247,6 +247,8 @@ def __call__(self, args: argparse.Namespace) -> None:
247247

248248
def test_initialization(self) -> None:
249249
"""Test if init is possible and wanted. If not: sys.exit()"""
250+
sc.echo("Preparing HERMES initialization\n")
251+
250252
# Abort if git is not installed
251253
if not git_info.is_git_installed():
252254
sc.echo("Git is currently not installed. It is recommended to use HERMES with git.",
@@ -274,20 +276,26 @@ def test_initialization(self) -> None:
274276
if len(remotes) > 1:
275277
remote_index = sc.choose(
276278
"Your git project has multiple remotes. For which remote do you want to setup HERMES?",
277-
remotes
279+
[f"{remote} ({git_info.get_remote_url(remote)})" for remote in remotes]
278280
)
279281
self.git_remote = remotes[remote_index]
280282

281283
# Get url & hoster from remote
282284
if self.git_remote:
283285
self.git_remote_url = git_info.get_remote_url(self.git_remote)
284286
self.git_hoster = get_git_hoster_from_url(self.git_remote_url)
287+
# Abort with no remote
288+
else:
289+
sc.echo("Your git project does not have a remote. It is recommended for HERMES to "
290+
"use either GitHub or GitLab as hosting service.", formatting=sc.Formats.WARNING)
291+
self.no_git_setup()
292+
sys.exit()
285293

286294
# Abort if neither GitHub nor gitlab is used
287295
if self.git_hoster == GitHoster.Empty:
288296
project_url = " (" + self.git_remote_url + ")" if self.git_remote_url else ""
289297
sc.echo("Your git project{} is not connected to GitHub or GitLab. It is recommended for HERMES to "
290-
"use one of those hosting services.".format(project_url),
298+
"use one of these hosting services.".format(project_url),
291299
formatting=sc.Formats.WARNING)
292300
self.no_git_setup()
293301
sys.exit()
@@ -590,7 +598,8 @@ def connect_deposit_platform(self) -> None:
590598
def no_git_setup(self, start_question: str = "") -> None:
591599
"""Makes the init for a gitless project (basically just creating hermes.toml)"""
592600
if start_question == "":
593-
start_question = "Do you want to initialize HERMES anyways? (No CI/CD files will be created)"
601+
start_question = ("Do you want to initialize HERMES anyways? (CI/CD files for automated publishing will "
602+
"NOT be created)")
594603
if sc.confirm(start_question):
595604
sc.max_steps = 2
596605

@@ -600,7 +609,7 @@ def no_git_setup(self, start_question: str = "") -> None:
600609
sc.next_step("Create CITATION.cff file")
601610
self.create_citation_cff()
602611

603-
sc.echo("\nHERMES is now initialized (without git integration).\n",
612+
sc.echo("\nHERMES is now initialized (without git integration or CI/CD files).\n",
604613
formatting=sc.Formats.OKGREEN)
605614

606615
def choose_push_branch(self) -> None:

src/hermes/commands/init/util/git_info.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def get_remotes() -> list[str]:
5656
"""
5757
Returns a list of all remotes.
5858
"""
59-
git_remote_output: str = run_git_command("remote")
59+
git_remote_output: str = run_git_command("remote").strip()
6060
cleaned_remote_list = [s.strip() for s in git_remote_output.split("\n")]
6161
return cleaned_remote_list
6262

@@ -100,7 +100,7 @@ def is_git_installed() -> bool:
100100
Uses the --version command to check whether git is installed.
101101
"""
102102
try:
103-
result = subprocess.run(['git', '--version'])
103+
result = subprocess.run(['git', '--version'], capture_output=True)
104104
return result.returncode == 0
105105
except Exception:
106106
return False

src/hermes/commands/init/util/slim_click.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def confirm(text: str, default: bool = True) -> bool:
101101
print("")
102102
return False
103103
elif _answer == "":
104-
print("Y\n" if default else "N\n")
104+
echo("Y\n" if default else "N\n", formatting=Formats.OKCYAN)
105105
return default
106106
else:
107107
echo("Error: invalid input", formatting=Formats.FAIL)

0 commit comments

Comments
 (0)