Skip to content

Commit 1f55229

Browse files
committed
More documentation
1 parent e164bbd commit 1f55229

2 files changed

Lines changed: 33 additions & 29 deletions

File tree

src/hermes/commands/init/base.py

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def get_git_hoster_from_url(url: str) -> GitHoster:
109109
return GitHoster.Empty
110110

111111

112-
def download_file_from_url(url, filepath, append: bool = False):
112+
def download_file_from_url(url, filepath, append: bool = False) -> None:
113113
try:
114114
with requests.get(url, stream=True) as r:
115115
r.raise_for_status()
@@ -126,6 +126,7 @@ def string_in_file(file_path, search_string: str) -> bool:
126126

127127

128128
def get_builtin_plugins(plugin_commands: list[str]) -> dict[str: HermesPlugin]:
129+
"""Returns a list of installed HermesPlugins based on a list of related command names."""
129130
plugins = {}
130131
for plugin_command_name in plugin_commands:
131132
entry_point_group = f"hermes.{plugin_command_name}"
@@ -187,12 +188,13 @@ def init_command_parser(self, command_parser: argparse.ArgumentParser) -> None:
187188
def load_settings(self, args: argparse.Namespace):
188189
pass
189190

190-
def refresh_folder_info(self):
191+
def refresh_folder_info(self) -> None:
192+
"""Checks the contents of the current directory and saves relevant info in self.folder_info"""
191193
sc.debug_info("Scanning folder...")
192194
self.folder_info = scout_current_folder()
193195
sc.debug_info("Scan complete.")
194196

195-
def setup_file_logging(self):
197+
def setup_file_logging(self) -> None:
196198
# Silence old StreamHandler
197199
handler = get_handler_by_name("terminal")
198200
if handler:
@@ -243,7 +245,7 @@ def __call__(self, args: argparse.Namespace) -> None:
243245

244246
sc.echo("\nHERMES is now initialized and ready to be used.\n", formatting=sc.Formats.OKGREEN+sc.Formats.BOLD)
245247

246-
def test_initialization(self):
248+
def test_initialization(self) -> None:
247249
"""Test if init is possible and wanted. If not: sys.exit()"""
248250
# Abort if git is not installed
249251
if not git_info.is_git_installed():
@@ -300,7 +302,7 @@ def test_initialization(self):
300302
"(Hermes config files and related project variables will be overwritten.) "):
301303
sys.exit()
302304

303-
def create_hermes_toml(self):
305+
def create_hermes_toml(self) -> None:
304306
"""Creates the hermes.toml file based on a dictionary"""
305307
deposit_url = DepositPlatformUrls.get(self.deposit_platform)
306308
default_values = {
@@ -323,7 +325,7 @@ def create_hermes_toml(self):
323325
toml.dump(default_values, toml_file)
324326
sc.echo("`hermes.toml` was created.", formatting=sc.Formats.OKGREEN)
325327

326-
def create_citation_cff(self):
328+
def create_citation_cff(self) -> None:
327329
"""If there is no CITATION.cff, the user gets the opportunity to create one online."""
328330
if not self.folder_info.has_citation_cff:
329331
citation_cff_url = "https://citation-file-format.github.io/cff-initializer-javascript/#/"
@@ -347,7 +349,7 @@ def create_citation_cff(self):
347349
else:
348350
sc.echo("Your project already contains a `CITATION.cff` file. Nice!", formatting=sc.Formats.OKGREEN)
349351

350-
def update_gitignore(self):
352+
def update_gitignore(self) -> None:
351353
"""Creates .gitignore if there is none and adds '.hermes' to it"""
352354
if not self.folder_info.has_gitignore:
353355
open(".gitignore", 'w')
@@ -366,11 +368,12 @@ def update_gitignore(self):
366368
sc.echo("Added `.hermes/` to the `.gitignore` file.", formatting=sc.Formats.OKGREEN)
367369

368370
def get_template_url(self, filename: str) -> str:
371+
"""Returns the full template url with a given filename."""
369372
return (f"{self.template_base_url}/{self.template_repo}/refs/heads/"
370373
f"{self.template_branch}/{self.template_folder}/{filename}")
371374

372-
def create_ci_template(self):
373-
"""Downloads and configures the ci workflow files using templates from the chosen template branch"""
375+
def create_ci_template(self) -> None:
376+
"""Downloads and configures the ci workflow files using templates from the chosen template branch."""
374377
match self.git_hoster:
375378
case GitHoster.GitHub:
376379
# TODO Replace this later with the link to the real templates (not the feature branch)
@@ -411,7 +414,7 @@ def create_ci_template(self):
411414

412415
sc.echo(f"GitLab CI: {hermes_ci_path} was created.", formatting=sc.Formats.OKGREEN)
413416

414-
def configure_ci_template(self, ci_file_path):
417+
def configure_ci_template(self, ci_file_path) -> None:
415418
"""Replaces all {%parameter%} in a ci file with values from ci_parameters dict"""
416419
with open(ci_file_path, 'r') as file:
417420
content = file.read()
@@ -425,7 +428,8 @@ def configure_ci_template(self, ci_file_path):
425428
with open(ci_file_path, 'w') as file:
426429
file.write(content)
427430

428-
def get_zenodo_token(self):
431+
def create_zenodo_token(self) -> None:
432+
"""Makes the user create a zenodo token and saves it in self.tokens."""
429433
self.tokens[self.deposit_platform] = ""
430434
# Deactivated Zenodo OAuth as long as the refresh token bug is not fixed.
431435
if self.setup_method == "a":
@@ -453,15 +457,15 @@ def get_zenodo_token(self):
453457
"(If this error persists, you should try switching to the manual setup mode.)",
454458
formatting=sc.Formats.WARNING)
455459

456-
def configure_git_project(self):
457-
"""Adding the token to the git secrets & changing action workflow settings"""
460+
def configure_git_project(self) -> None:
461+
"""Adds the token to the git secrets & changes action workflow settings."""
458462
match self.git_hoster:
459463
case GitHoster.GitHub:
460464
self.configure_github()
461465
case GitHoster.GitLab:
462466
self.configure_gitlab()
463467

464-
def configure_github(self):
468+
def configure_github(self) -> None:
465469
oauth_success = False
466470
if self.setup_method == "a":
467471
self.tokens[GitHoster.GitHub] = connect_github.get_access_token()
@@ -495,7 +499,7 @@ def configure_github(self):
495499
sc.echo("Allow GitHub Actions to create and approve pull requests")
496500
sc.press_enter_to_continue()
497501

498-
def configure_gitlab(self):
502+
def configure_gitlab(self) -> None:
499503
# Doing it with API / OAuth
500504
oauth_success = False
501505
if self.setup_method == "a":
@@ -552,15 +556,16 @@ def configure_gitlab(self):
552556
sc.echo("(For your safety, you should set the visibility to 'Masked'.)")
553557
sc.press_enter_to_continue()
554558

555-
def choose_deposit_platform(self):
556-
"""User chooses his desired deposit platform"""
559+
def choose_deposit_platform(self) -> None:
560+
"""User chooses his desired deposit platform."""
557561
deposit_platform_list = list(DepositPlatformNames.keys())
558562
deposit_platform_index = sc.choose(
559563
"Where do you want to publish the software?", [DepositPlatformNames[dp] for dp in deposit_platform_list]
560564
)
561565
self.deposit_platform = deposit_platform_list[deposit_platform_index]
562566

563-
def choose_setup_method(self):
567+
def choose_setup_method(self) -> None:
568+
"""User chooses his desired setup method: Either preferring automatic (if available) or manual."""
564569
setup_method_index = sc.choose(
565570
f"How do you want to connect {DepositPlatformNames[self.deposit_platform]} "
566571
f"with your {self.git_hoster.name} CI?",
@@ -571,18 +576,18 @@ def choose_setup_method(self):
571576
)
572577
self.setup_method = ["a", "m"][setup_method_index]
573578

574-
def connect_deposit_platform(self):
575-
"""Acquires the access token of the chosen deposit platform"""
579+
def connect_deposit_platform(self) -> None:
580+
"""Acquires the access token of the chosen deposit platform."""
576581
assert self.deposit_platform != DepositPlatform.Empty
577582
match self.deposit_platform:
578583
case DepositPlatform.Zenodo:
579584
connect_zenodo.setup(using_sandbox=False)
580-
self.get_zenodo_token()
585+
self.create_zenodo_token()
581586
case DepositPlatform.ZenodoSandbox:
582587
connect_zenodo.setup(using_sandbox=True)
583-
self.get_zenodo_token()
588+
self.create_zenodo_token()
584589

585-
def no_git_setup(self, start_question: str = ""):
590+
def no_git_setup(self, start_question: str = "") -> None:
586591
"""Makes the init for a gitless project (basically just creating hermes.toml)"""
587592
if start_question == "":
588593
start_question = "Do you want to initialize HERMES anyways? (No CI/CD files will be created)"
@@ -598,8 +603,8 @@ def no_git_setup(self, start_question: str = ""):
598603
sc.echo("\nHERMES is now initialized (without git integration).\n",
599604
formatting=sc.Formats.OKGREEN)
600605

601-
def choose_push_branch(self):
602-
"""User chooses the branch that should be used to activate the whole hermes process"""
606+
def choose_push_branch(self) -> None:
607+
"""User chooses the branch that should be used to activate the whole hermes process."""
603608
push_choice = sc.choose(
604609
"When should the automated HERMES process start?",
605610
[
@@ -613,8 +618,8 @@ def choose_push_branch(self):
613618
sc.echo("Setting up triggering by tags is currently not implemented.", formatting=sc.Formats.WARNING)
614619
sc.echo(f"You can visit {TUTORIAL_URL} to set it up manually later-on.", formatting=sc.Formats.WARNING)
615620

616-
def choose_deposit_files(self):
617-
"""User chooses the files that should be included in the deposition"""
621+
def choose_deposit_files(self) -> None:
622+
"""User chooses the files that should be included in the deposition."""
618623
dp_name = DepositPlatformNames[self.deposit_platform]
619624
add_readme = False
620625
if self.folder_info.has_readme:

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def get_remotes() -> list[str]:
6363

6464
def convert_remote_url(url: str) -> str:
6565
"""
66-
Takes any url produced by 'git remote get-url ...' and returns a consistent version with https & without .git
66+
Takes any url produced by 'git remote get-url ...' and returns a consistent version with https & without '.git'.
6767
"""
6868
url = url.strip()
6969
# Remove .git from the end of the url
@@ -87,7 +87,6 @@ def get_remote_url(remote: str) -> str:
8787
def get_current_branch() -> str:
8888
"""
8989
Returns the name of the current branch.
90-
:return:
9190
"""
9291
branch_info = run_git_command("branch")
9392
for line in branch_info.splitlines():

0 commit comments

Comments
 (0)