From 5e4d2931ea915149f57bd982c30bc1ddecf97c0e Mon Sep 17 00:00:00 2001 From: Stefan Janssen Date: Thu, 13 Nov 2025 23:24:25 +0100 Subject: [PATCH 1/6] after calling a plugin function, push files of artifacts to qiita central --- qiita_client/plugin.py | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/qiita_client/plugin.py b/qiita_client/plugin.py index 4c30bdc..6e7139d 100644 --- a/qiita_client/plugin.py +++ b/qiita_client/plugin.py @@ -100,9 +100,47 @@ def __init__(self, name, description, function, required_parameters, self.outputs = outputs self.analysis_only = analysis_only + def _push_artifacts_files_to_central(qclient, artifacts): + """Pushes all files of a list of artifacts to BASE_DATA_DIR. + + Parameters + ---------- + qclient : qiita_client.QiitaClient + The Qiita server client + artifacts : [ArtifactInfo] + A list of qiita Artifacts + + Returns + ------- + The input list of artifacts + """ + if artifacts is None: + return artifacts + + for artifact in artifacts: + if artifact is not None: + if 'files' in artifact.keys(): + artifact['files'] = { + filetype: [ + { + k: qclient.push_file_to_central(v) + if k == 'filepath' else v + for k, v + in file.items()} + for file + in artifact['files'][filetype]] + for filetype + in artifact['files'].keys() + } + + return artifacts + def __call__(self, qclient, server_url, job_id, output_dir): logger.debug('Entered QiitaCommand.__call__()') - return self.function(qclient, server_url, job_id, output_dir) + status, artifacts, error_message = self.function( + qclient, server_url, job_id, output_dir) + return status, QiitaCommand._push_artifacts_files_to_central( + qclient, artifacts), error_message class QiitaArtifactType(object): From 0d6a453e4420c13cab972e7afa52ebc81d6da958 Mon Sep 17 00:00:00 2001 From: Stefan Janssen Date: Thu, 13 Nov 2025 23:42:25 +0100 Subject: [PATCH 2/6] handle cases where Command function does NOT return typical 3-tuple --- qiita_client/plugin.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/qiita_client/plugin.py b/qiita_client/plugin.py index 6e7139d..7bb0422 100644 --- a/qiita_client/plugin.py +++ b/qiita_client/plugin.py @@ -137,10 +137,17 @@ def _push_artifacts_files_to_central(qclient, artifacts): def __call__(self, qclient, server_url, job_id, output_dir): logger.debug('Entered QiitaCommand.__call__()') - status, artifacts, error_message = self.function( + results = self.function( qclient, server_url, job_id, output_dir) - return status, QiitaCommand._push_artifacts_files_to_central( - qclient, artifacts), error_message + # typical, but not all, functions of QiitaCommands return 3-tuple + # status=bool, list of artifacts, error_message=str + if isinstance(results, tuple) and (len(results) == 3) and \ + isinstance(results[0], bool) and \ + isinstance(results[1], list) and \ + isinstance(results[2], str): + results[1] = QiitaCommand._push_artifacts_files_to_central( + qclient, results[1]) + return results class QiitaArtifactType(object): From b5f9c0e634fd200006eee60a905dec4dade1ace5 Mon Sep 17 00:00:00 2001 From: Stefan Janssen Date: Fri, 14 Nov 2025 10:52:00 +0100 Subject: [PATCH 3/6] adapt push function to list of ArtifactInfos --- qiita_client/plugin.py | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/qiita_client/plugin.py b/qiita_client/plugin.py index 7bb0422..867ea35 100644 --- a/qiita_client/plugin.py +++ b/qiita_client/plugin.py @@ -15,7 +15,7 @@ from future import standard_library from json import dumps import urllib -from qiita_client import QiitaClient +from qiita_client import QiitaClient, ArtifactInfo import logging @@ -118,22 +118,13 @@ def _push_artifacts_files_to_central(qclient, artifacts): return artifacts for artifact in artifacts: - if artifact is not None: - if 'files' in artifact.keys(): - artifact['files'] = { - filetype: [ - { - k: qclient.push_file_to_central(v) - if k == 'filepath' else v - for k, v - in file.items()} - for file - in artifact['files'][filetype]] - for filetype - in artifact['files'].keys() - } - - return artifacts + if isinstance(artifact, ArtifactInfo): + for i in range(len(artifact.files)): + (fp, ftype) = artifact.files[i] + # send file to Qiita central and potentially update + # filepath, which is not done at the moment (2025-11-14) + fp = qclient.push_file_to_central(fp) + artifact.files[i] = (fp, ftype) def __call__(self, qclient, server_url, job_id, output_dir): logger.debug('Entered QiitaCommand.__call__()') From 9cc935a59e5aa4c668f143849791c878789ef050 Mon Sep 17 00:00:00 2001 From: Stefan Janssen Date: Fri, 14 Nov 2025 10:59:45 +0100 Subject: [PATCH 4/6] add tests --- qiita_client/tests/test_plugin.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/qiita_client/tests/test_plugin.py b/qiita_client/tests/test_plugin.py index 43a8eca..d3f11f7 100644 --- a/qiita_client/tests/test_plugin.py +++ b/qiita_client/tests/test_plugin.py @@ -73,6 +73,23 @@ def func(a, b, c, d): self.exp_opt, self.exp_out, self.exp_dflt) self.assertEqual(obs('a', 'b', 'c', 'd'), 42) + def test__push_artifacts_files_to_central(self): + class fakeClient(): + def push_file_to_central(self, fp): + return 'pushed:%s' % fp + + obs = QiitaCommand._push_artifacts_files_to_central( + fakeClient(), [ + ArtifactInfo("stefArtiName", "Atype", [ + ("fp1", "preprocessed_fasta"), + ("fp2", "preprocessed_fastq")]), + None, + ArtifactInfo("artiName", "artiType", [])]) + + self.assertIn('pushed:', obs[0].files[0][0]) + self.assertIn('pushed:', obs[0].files[1][0]) + self.assertEqual([], obs[2].files) + class QiitaArtifactTypeTest(TestCase): def test_init(self): From 4a046cb633b56688fd785a79c81dd14952e27593 Mon Sep 17 00:00:00 2001 From: Stefan Janssen Date: Fri, 14 Nov 2025 11:13:31 +0100 Subject: [PATCH 5/6] cope with no return value --- qiita_client/tests/test_plugin.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/qiita_client/tests/test_plugin.py b/qiita_client/tests/test_plugin.py index d3f11f7..e6d28ae 100644 --- a/qiita_client/tests/test_plugin.py +++ b/qiita_client/tests/test_plugin.py @@ -75,20 +75,20 @@ def func(a, b, c, d): def test__push_artifacts_files_to_central(self): class fakeClient(): - def push_file_to_central(self, fp): - return 'pushed:%s' % fp - - obs = QiitaCommand._push_artifacts_files_to_central( - fakeClient(), [ - ArtifactInfo("stefArtiName", "Atype", [ - ("fp1", "preprocessed_fasta"), - ("fp2", "preprocessed_fastq")]), - None, - ArtifactInfo("artiName", "artiType", [])]) - - self.assertIn('pushed:', obs[0].files[0][0]) - self.assertIn('pushed:', obs[0].files[1][0]) - self.assertEqual([], obs[2].files) + def push_file_to_central(self, filepath): + return 'pushed:%s' % filepath + + artifacts = [ + ArtifactInfo("stefArtiName", "Atype", [ + ("fp1", "preprocessed_fasta"), + ("fp2", "preprocessed_fastq")]), + None, + ArtifactInfo("artiName", "artiType", [])] + QiitaCommand._push_artifacts_files_to_central(fakeClient(), artifacts) + + self.assertIn('pushed:', artifacts[0].files[0][0]) + self.assertIn('pushed:', artifacts[0].files[1][0]) + self.assertEqual([], artifacts[2].files) class QiitaArtifactTypeTest(TestCase): From 2b08035d51ca5dfa336aeb9860e73dd251d53cec Mon Sep 17 00:00:00 2001 From: Stefan Janssen Date: Fri, 14 Nov 2025 11:29:54 +0100 Subject: [PATCH 6/6] make method static --- qiita_client/plugin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qiita_client/plugin.py b/qiita_client/plugin.py index 867ea35..ff2c1fc 100644 --- a/qiita_client/plugin.py +++ b/qiita_client/plugin.py @@ -100,6 +100,7 @@ def __init__(self, name, description, function, required_parameters, self.outputs = outputs self.analysis_only = analysis_only + @staticmethod def _push_artifacts_files_to_central(qclient, artifacts): """Pushes all files of a list of artifacts to BASE_DATA_DIR. @@ -136,8 +137,7 @@ def __call__(self, qclient, server_url, job_id, output_dir): isinstance(results[0], bool) and \ isinstance(results[1], list) and \ isinstance(results[2], str): - results[1] = QiitaCommand._push_artifacts_files_to_central( - qclient, results[1]) + QiitaCommand._push_artifacts_files_to_central(qclient, results[1]) return results