Skip to content

Commit ba58c6c

Browse files
committed
Add output option
1 parent becc5b2 commit ba58c6c

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

mars-cli/mars_cli.py

+7
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,11 @@ def cli(ctx, development):
206206
type=click.BOOL,
207207
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.",
208208
)
209+
@click.option(
210+
"--output",
211+
type=click.STRING,
212+
default=f"output_{datetime.now().strftime('%Y-%m-%dT%H:%M:%S')}",
213+
)
209214
@click.pass_context
210215
def submit(
211216
ctx,
@@ -218,6 +223,7 @@ def submit(
218223
submit_to_metabolights,
219224
investigation_is_root,
220225
file_transfer,
226+
output,
221227
data_files,
222228
):
223229
"""Start a submission to the target repositories."""
@@ -250,6 +256,7 @@ def submit(
250256
investigation_is_root,
251257
urls_dict,
252258
file_transfer,
259+
output,
253260
data_file_paths,
254261
)
255262
except requests.RequestException as err:

mars-cli/mars_lib/submit.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131

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

3636
with open(f"{dir_path}/{filename}.json", "w") as f:
@@ -49,8 +49,9 @@ def submission(
4949
investigation_is_root: bool,
5050
urls: dict[str, Any],
5151
file_transfer: str,
52+
output: str,
5253
data_file_paths=None,
53-
):
54+
) -> None:
5455
# If credential manager info found:
5556
# Get password from the credential manager
5657
# Else:
@@ -150,8 +151,9 @@ def submission(
150151
)
151152
# TODO: Update `isa_json`, based on the receipt returned
152153

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

156158

157159
def submit_to_biosamples(

mars-cli/tests/test_ftp_upload.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,17 @@ def test_upload_login_failure():
1313
uploader.upload([Path("./tests/fixtures/not_a_json_file.txt")])
1414

1515

16-
@pytest.mark.skip(reason="Relies on real ENA credentials in test_credentials_example.json")
16+
@pytest.mark.skip(
17+
reason="Relies on real ENA credentials in test_credentials_example.json"
18+
)
1719
def test_upload_success():
1820
# For local testing, add ENA username/password to test_credentials_example.json
1921
with open("./tests/test_credentials_example.json") as f:
2022
creds = json.load(f)
2123
uploader = FTPUploader("webin2.ebi.ac.uk", creds["username"], creds["password"])
22-
uploader.upload([Path("../test-data/ENA_TEST2.R1.fastq.gz"), Path("./tests/fixtures/not_a_json_file.txt")])
24+
uploader.upload(
25+
[
26+
Path("../test-data/ENA_TEST2.R1.fastq.gz"),
27+
Path("./tests/fixtures/not_a_json_file.txt"),
28+
]
29+
)

0 commit comments

Comments
 (0)