Skip to content

Commit ee710a4

Browse files
committed
function used to import an invocation archive. Needs API updates before it can be merged.
1 parent 305bed6 commit ee710a4

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

bioblend/_tests/TestGalaxyInvocations.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,15 @@ def test_get_invocation_jobs_summary(self):
112112
assert len(step_jobs_summary) == 1
113113
assert step_jobs_summary[0]["populated_state"] == "ok"
114114

115+
@test_util.skip_unless_galaxy("release_23.0")
116+
def test_import_invocation_archive(self):
117+
new_history = self.gi.histories.create_history(name="My History")
118+
test_file = test_util.get_abspath(os.path.join("data", "example3.rocrate.zip"))
119+
import_response = self.gi.invocations.import_invocation(
120+
history_id=new_history["id"], model_store_format="rocrate.zip", file_path=test_file
121+
)
122+
assert "model_class" in import_response[0] and import_response[0]["model_class"] == "WorkflowInvocation"
123+
115124
@test_util.skip_unless_galaxy("release_19.09")
116125
@test_util.skip_unless_tool("cat1")
117126
@test_util.skip_unless_tool("cat")
10.8 KB
Binary file not shown.

bioblend/galaxy/invocations/__init__.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Contains possible interactions with the Galaxy workflow invocations
33
"""
44

5+
import base64
56
import logging
67
from typing import (
78
Any,
@@ -267,6 +268,39 @@ def cancel_invocation(self, invocation_id: str) -> dict[str, Any]:
267268
url = self._make_url(invocation_id)
268269
return self._delete(url=url)
269270

271+
def import_invocation(
272+
self, history_id: str, model_store_format: str, file_path: Optional[str] = None, url: Optional[str] = None
273+
) -> Any:
274+
"""
275+
Import a invocation from an archive on disk or a URL.
276+
277+
:type history_id
278+
:param history_id: id of the history where the invocation will be imported
279+
280+
:type model_store_format
281+
:param model_store_format: archive type that will be imported
282+
283+
:type file_path: str
284+
:param file_path: Path to exported history archive on disk.
285+
286+
:type url: str
287+
:param url: URL for an exported history archive
288+
289+
:rtype: dict or list of dicts
290+
:return: if the import is successful, a list of dictionaries will be returned; otherwise, a single dictionary will be returned.
291+
"""
292+
payload: dict[str, Any] = {
293+
"history_id": history_id,
294+
"model_store_format": model_store_format,
295+
}
296+
if file_path:
297+
with open(file_path, "rb") as reader:
298+
payload["store_content_uri"] = "base64://" + base64.b64encode(reader.read()).decode("utf-8")
299+
else:
300+
payload["store_content_uri"] = url
301+
url = "/".join((self._make_url(), "from_store"))
302+
return self._post(url=url, payload=payload)
303+
270304
def show_invocation_step(self, invocation_id: str, step_id: str) -> dict[str, Any]:
271305
"""
272306
See the details of a particular workflow invocation step.

0 commit comments

Comments
 (0)