Skip to content

Commit

Permalink
Evaulate format_source (again) just before job submission
Browse files Browse the repository at this point in the history
At this point the inputs are ready, so expession.json has been replaced
with the true extension.
  • Loading branch information
mvdbeek committed Jan 10, 2025
1 parent 20dc7b7 commit a0919d1
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
8 changes: 7 additions & 1 deletion lib/galaxy/tool_util/parser/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@
ResourceRequirement,
ToolRequirements,
)
from galaxy.tool_util.parser.output_objects import (
ToolOutput,
ToolOutputCollection,
)
from galaxy.tools import Tool


NOT_IMPLEMENTED_MESSAGE = "Galaxy tool format does not yet support this tool feature."

Expand Down Expand Up @@ -331,7 +337,7 @@ def parse_provided_metadata_file(self):
return "galaxy.json"

@abstractmethod
def parse_outputs(self, tool):
def parse_outputs(self, tool: "Tool") -> Tuple[Dict[str, "ToolOutput"], Dict[str, "ToolOutputCollection"]]:
"""Return a pair of output and output collections ordered
dictionaries for use by Tool.
"""
Expand Down
6 changes: 6 additions & 0 deletions lib/galaxy/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@
PageSource,
ToolSource,
)
from galaxy.tool_util.parser.output_objects import (
ToolOutput,
ToolOutputCollection,
)
from galaxy.tool_util.parser.util import (
parse_profile_version,
parse_tool_version_with_defaults,
Expand Down Expand Up @@ -847,6 +851,8 @@ def __init__(
self.tool_errors = None
# Parse XML element containing configuration
self.tool_source = tool_source
self.outputs: Dict[str, ToolOutput] = {}
self.output_collections: Dict[str, ToolOutputCollection] = {}
self._is_workflow_compatible = None
self.__help = None
self.__tests: Optional[str] = None
Expand Down
4 changes: 2 additions & 2 deletions lib/galaxy/tools/actions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import os
import re
from abc import abstractmethod
from collections import UserDict
from json import dumps
from typing import (
Any,
cast,
Dict,
List,
MutableMapping,
Optional,
Set,
Tuple,
Expand Down Expand Up @@ -1157,7 +1157,7 @@ def determine_output_format(
output: "ToolOutput",
parameter_context,
input_datasets,
input_dataset_collections: UserDict[str, model.HistoryDatasetCollectionAssociation],
input_dataset_collections: MutableMapping[str, model.HistoryDatasetCollectionAssociation],
random_input_ext,
python_template_version="3",
execution_cache=None,
Expand Down
23 changes: 22 additions & 1 deletion lib/galaxy/tools/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
MinimalToolApp,
)
from galaxy.tool_util.data import TabularToolDataTable
from galaxy.tools.actions import determine_output_format
from galaxy.tools.parameters import (
visit_input_values,
wrapped_json,
Expand Down Expand Up @@ -130,7 +131,7 @@ class ToolEvaluator:
job: model.Job
materialize_datasets: bool = True

def __init__(self, app: MinimalToolApp, tool, job, local_working_directory):
def __init__(self, app: MinimalToolApp, tool: "Tool", job, local_working_directory):
self.app = app
self.job = job
self.tool = tool
Expand Down Expand Up @@ -186,6 +187,9 @@ def set_compute_environment(self, compute_environment: ComputeEnvironment, get_s
out_data,
output_collections=out_collections,
)
# late update of format_source outputs
self._eval_format_source(job, inp_data, out_data)

self.execute_tool_hooks(inp_data=inp_data, out_data=out_data, incoming=incoming)

def execute_tool_hooks(self, inp_data, out_data, incoming):
Expand Down Expand Up @@ -275,6 +279,23 @@ def _materialize_objects(

return undeferred_objects

def _eval_format_source(
self,
job: model.Job,
inp_data: Dict[str, Optional[model.DatasetInstance]],
out_data: Dict[str, model.DatasetInstance],
):
for output_name, output in out_data.items():
if (
(tool_output := self.tool.outputs.get(output_name))
and (tool_output.format_source or tool_output.change_format)
and output.extension == "expression.json"
):
input_collections = {jtidca.name: jtidca.dataset_collection for jtidca in job.input_dataset_collections}
ext = determine_output_format(tool_output, self.param_dict, inp_data, input_collections, None)
if ext:
output.extension = ext

def _replaced_deferred_objects(
self,
inp_data: Dict[str, Optional[model.DatasetInstance]],
Expand Down

0 comments on commit a0919d1

Please sign in to comment.