Skip to content

Commit 2882cc4

Browse files
committed
Add version and use_cached_job parameters to WorkflowClient.invoke_workflow()
Fix #491 .
1 parent e4fc020 commit 2882cc4

File tree

3 files changed

+80
-34
lines changed

3 files changed

+80
-34
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
* Added support for Python 3.13. Added support for Galaxy release 24.1.
44

5+
* Added ``version`` and ``use_cached_job`` parameters to
6+
``WorkflowClient.invoke_workflow()`` method (reported by
7+
[Bérénice Batut](https://github.com/bebatut)).
8+
59
### BioBlend v1.3.0 - 2024-05-12
610

711
* Dropped support for Python 3.7. Added support for Python 3.12. Added support

bioblend/_tests/TestGalaxyWorkflows.py

Lines changed: 60 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ def test_show_workflow(self):
188188
assert wf_data["id"] == wf["id"]
189189
assert wf_data["name"] == wf["name"]
190190
assert wf_data["url"] == wf["url"]
191+
assert wf_data["version"] == 0
191192
assert len(wf_data["steps"]) == 3
192193
assert wf_data["inputs"] is not None
193194

@@ -208,26 +209,6 @@ def test_update_workflow_published(self):
208209
updated_wf = self.gi.workflows.update_workflow(wf["id"], published=False)
209210
assert not updated_wf["published"]
210211

211-
@test_util.skip_unless_galaxy(
212-
"release_19.09"
213-
) # due to Galaxy bug fixed in https://github.com/galaxyproject/galaxy/pull/9014
214-
def test_show_workflow_versions(self):
215-
path = test_util.get_abspath(os.path.join("data", "paste_columns.ga"))
216-
wf = self.gi.workflows.import_workflow_from_local_path(path)
217-
wf_data = self.gi.workflows.show_workflow(wf["id"])
218-
assert wf_data["version"] == 0
219-
new_name = "new name"
220-
self.gi.workflows.update_workflow(wf["id"], name=new_name)
221-
updated_wf = self.gi.workflows.show_workflow(wf["id"])
222-
assert updated_wf["name"] == new_name
223-
assert updated_wf["version"] == 1
224-
updated_wf = self.gi.workflows.show_workflow(wf["id"], version=0)
225-
assert updated_wf["name"] == "paste_columns"
226-
assert updated_wf["version"] == 0
227-
updated_wf = self.gi.workflows.show_workflow(wf["id"], version=1)
228-
assert updated_wf["name"] == new_name
229-
assert updated_wf["version"] == 1
230-
231212
@test_util.skip_unless_galaxy("release_19.09")
232213
def test_extract_workflow_from_history(self):
233214
path = test_util.get_abspath(os.path.join("data", "paste_columns.ga"))
@@ -264,16 +245,6 @@ def test_extract_workflow_from_history(self):
264245
assert wf1["steps"][str(i)]["type"] == wf2["steps"][str(i)]["type"]
265246
assert wf1["steps"][str(i)]["tool_id"] == wf2["steps"][str(i)]["tool_id"]
266247

267-
def test_show_versions(self):
268-
path = test_util.get_abspath(os.path.join("data", "paste_columns.ga"))
269-
wf = self.gi.workflows.import_workflow_from_local_path(path)
270-
versions = self.gi.workflows.show_versions(wf["id"])
271-
assert len(versions) == 1
272-
version = versions[0]
273-
assert version["version"] == 0
274-
assert "update_time" in version
275-
assert "steps" in version
276-
277248
@test_util.skip_unless_galaxy("release_21.01")
278249
def test_refactor_workflow(self):
279250
actions: List[Dict[str, Any]] = [
@@ -288,3 +259,62 @@ def test_refactor_workflow(self):
288259
updated_steps = response["workflow"]["steps"]
289260
assert len(updated_steps) == 4
290261
assert {step["label"] for step in updated_steps.values()} == {"bar", None, "Input 1", "Input 2"}
262+
263+
264+
class TestGalaxyWorkflowVersions(GalaxyTestBase.GalaxyTestBase):
265+
new_name: str
266+
workflow_id: str
267+
268+
@classmethod
269+
def setUpClass(cls) -> None:
270+
super().setUpClass()
271+
path = test_util.get_abspath(os.path.join("data", "paste_columns.ga"))
272+
cls.workflow_id = cls.gi.workflows.import_workflow_from_local_path(path)["id"]
273+
cls.new_name = "new name"
274+
cls.gi.workflows.update_workflow(cls.workflow_id, name=cls.new_name)
275+
276+
@test_util.skip_unless_galaxy(
277+
"release_19.09"
278+
) # due to Galaxy bug fixed in https://github.com/galaxyproject/galaxy/pull/9014
279+
def test_show_workflow_versions(self):
280+
updated_wf = self.gi.workflows.show_workflow(self.workflow_id)
281+
assert updated_wf["name"] == self.new_name
282+
assert updated_wf["version"] == 1
283+
wf_v0 = self.gi.workflows.show_workflow(self.workflow_id, version=0)
284+
assert wf_v0["name"] == "paste_columns"
285+
assert wf_v0["version"] == 0
286+
wf_v1 = self.gi.workflows.show_workflow(self.workflow_id, version=1)
287+
assert updated_wf == wf_v1
288+
289+
def test_show_versions(self):
290+
versions = self.gi.workflows.show_versions(self.workflow_id)
291+
assert len(versions) == 2
292+
for i, version in enumerate(versions):
293+
assert version["version"] == i
294+
assert "update_time" in version
295+
assert "steps" in version
296+
297+
@test_util.skip_unless_galaxy(
298+
"release_24.01"
299+
) # due to Galaxy bug fixed in https://github.com/galaxyproject/galaxy/pull/18378
300+
def test_invoke_previous_version(self):
301+
history_id = self.gi.histories.create_history(name="test_wf_invocation")["id"]
302+
dataset1_id = self._test_dataset(history_id)
303+
dataset = {"src": "hda", "id": dataset1_id}
304+
invocation_id = self.gi.workflows.invoke_workflow(
305+
self.workflow_id,
306+
inputs={"Input 1": dataset, "Input 2": dataset},
307+
history_id=history_id,
308+
inputs_by="name",
309+
version=0,
310+
)["id"]
311+
self.gi.invocations.wait_for_invocation(invocation_id)
312+
# Try invalid invocation (wrong version)
313+
with pytest.raises(ConnectionError):
314+
self.gi.workflows.invoke_workflow(
315+
self.workflow_id,
316+
inputs={"Input 1": dataset, "Input 2": dataset},
317+
history_id=history_id,
318+
inputs_by="name",
319+
version=2,
320+
)

bioblend/galaxy/workflows/__init__.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ def invoke_workflow(
289289
inputs_by: Optional[InputsBy] = None,
290290
parameters_normalized: bool = False,
291291
require_exact_tool_versions: bool = True,
292+
version: Optional[int] = None,
293+
use_cached_job: bool = False,
292294
) -> Dict[str, Any]:
293295
"""
294296
Invoke the workflow identified by ``workflow_id``. This will
@@ -359,6 +361,14 @@ def invoke_workflow(
359361
Galaxy does not have the exact tool versions. Default is ``True``.
360362
Parameter does not any effect for Galaxy versions < 22.05.
361363
364+
:type version: int
365+
:param version: The version of the workflow to invoke. If omitted or
366+
None, the latest workflow version will be invoked.
367+
368+
:type use_cached_job: bool
369+
:param use_cached_job: Whether to use cached jobs for the workflow
370+
invocation.
371+
362372
:rtype: dict
363373
:return: A dict containing the workflow invocation describing the
364374
scheduling of the workflow. For example::
@@ -467,7 +477,12 @@ def invoke_workflow(
467477
(which is stable across workflow imports) or the step UUID which is
468478
also stable.
469479
"""
470-
payload: Dict[str, Any] = {}
480+
payload: Dict[str, Any] = {
481+
"allow_tool_state_corrections": allow_tool_state_corrections,
482+
"require_exact_tool_versions": require_exact_tool_versions,
483+
"version": version,
484+
"use_cached_job": use_cached_job,
485+
}
471486
if inputs:
472487
payload["inputs"] = inputs
473488

@@ -483,11 +498,8 @@ def invoke_workflow(
483498
payload["history"] = history_name
484499
if not import_inputs_to_history:
485500
payload["no_add_to_history"] = True
486-
if allow_tool_state_corrections:
487-
payload["allow_tool_state_corrections"] = allow_tool_state_corrections
488501
if inputs_by is not None:
489502
payload["inputs_by"] = inputs_by
490-
payload["require_exact_tool_versions"] = require_exact_tool_versions
491503
if parameters_normalized:
492504
payload["parameters_normalized"] = parameters_normalized
493505
url = self._invocations_url(workflow_id)

0 commit comments

Comments
 (0)