diff --git a/mars-cli/mars_cli.py b/mars-cli/mars_cli.py index 7b85a26..55a01e4 100644 --- a/mars-cli/mars_cli.py +++ b/mars-cli/mars_cli.py @@ -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, @@ -218,6 +223,7 @@ def submit( submit_to_metabolights, investigation_is_root, file_transfer, + output, data_files, ): """Start a submission to the target repositories.""" @@ -250,6 +256,7 @@ def submit( investigation_is_root, urls_dict, file_transfer, + output, data_file_paths, ) except requests.RequestException as err: diff --git a/mars-cli/mars_lib/submit.py b/mars-cli/mars_lib/submit.py index 8d79dee..dc347c9 100644 --- a/mars-cli/mars_lib/submit.py +++ b/mars-cli/mars_lib/submit.py @@ -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: @@ -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: @@ -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( diff --git a/mars-cli/tests/test_ftp_upload.py b/mars-cli/tests/test_ftp_upload.py index 13915ab..a5d1672 100644 --- a/mars-cli/tests/test_ftp_upload.py +++ b/mars-cli/tests/test_ftp_upload.py @@ -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"), + ] + )