Skip to content

Commit 57f031e

Browse files
authored
Merge pull request #7 from jlab/uncouple_clientpush
after calling a plugin function, push files of artifacts to qiita cen…
2 parents 5c74aca + 2b08035 commit 57f031e

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed

qiita_client/plugin.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from future import standard_library
1616
from json import dumps
1717
import urllib
18-
from qiita_client import QiitaClient
18+
from qiita_client import QiitaClient, ArtifactInfo
1919

2020
import logging
2121

@@ -100,9 +100,45 @@ def __init__(self, name, description, function, required_parameters,
100100
self.outputs = outputs
101101
self.analysis_only = analysis_only
102102

103+
@staticmethod
104+
def _push_artifacts_files_to_central(qclient, artifacts):
105+
"""Pushes all files of a list of artifacts to BASE_DATA_DIR.
106+
107+
Parameters
108+
----------
109+
qclient : qiita_client.QiitaClient
110+
The Qiita server client
111+
artifacts : [ArtifactInfo]
112+
A list of qiita Artifacts
113+
114+
Returns
115+
-------
116+
The input list of artifacts
117+
"""
118+
if artifacts is None:
119+
return artifacts
120+
121+
for artifact in artifacts:
122+
if isinstance(artifact, ArtifactInfo):
123+
for i in range(len(artifact.files)):
124+
(fp, ftype) = artifact.files[i]
125+
# send file to Qiita central and potentially update
126+
# filepath, which is not done at the moment (2025-11-14)
127+
fp = qclient.push_file_to_central(fp)
128+
artifact.files[i] = (fp, ftype)
129+
103130
def __call__(self, qclient, server_url, job_id, output_dir):
104131
logger.debug('Entered QiitaCommand.__call__()')
105-
return self.function(qclient, server_url, job_id, output_dir)
132+
results = self.function(
133+
qclient, server_url, job_id, output_dir)
134+
# typical, but not all, functions of QiitaCommands return 3-tuple
135+
# status=bool, list of artifacts, error_message=str
136+
if isinstance(results, tuple) and (len(results) == 3) and \
137+
isinstance(results[0], bool) and \
138+
isinstance(results[1], list) and \
139+
isinstance(results[2], str):
140+
QiitaCommand._push_artifacts_files_to_central(qclient, results[1])
141+
return results
106142

107143

108144
class QiitaArtifactType(object):

qiita_client/tests/test_plugin.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,23 @@ def func(a, b, c, d):
7373
self.exp_opt, self.exp_out, self.exp_dflt)
7474
self.assertEqual(obs('a', 'b', 'c', 'd'), 42)
7575

76+
def test__push_artifacts_files_to_central(self):
77+
class fakeClient():
78+
def push_file_to_central(self, filepath):
79+
return 'pushed:%s' % filepath
80+
81+
artifacts = [
82+
ArtifactInfo("stefArtiName", "Atype", [
83+
("fp1", "preprocessed_fasta"),
84+
("fp2", "preprocessed_fastq")]),
85+
None,
86+
ArtifactInfo("artiName", "artiType", [])]
87+
QiitaCommand._push_artifacts_files_to_central(fakeClient(), artifacts)
88+
89+
self.assertIn('pushed:', artifacts[0].files[0][0])
90+
self.assertIn('pushed:', artifacts[0].files[1][0])
91+
self.assertEqual([], artifacts[2].files)
92+
7693

7794
class QiitaArtifactTypeTest(TestCase):
7895
def test_init(self):

0 commit comments

Comments
 (0)