Skip to content

Commit 2e864f9

Browse files
authored
Merge pull request #21171 from nsoranzo/type_annot_job_handling
Add type annotations to job handling code
2 parents 07a8b64 + 5b74f08 commit 2e864f9

File tree

38 files changed

+608
-394
lines changed

38 files changed

+608
-394
lines changed

lib/galaxy/datatypes/registry.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
if TYPE_CHECKING:
4646
from galaxy.datatypes.data import Data
4747
from galaxy.tool_util.toolbox.base import AbstractToolBox
48+
from galaxy.tools import SetMetadataTool
4849

4950

5051
class ConfigurationError(Exception):
@@ -749,15 +750,15 @@ def reload_display_applications(self, display_application_ids=None):
749750
failed.append(display_application_id)
750751
return (reloaded, failed)
751752

752-
def load_external_metadata_tool(self, toolbox):
753+
def load_external_metadata_tool(self, toolbox: "AbstractToolBox") -> None:
753754
"""Adds a tool which is used to set external metadata"""
754755
# We need to be able to add a job to the queue to set metadata. The queue will currently only accept jobs with an associated
755756
# tool. We'll load a special tool to be used for Auto-Detecting metadata; this is less than ideal, but effective
756757
# Properly building a tool without relying on parsing an XML file is near difficult...so we bundle with Galaxy.
757758
set_meta_tool = toolbox.load_hidden_lib_tool(
758759
os.path.abspath(os.path.join(os.path.dirname(__file__), "set_metadata_tool.xml"))
759760
)
760-
self.set_external_metadata_tool = set_meta_tool
761+
self.set_external_metadata_tool = cast("SetMetadataTool", set_meta_tool)
761762
self.log.debug("Loaded external metadata tool: %s", self.set_external_metadata_tool.id)
762763

763764
def set_default_values(self):

lib/galaxy/job_metrics/__init__.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
NamedTuple,
2727
Optional,
2828
TYPE_CHECKING,
29+
Union,
2930
)
3031

3132
from galaxy import util
@@ -38,6 +39,7 @@
3839

3940
if TYPE_CHECKING:
4041
from galaxy.job_metrics.instrumenters import InstrumentPlugin
42+
from galaxy.util import Element
4143

4244
log = logging.getLogger(__name__)
4345

@@ -123,21 +125,23 @@ def raw_to_dictifiable(raw_metric: RawMetric) -> DictifiableMetric:
123125
metrics = map(raw_to_dictifiable, raw_metrics)
124126
return [m for m in metrics if m.safety.value >= allowed_safety.value]
125127

126-
def set_destination_conf_file(self, destination_id, conf_file):
128+
def set_destination_conf_file(self, destination_id: str, conf_file: str) -> None:
127129
instrumenter = JobInstrumenter.from_file(self.plugin_classes, conf_file)
128130
self.set_destination_instrumenter(destination_id, instrumenter)
129131

130-
def set_destination_conf_element(self, destination_id, element):
132+
def set_destination_conf_element(self, destination_id: str, element: "Element") -> None:
131133
plugin_source = plugin_config.PluginConfigSource("xml", element)
132134
instrumenter = JobInstrumenter(self.plugin_classes, plugin_source)
133135
self.set_destination_instrumenter(destination_id, instrumenter)
134136

135-
def set_destination_conf_dicts(self, destination_id, conf_dicts):
137+
def set_destination_conf_dicts(self, destination_id: str, conf_dicts: List[Dict[str, Any]]) -> None:
136138
plugin_source = plugin_config.PluginConfigSource("dict", conf_dicts)
137139
instrumenter = JobInstrumenter(self.plugin_classes, plugin_source)
138140
self.set_destination_instrumenter(destination_id, instrumenter)
139141

140-
def set_destination_instrumenter(self, destination_id, job_instrumenter=None):
142+
def set_destination_instrumenter(
143+
self, destination_id: str, job_instrumenter: Union["JobInstrumenterI", None] = None
144+
) -> None:
141145
if job_instrumenter is None:
142146
job_instrumenter = NULL_JOB_INSTRUMENTER
143147
self.job_instrumenters[destination_id] = job_instrumenter

0 commit comments

Comments
 (0)