Skip to content

Commit 835fa1f

Browse files
committed
Better annotation
1 parent a6591c2 commit 835fa1f

4 files changed

Lines changed: 24 additions & 22 deletions

File tree

mars_cli.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import click
22
from datetime import datetime
33
from mars_lib.target_repo import TargetRepository
4-
from mars_lib.models.isa_json import IsaJson
4+
from mars_lib.models.isa_json import Investigation, IsaJson
55
from mars_lib.submit import submission
66
from mars_lib.credential import CredentialManager
77
from mars_lib.logging import print_and_log, init_logging
@@ -12,6 +12,7 @@
1212
from pathlib import Path
1313
import os
1414
from configparser import ConfigParser
15+
from typing import List
1516

1617
# Load CLI configuration
1718
home_dir = (
@@ -41,7 +42,7 @@
4142
help="Boolean indicating the usage of the development environment of the target repositories. If not present, the production instances will be used.",
4243
)
4344
@click.pass_context
44-
def cli(ctx, development):
45+
def cli(ctx: click.Context, development: bool):
4546
print_and_log("############# Welcome to the MARS CLI. #############")
4647
print_and_log(
4748
"Sensitive information might be dumped in the log files when setting the 'log_level' to DEBUG in the config file. Logging in debug mode should only be used for developing purpose a can implicate security issues if used in a production environment!",
@@ -124,22 +125,22 @@ def cli(ctx, development):
124125
)
125126
@click.pass_context
126127
def submit(
127-
ctx,
128-
webin_username,
129-
metabolights_username,
130-
metabolights_ftp_username,
131-
credentials_file,
132-
isa_json_file,
133-
submit_to_biosamples,
134-
submit_to_ena,
135-
submit_to_metabolights,
136-
investigation_is_root,
137-
file_transfer,
138-
output,
139-
data_files,
128+
ctx: click.Context,
129+
webin_username: str,
130+
metabolights_username: str,
131+
metabolights_ftp_username: str,
132+
credentials_file: click.File,
133+
isa_json_file : click.File,
134+
submit_to_biosamples: bool,
135+
submit_to_ena: bool,
136+
submit_to_metabolights: bool,
137+
investigation_is_root: bool,
138+
file_transfer: str,
139+
output: str,
140+
data_files: List[click.File],
140141
):
141142
"""Start a submission to the target repositories."""
142-
target_repositories = []
143+
target_repositories: List[str] = []
143144

144145
if submit_to_biosamples:
145146
target_repositories.append(TargetRepository.BIOSAMPLES.value)
@@ -175,7 +176,7 @@ def submit(
175176

176177
@cli.command()
177178
@click.pass_context
178-
def health_check(ctx):
179+
def health_check(ctx: click.Context):
179180
"""Check the health of the target repositories."""
180181
print_and_log("Checking the health of the target repositories.")
181182

@@ -218,7 +219,7 @@ def health_check(ctx):
218219
help="Boolean indicating if the investigation is the root of the ISA JSON. Set this to True if the ISA-JSON does not contain a 'investigation' field.",
219220
)
220221
@click.option("--validation-schema", default="{}", type=click.STRING, help="")
221-
def validate_isa_json(isa_json_file, investigation_is_root, validation_schema):
222+
def validate_isa_json(isa_json_file: str, investigation_is_root: bool, validation_schema: str):
222223
"""Validate the ISA JSON file."""
223224
print_and_log(f"Validating {isa_json_file}.")
224225

@@ -227,7 +228,7 @@ def validate_isa_json(isa_json_file, investigation_is_root, validation_schema):
227228
json_data = json.load(f)
228229

229230
if investigation_is_root:
230-
isa_json = IsaJson(investigation=isa_json_file.model_validate(json_data))
231+
isa_json = IsaJson(investigation=Investigation.model_validate(json_data))
231232
else:
232233
isa_json = IsaJson.model_validate(json_data).investigation
233234
validation_schema = json.loads(validation_schema)

mars_lib/ftp_upload.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def __init__(self, ftp_host: str, username: str, password: str):
3030
self.password = password
3131

3232
@retry(exceptions=ftplib.all_errors, tries=3, delay=2, backoff=1.2, jitter=(1, 3))
33-
def upload(self, file_paths: List[Path], target_location: str = "/") -> bool:
33+
def upload(self, file_paths: list[Path], target_location: str = "/") -> bool:
3434
# Heuristic to set the expected timeout assuming 10Mb/s upload speed but no less than 30 sec
3535
# and no more than an hour
3636
max_file_size = max([os.path.getsize(f) for f in file_paths])

mars_lib/logging.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
logger = logging.getLogger("MARS-CLI")
88

99

10-
def print_and_log(msg, level="info"):
10+
def print_and_log(msg: str, level: str = "info"):
1111
if level == "info":
1212
logger.info(msg)
1313
elif level == "warning":

mars_lib/target_repo.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from configparser import ConfigParser
12
from enum import Enum
23

34

@@ -21,7 +22,7 @@ def available_repositories(cls):
2122

2223
@classmethod
2324
def get_repository_urls_from_config(
24-
cls, config
25+
cls, config: ConfigParser
2526
) -> dict[str, dict[str, dict[str, str]]]:
2627
return {
2728
"DEV": {

0 commit comments

Comments
 (0)