Skip to content

Commit

Permalink
Add output option
Browse files Browse the repository at this point in the history
  • Loading branch information
kdp-cloud committed Nov 7, 2024
1 parent becc5b2 commit ba58c6c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
7 changes: 7 additions & 0 deletions mars-cli/mars_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ def cli(ctx, development):
type=click.BOOL,
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.",
)
@click.option(
"--output",
type=click.STRING,
default=f"output_{datetime.now().strftime('%Y-%m-%dT%H:%M:%S')}",
)
@click.pass_context
def submit(
ctx,
Expand All @@ -218,6 +223,7 @@ def submit(
submit_to_metabolights,
investigation_is_root,
file_transfer,
output,
data_files,
):
"""Start a submission to the target repositories."""
Expand Down Expand Up @@ -250,6 +256,7 @@ def submit(
investigation_is_root,
urls_dict,
file_transfer,
output,
data_file_paths,
)
except requests.RequestException as err:
Expand Down
10 changes: 6 additions & 4 deletions mars-cli/mars_lib/submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@


def save_step_to_file(time_stamp: float, filename: str, isa_json: IsaJson):
dir_path = f"tmp/{str(time_stamp)}"
dir_path = f"tmp/{datetime.now().strftime('%Y-%m-%dT%H:%M:%S')}"
os.makedirs(dir_path, exist_ok=True)

with open(f"{dir_path}/{filename}.json", "w") as f:
Expand All @@ -49,8 +49,9 @@ def submission(
investigation_is_root: bool,
urls: dict[str, Any],
file_transfer: str,
output: str,
data_file_paths=None,
):
) -> None:
# If credential manager info found:
# Get password from the credential manager
# Else:
Expand Down Expand Up @@ -150,8 +151,9 @@ def submission(
)
# TODO: Update `isa_json`, based on the receipt returned

# TODO: Return the updated ISA JSON
return isa_json
# Return the updated ISA JSON
with open(f"{output}.json", "w") as f:
f.write(isa_json.model_dump_json(by_alias=True, exclude_none=True))


def submit_to_biosamples(
Expand Down
11 changes: 9 additions & 2 deletions mars-cli/tests/test_ftp_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,17 @@ def test_upload_login_failure():
uploader.upload([Path("./tests/fixtures/not_a_json_file.txt")])


@pytest.mark.skip(reason="Relies on real ENA credentials in test_credentials_example.json")
@pytest.mark.skip(
reason="Relies on real ENA credentials in test_credentials_example.json"
)
def test_upload_success():
# For local testing, add ENA username/password to test_credentials_example.json
with open("./tests/test_credentials_example.json") as f:
creds = json.load(f)
uploader = FTPUploader("webin2.ebi.ac.uk", creds["username"], creds["password"])
uploader.upload([Path("../test-data/ENA_TEST2.R1.fastq.gz"), Path("./tests/fixtures/not_a_json_file.txt")])
uploader.upload(
[
Path("../test-data/ENA_TEST2.R1.fastq.gz"),
Path("./tests/fixtures/not_a_json_file.txt"),
]
)

0 comments on commit ba58c6c

Please sign in to comment.