Skip to content

Commit f3f4f45

Browse files
author
Anup Kumar
committed
add new method for getting entire tool source
1 parent ea01525 commit f3f4f45

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

bioblend/_tests/TestGalaxyTools.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,18 @@ def test_get_tool_tests(self):
176176
assert "inputs" in first_test
177177
assert "outputs" in first_test
178178

179+
@test_util.skip_unless_tool("random_lines1")
180+
def test_get_tool_source(self):
181+
tool_source = self.gi.tools.get_tool_source("random_lines1")
182+
assert isinstance(tool_source, str)
183+
assert tool_source
184+
assert "<tool" in tool_source.lower()
185+
assert "</tool>" in tool_source.lower()
186+
assert "<test>" in tool_source.lower()
187+
assert "</test>" in tool_source.lower()
188+
assert "<help>" in tool_source.lower()
189+
assert "</help>" in tool_source.lower()
190+
179191
@test_util.skip_unless_tool("random_lines1")
180192
def test_get_tool_help_text(self):
181193
help_text = self.gi.tools.get_tool_help_text("random_lines1")

bioblend/galaxy/tools/__init__.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,23 @@ def uninstall_dependencies(self, tool_id: str) -> dict:
182182
"""
183183
url = self._make_url(tool_id) + "/dependencies"
184184
return self._delete(url=url)
185+
186+
def get_tool_source(self, tool_id: str) -> str:
187+
"""
188+
Get the raw tool XML source for a given tool ID.
189+
190+
:type tool_id: str
191+
:param tool_id: id of the requested tool
192+
193+
:rtype: str
194+
:return: Tool XML source as a string
195+
"""
196+
try:
197+
raw_source_url = self._make_url(tool_id) + "/raw_tool_source"
198+
ht_response = self._get(url=raw_source_url, json=False)
199+
return ht_response.text
200+
except Exception as e:
201+
raise RuntimeError(f"Could not retrieve tool source for tool '{tool_id}': {e}")
185202

186203
def get_tool_help_text(self, tool_id: str) -> str:
187204
"""
@@ -198,12 +215,11 @@ def get_tool_help_text(self, tool_id: str) -> str:
198215
flags=re.DOTALL | re.IGNORECASE,
199216
)
200217
try:
201-
raw_source_url = self._make_url(tool_id) + "/raw_tool_source"
202-
ht_response = self._get(url=raw_source_url, json=False)
203-
ht = HELP_BLOCK_RE.search(ht_response.text)
218+
tool_source = self.get_tool_source(tool_id)
219+
ht = HELP_BLOCK_RE.search(tool_source)
204220
return ht.group("body").strip() if ht else ""
205221
except Exception as e:
206-
raise RuntimeError(f"Could not retrieve tool source for tool '{tool_id}': {e}")
222+
raise RuntimeError(f"Could not retrieve tool helptext for tool '{tool_id}': {e}")
207223

208224
def show_tool(self, tool_id: str, io_details: bool = False, link_details: bool = False) -> dict[str, Any]:
209225
"""

0 commit comments

Comments
 (0)