mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-11-22 06:52:13 +08:00
DataManagers registers a manager under DataManager.id, which is the conf guid when there is one (every shed-installed data manager) and the id attribute otherwise. Discovery recorded the id attribute, and the load-time stamp kept whatever id an entry already had, so after a populate a materialised DataManagerTool looked up "repeatmasker_download" in a registry keyed by the guid, and every data manager job failed in exec_after_process with "Invalid data manager ... requested". Discovery now records guid-or-id, and the load-time stamp replaces a differing id, which also corrects entries already in published stores.
273 lines
9.4 KiB
Python
273 lines
9.4 KiB
Python
import sys
|
|
import textwrap
|
|
from pathlib import Path
|
|
|
|
galaxy_root = Path(__file__).parent.parent.parent.parent.parent
|
|
sys.path.insert(0, str(galaxy_root / "lib"))
|
|
|
|
from galaxy.config import GalaxyAppConfiguration
|
|
from galaxy.tool_util.toolbox.parser import get_toolbox_parser
|
|
from galaxy.tools.source_store.discover import (
|
|
discover_tools,
|
|
discover_tools_from_config,
|
|
DiscoveredTool,
|
|
)
|
|
|
|
|
|
def _write_conf(tmp_path: Path, body: str) -> tuple[Path, Path]:
|
|
tools_dir = tmp_path / "tools"
|
|
tools_dir.mkdir()
|
|
(tools_dir / "alpha.xml").write_text("<tool id='alpha' version='1.0'><description/></tool>")
|
|
(tools_dir / "beta.xml").write_text("<tool id='beta' version='1.0'><description/></tool>")
|
|
conf = tmp_path / "tool_conf.xml"
|
|
conf.write_text(textwrap.dedent(body).strip())
|
|
return conf, tools_dir
|
|
|
|
|
|
def test_top_level_tool_has_no_section(tmp_path):
|
|
conf, _ = _write_conf(
|
|
tmp_path,
|
|
f"""
|
|
<toolbox tool_path="{tmp_path}/tools">
|
|
<tool file="alpha.xml"/>
|
|
</toolbox>
|
|
""",
|
|
)
|
|
tools = list(discover_tools_from_config(str(conf)))
|
|
assert len(tools) == 1
|
|
assert tools[0].section_id is None
|
|
assert tools[0].section_name is None
|
|
assert tools[0].labels == []
|
|
|
|
|
|
def test_section_stamps_id_and_name(tmp_path):
|
|
conf, _ = _write_conf(
|
|
tmp_path,
|
|
f"""
|
|
<toolbox tool_path="{tmp_path}/tools">
|
|
<section id="ngs" name="NGS Tools">
|
|
<tool file="alpha.xml"/>
|
|
<tool file="beta.xml"/>
|
|
</section>
|
|
</toolbox>
|
|
""",
|
|
)
|
|
tools = {t.path: t for t in discover_tools_from_config(str(conf))}
|
|
assert len(tools) == 2
|
|
for t in tools.values():
|
|
assert t.section_id == "ngs"
|
|
assert t.section_name == "NGS Tools"
|
|
|
|
|
|
def test_labels_attribute_parsed_into_list(tmp_path):
|
|
conf, _ = _write_conf(
|
|
tmp_path,
|
|
f"""
|
|
<toolbox tool_path="{tmp_path}/tools">
|
|
<tool file="alpha.xml" labels="beta, experimental"/>
|
|
</toolbox>
|
|
""",
|
|
)
|
|
tools = list(discover_tools_from_config(str(conf)))
|
|
assert tools[0].labels == ["beta", "experimental"]
|
|
|
|
|
|
def test_hidden_attribute_still_captured(tmp_path):
|
|
conf, _ = _write_conf(
|
|
tmp_path,
|
|
f"""
|
|
<toolbox tool_path="{tmp_path}/tools">
|
|
<tool file="alpha.xml" hidden="true"/>
|
|
<tool file="beta.xml"/>
|
|
</toolbox>
|
|
""",
|
|
)
|
|
by_name = {Path(t.path).name: t for t in discover_tools_from_config(str(conf))}
|
|
assert by_name["alpha.xml"].hidden is True
|
|
assert by_name["beta.xml"].hidden is False
|
|
|
|
|
|
def test_mixed_top_level_and_section(tmp_path):
|
|
conf, _ = _write_conf(
|
|
tmp_path,
|
|
f"""
|
|
<toolbox tool_path="{tmp_path}/tools">
|
|
<tool file="alpha.xml" labels="featured"/>
|
|
<section id="ngs" name="NGS">
|
|
<tool file="beta.xml"/>
|
|
</section>
|
|
</toolbox>
|
|
""",
|
|
)
|
|
by_name = {Path(t.path).name: t for t in discover_tools_from_config(str(conf))}
|
|
assert by_name["alpha.xml"].section_id is None
|
|
assert by_name["alpha.xml"].labels == ["featured"]
|
|
assert by_name["beta.xml"].section_id == "ngs"
|
|
assert by_name["beta.xml"].section_name == "NGS"
|
|
assert by_name["beta.xml"].labels == []
|
|
|
|
|
|
def test_section_propagates_to_tool_dir_walk(tmp_path):
|
|
tools_dir = tmp_path / "tools"
|
|
tools_dir.mkdir()
|
|
nested = tools_dir / "ngs_pack"
|
|
nested.mkdir()
|
|
(nested / "one.xml").write_text("<tool id='one' version='1'><description/></tool>")
|
|
conf = tmp_path / "tool_conf.xml"
|
|
conf.write_text(textwrap.dedent(f"""
|
|
<toolbox tool_path="{tmp_path}/tools">
|
|
<section id="ngs" name="NGS Tools">
|
|
<tool_dir dir="ngs_pack"/>
|
|
</section>
|
|
</toolbox>
|
|
""").strip())
|
|
tools = list(discover_tools_from_config(str(conf)))
|
|
assert len(tools) == 1
|
|
assert tools[0].section_id == "ngs"
|
|
assert tools[0].section_name == "NGS Tools"
|
|
|
|
|
|
def test_dataclass_defaults_are_independent_lists():
|
|
# Regression guard for the field(default_factory=list) wiring on labels —
|
|
# two instances must not share the same underlying list.
|
|
a = DiscoveredTool(path="/a", tool_conf="/c", tool_path=None)
|
|
b = DiscoveredTool(path="/b", tool_conf="/c", tool_path=None)
|
|
a.labels.append("x")
|
|
assert b.labels == []
|
|
|
|
|
|
def test_only_confs_skips_unlisted_conf_walk(tmp_path):
|
|
conf_bodies = {}
|
|
for name in ("a", "b"):
|
|
tool = tmp_path / f"{name}_tool.xml"
|
|
tool.write_text(f'<tool id="{name}" version="1.0"><command>echo</command></tool>')
|
|
conf = tmp_path / f"{name}_conf.xml"
|
|
conf.write_text(f'<toolbox tool_path="{tmp_path}"><tool file="{tool.name}"/></toolbox>')
|
|
conf_bodies[name] = str(conf)
|
|
|
|
class _Cfg:
|
|
root = None
|
|
tool_path = str(tmp_path)
|
|
enable_beta_tool_formats = False
|
|
data_manager_config_file = None
|
|
shed_data_manager_config_file = None
|
|
|
|
def all_tool_config_files(self):
|
|
return [conf_bodies["a"], conf_bodies["b"]]
|
|
|
|
cfg = _Cfg()
|
|
walked = {
|
|
d.tool_conf
|
|
for d in discover_tools(cfg, include_bundled=False, include_converters=False) # type: ignore[arg-type]
|
|
if d.tool_conf in conf_bodies.values()
|
|
}
|
|
assert walked == set(conf_bodies.values())
|
|
|
|
walked = {
|
|
d.tool_conf
|
|
for d in discover_tools(cfg, include_bundled=False, include_converters=False, only_confs={conf_bodies["a"]}) # type: ignore[arg-type]
|
|
if d.tool_conf in conf_bodies.values()
|
|
}
|
|
assert walked == {conf_bodies["a"]}
|
|
|
|
|
|
def test_bundled_compatibility_alias_is_not_a_second_panel_placement(tmp_path):
|
|
tools_dir = tmp_path / "tools"
|
|
bundled_dir = tmp_path / "lib" / "galaxy" / "tools" / "bundled"
|
|
tools_dir.mkdir()
|
|
bundled_dir.mkdir(parents=True)
|
|
tool_source = "<tool id='alpha' version='1.0'><description/></tool>"
|
|
(tools_dir / "alpha.xml").write_text(tool_source)
|
|
(bundled_dir / "alpha.xml").write_text(tool_source)
|
|
conf = tmp_path / "tool_conf.xml"
|
|
conf.write_text(
|
|
f'<toolbox tool_path="{tools_dir}"><section id="section"><tool file="alpha.xml"/></section></toolbox>'
|
|
)
|
|
|
|
class _Cfg:
|
|
root = str(tmp_path)
|
|
tool_path = str(tools_dir)
|
|
enable_beta_tool_formats = False
|
|
data_manager_config_file = None
|
|
shed_data_manager_config_file = None
|
|
|
|
def all_tool_config_files(self):
|
|
return [str(conf)]
|
|
|
|
discoveries = [
|
|
discovered
|
|
for discovered in discover_tools(_Cfg(), include_converters=False) # type: ignore[arg-type]
|
|
if Path(discovered.path).name == "alpha.xml"
|
|
]
|
|
|
|
assert len(discoveries) == 1
|
|
assert discoveries[0].section_id == "section"
|
|
|
|
|
|
def test_shed_data_managers_parse_their_shed_conf_once(tmp_path, monkeypatch):
|
|
shed_tools = tmp_path / "shed_tools"
|
|
shed_tools.mkdir()
|
|
shed_conf = tmp_path / "shed_tool_conf.xml"
|
|
shed_conf.write_text(f'<toolbox tool_path="{shed_tools}"></toolbox>')
|
|
dm_elems = []
|
|
for name in ("a", "b", "c"):
|
|
(shed_tools / f"dm_{name}.xml").write_text(f'<tool id="dm_{name}" tool_type="manage_data" version="1.0"/>')
|
|
dm_elems.append(
|
|
f'<data_manager id="{name}" shed_conf_file="{shed_conf}">'
|
|
f'<tool file="dm_{name}.xml" guid="shed/repos/o/r/dm_{name}/1.0"/></data_manager>'
|
|
)
|
|
dm_conf = tmp_path / "shed_data_manager_conf.xml"
|
|
dm_conf.write_text(f"<data_managers>{''.join(dm_elems)}</data_managers>")
|
|
|
|
config = GalaxyAppConfiguration(
|
|
root=str(galaxy_root),
|
|
data_dir=str(tmp_path / "data"),
|
|
override_tempdir=False,
|
|
tool_config_file=str(shed_conf),
|
|
shed_data_manager_config_file=str(dm_conf),
|
|
)
|
|
parsed: list[str] = []
|
|
|
|
def counting_get_toolbox_parser(path):
|
|
parsed.append(str(path))
|
|
return get_toolbox_parser(path)
|
|
|
|
monkeypatch.setattr("galaxy.tools.source_store.discover.get_toolbox_parser", counting_get_toolbox_parser)
|
|
discovered = [
|
|
d
|
|
for d in discover_tools(config, include_bundled=False, include_converters=False, only_confs=set())
|
|
if d.tool_conf == str(dm_conf)
|
|
]
|
|
|
|
assert sorted(d.path for d in discovered) == [str(shed_tools / f"dm_{name}.xml") for name in ("a", "b", "c")]
|
|
assert parsed == [str(shed_conf)]
|
|
|
|
|
|
def test_data_manager_id_is_the_registry_id(tmp_path):
|
|
tools = tmp_path / "tools"
|
|
tools.mkdir()
|
|
for name in ("shed_dm", "local_dm"):
|
|
(tools / f"{name}.xml").write_text(f'<tool id="{name}" tool_type="manage_data" version="1.0"/>')
|
|
dm_conf = tmp_path / "data_manager_conf.xml"
|
|
dm_conf.write_text(
|
|
f'<data_managers tool_path="{tools}">'
|
|
'<data_manager id="shed_dm" guid="shed/repos/o/r/data_manager/shed_dm/1.0">'
|
|
'<tool file="shed_dm.xml" guid="shed/repos/o/r/shed_dm/1.0"/></data_manager>'
|
|
'<data_manager id="local_dm" tool_file="local_dm.xml"/>'
|
|
"</data_managers>"
|
|
)
|
|
config = GalaxyAppConfiguration(
|
|
root=str(galaxy_root),
|
|
data_dir=str(tmp_path / "data"),
|
|
override_tempdir=False,
|
|
data_manager_config_file=str(dm_conf),
|
|
)
|
|
|
|
ids = {
|
|
Path(d.path).stem: d.data_manager_id
|
|
for d in discover_tools(config, include_bundled=False, include_converters=False, only_confs=set())
|
|
if d.tool_conf == str(dm_conf)
|
|
}
|
|
|
|
assert ids == {"shed_dm": "shed/repos/o/r/data_manager/shed_dm/1.0", "local_dm": "local_dm"}
|