Skip to content

Commit 0bf1d42

Browse files
authored
Merge pull request #496 from mvdbeek/gxformat2_export
Add gxformat2 export
2 parents 8e08b05 + bf52ac6 commit 0bf1d42

File tree

5 files changed

+41
-6
lines changed

5 files changed

+41
-6
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
* Added ``offset`` parameter to ``InvocationClient.get_invocations()`` and
66
BioBlend.objects ``ObjInvocationClient.list()`` methods.
77

8+
* Added ``style`` parameter to ``WorkflowClient.export_workflow_dict()`` method
9+
(thanks to [Marius van den Beek](https://github.com/mvdbeek)).
10+
811
* Improvements to type annotations and documentation.
912

1013
### BioBlend v1.4.0 - 2024-11-06

bioblend/_tests/TestGalaxyWorkflows.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
import shutil
44
import tempfile
55
import time
6-
from typing import Any
6+
from typing import (
7+
Any,
8+
Literal,
9+
Optional,
10+
)
711

812
import pytest
913

@@ -141,7 +145,7 @@ def test_import_publish_workflow_from_local_path(self):
141145
assert not imported_wf["deleted"]
142146
assert imported_wf["published"]
143147

144-
def test_import_export_workflow_dict(self):
148+
def _import_export(self, style: Optional[Literal["ga", "format2"]] = None):
145149
path = test_util.get_abspath(os.path.join("data", "paste_columns.ga"))
146150
with open(path) as f:
147151
wf_dict = json.load(f)
@@ -151,8 +155,21 @@ def test_import_export_workflow_dict(self):
151155
assert imported_wf["url"].startswith("/api/workflows/")
152156
assert not imported_wf["deleted"]
153157
assert not imported_wf["published"]
154-
exported_wf_dict = self.gi.workflows.export_workflow_dict(imported_wf["id"])
158+
exported_wf_dict = self.gi.workflows.export_workflow_dict(imported_wf["id"], style=style)
155159
assert isinstance(exported_wf_dict, dict)
160+
if style == "format2":
161+
assert exported_wf_dict["class"] == "GalaxyWorkflow"
162+
else:
163+
assert exported_wf_dict["a_galaxy_workflow"] == "true"
164+
165+
def test_import_export_workflow_dict(self):
166+
self._import_export()
167+
168+
def test_import_export_workflow_dict_ga(self):
169+
self._import_export("ga")
170+
171+
def test_import_export_workflow_dict_format2(self):
172+
self._import_export("format2")
156173

157174
def test_import_publish_workflow_dict(self):
158175
path = test_util.get_abspath(os.path.join("data", "paste_columns.ga"))

bioblend/galaxy/workflows/__init__.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
TYPE_CHECKING,
1212
)
1313

14+
import yaml
15+
1416
from bioblend.galaxy.client import Client
1517

1618
if TYPE_CHECKING:
@@ -193,7 +195,9 @@ def import_shared_workflow(self, workflow_id: str) -> dict[str, Any]:
193195
url = self._make_url()
194196
return self._post(url=url, payload=payload)
195197

196-
def export_workflow_dict(self, workflow_id: str, version: Optional[int] = None) -> dict[str, Any]:
198+
def export_workflow_dict(
199+
self, workflow_id: str, version: Optional[int] = None, style: Optional[Literal["ga", "format2"]] = None
200+
) -> dict[str, Any]:
197201
"""
198202
Exports a workflow.
199203
@@ -203,15 +207,24 @@ def export_workflow_dict(self, workflow_id: str, version: Optional[int] = None)
203207
:type version: int
204208
:param version: Workflow version to export
205209
210+
:type style
211+
:param style: Either "ga" for the original JSON format or "format2" for
212+
the modern YAML gxformat2 format.
213+
206214
:rtype: dict
207215
:return: Dictionary representing the requested workflow
208216
"""
209217
params: dict[str, Any] = {}
210218
if version is not None:
211219
params["version"] = version
212-
220+
if style:
221+
params["style"] = style
213222
url = "/".join((self._make_url(), "download", workflow_id))
214-
return self._get(url=url, params=params)
223+
json = style != "format2"
224+
response = self._get(url=url, params=params, json=json)
225+
if not json:
226+
return yaml.safe_load(response.text)
227+
return response
215228

216229
def export_workflow_to_local_path(
217230
self, workflow_id: str, file_local_path: str, use_default_filename: bool = True

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ disable_error_code = func-returns-value
6868

6969
[options]
7070
install_requires =
71+
PyYAML
7172
requests>=2.20.0
7273
requests-toolbelt>=0.5.1,!=0.9.0
7374
tuspy

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,5 @@ deps =
4343
mypy
4444
ruff
4545
types-requests
46+
types-PyYAML
4647
skip_install = true

0 commit comments

Comments
 (0)