Skip to content

Commit

Permalink
Merge pull request #16492 from bernt-matthias/topic/consistent-profil…
Browse files Browse the repository at this point in the history
…e-check

consistently compare profile versions
  • Loading branch information
jdavcs authored Mar 4, 2024
2 parents 29725c4 + db2f548 commit d02c11a
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 21 deletions.
3 changes: 2 additions & 1 deletion lib/galaxy/tool_util/deps/container_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
)
from uuid import uuid4

from packaging.version import Version
from typing_extensions import Protocol

from galaxy.util import (
Expand Down Expand Up @@ -360,7 +361,7 @@ def add_var(name, value):
defaults += ",$tool_directory:default_ro"
if self.job_info.job_directory:
defaults += ",$job_directory:default_ro,$job_directory/outputs:rw"
if self.tool_info.profile <= 19.09:
if Version(str(self.tool_info.profile)) <= Version("19.09"):
defaults += ",$job_directory/configs:rw"
if self.job_info.home_directory is not None:
defaults += ",$home_directory:rw"
Expand Down
6 changes: 4 additions & 2 deletions lib/galaxy/tool_util/linters/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
TYPE_CHECKING,
)

from packaging.version import Version

from galaxy.tool_util.lint import Linter
from galaxy.tool_util.version import (
LegacyVersion,
Expand Down Expand Up @@ -161,7 +163,7 @@ def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext"):
_, tool_node = _tool_xml_and_root(tool_source)
profile = tool_source.parse_profile()
profile_valid = PROFILE_PATTERN.match(profile) is not None
if profile_valid and profile == "16.01":
if profile_valid and Version(profile) == Version("16.01"):
lint_ctx.valid("Tool targets 16.01 Galaxy profile.", linter=cls.name(), node=tool_node)


Expand All @@ -171,7 +173,7 @@ def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext"):
_, tool_node = _tool_xml_and_root(tool_source)
profile = tool_source.parse_profile()
profile_valid = PROFILE_PATTERN.match(profile) is not None
if profile_valid and profile != "16.01":
if profile_valid and Version(profile) != Version("16.01"):
lint_ctx.valid(f"Tool specifies profile version [{profile}].", linter=cls.name(), node=tool_node)


Expand Down
6 changes: 4 additions & 2 deletions lib/galaxy/tool_util/linters/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
TYPE_CHECKING,
)

from packaging.version import Version

from galaxy.tool_util.lint import Linter
from galaxy.util import string_as_bool
from ._util import (
Expand Down Expand Up @@ -814,7 +816,7 @@ def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext"):
profile = tool_source.parse_profile()
truevalue = param.attrib.get("truevalue", "true")
falsevalue = param.attrib.get("falsevalue", "false")
problematic_booleans_allowed = profile < "23.1"
problematic_booleans_allowed = Version(profile) < Version("23.1")
lint_level = lint_ctx.warn if problematic_booleans_allowed else lint_ctx.error
if truevalue == falsevalue:
lint_level(
Expand All @@ -840,7 +842,7 @@ def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext"):
profile = tool_source.parse_profile()
truevalue = param.attrib.get("truevalue", "true")
falsevalue = param.attrib.get("falsevalue", "false")
problematic_booleans_allowed = profile < "23.1"
problematic_booleans_allowed = Version(profile) < Version("23.1")
lint_level = lint_ctx.warn if problematic_booleans_allowed else lint_ctx.error
if truevalue.lower() == "false":
lint_level(
Expand Down
10 changes: 5 additions & 5 deletions lib/galaxy/tool_util/parser/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def __init__(self, xml_tree: ElementTree, source_path=None, macro_paths=None):
self.root = self.xml_tree.getroot()
self._source_path = source_path
self._macro_paths = macro_paths or []
self.legacy_defaults = self.parse_profile() == "16.01"
self.legacy_defaults = Version(self.parse_profile()) == Version("16.01")
self._string = xml_to_string(self.root)

def to_string(self):
Expand Down Expand Up @@ -248,7 +248,7 @@ def parse_environment_variables(self):
return environment_variables

def parse_home_target(self):
target = "job_home" if self.parse_profile() >= "18.01" else "shared_home"
target = "job_home" if Version(self.parse_profile()) >= Version("18.01") else "shared_home"
command_el = self._command_el
command_legacy = (command_el is not None) and command_el.get("use_shared_home", None)
if command_legacy is not None:
Expand Down Expand Up @@ -395,7 +395,7 @@ def parse_provided_metadata_style(self):
style = out_elem.attrib["provided_metadata_style"]

if style is None:
style = "legacy" if self.parse_profile() < "17.09" else "default"
style = "legacy" if Version(self.parse_profile()) < Version("17.09") else "default"

assert style in ["legacy", "default"]
return style
Expand Down Expand Up @@ -537,7 +537,7 @@ def _parse_output(
output.filters = data_elem.findall("filter")
output.tool = tool
output.from_work_dir = data_elem.get("from_work_dir", None)
if output.from_work_dir and getattr(tool, "profile", 0) < 21.09:
if output.from_work_dir and Version(str(getattr(tool, "profile", 0))) < Version("21.09"):
# We started quoting from_work_dir outputs in 21.09.
# Prior to quoting, trailing spaces had no effect.
# This ensures that old tools continue to work.
Expand Down Expand Up @@ -758,7 +758,7 @@ def __parse_element_tests(parent_element, profile=None):
element_tests[identifier] = __parse_test_attributes(
element, element_attrib, parse_elements=True, profile=profile
)
if profile and profile >= "20.09":
if profile and Version(profile) >= Version("20.09"):
element_tests[identifier][1]["expected_sort_order"] = idx

return element_tests
Expand Down
8 changes: 4 additions & 4 deletions lib/galaxy/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -913,10 +913,10 @@ def requires_galaxy_python_environment(self):
if self.tool_type not in ["default", "manage_data", "interactive", "data_source", "data_source_async"]:
return True

if self.tool_type == "manage_data" and self.profile < 18.09:
if self.tool_type == "manage_data" and Version(str(self.profile)) < Version("18.09"):
return True

if self.tool_type == "data_source" and self.profile < 21.09:
if self.tool_type == "data_source" and Version(str(self.profile)) < Version("21.09"):
return True

if self.tool_type == "data_source_async" and self.profile < 24.0:
Expand Down Expand Up @@ -1022,7 +1022,7 @@ def parse(self, tool_source: ToolSource, guid=None, dynamic=False):
self.python_template_version = tool_source.parse_python_template_version()
if self.python_template_version is None:
# If python_template_version not specified we assume tools with profile versions >= 19.05 are python 3 ready
if self.profile >= 19.05:
if profile >= Version("19.05"):
self.python_template_version = Version("3.5")
else:
self.python_template_version = Version("2.7")
Expand All @@ -1036,7 +1036,7 @@ def parse(self, tool_source: ToolSource, guid=None, dynamic=False):

self.version = tool_source.parse_version()
if not self.version:
if self.profile < 16.04:
if profile < Version("16.04"):
# For backward compatibility, some tools may not have versions yet.
self.version = "1.0.0"
else:
Expand Down
6 changes: 4 additions & 2 deletions lib/galaxy/tools/actions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
Union,
)

from packaging.version import Version

from galaxy import model
from galaxy.exceptions import ItemAccessibilityException
from galaxy.job_execution.actions.post import ActionBox
Expand Down Expand Up @@ -420,7 +422,7 @@ def execute(
# format='input" previously would give you a random extension from
# the input extensions, now it should just give "input" as the output
# format.
input_ext = "data" if tool.profile < 16.04 else "input"
input_ext = "data" if Version(str(tool.profile)) < Version("16.04") else "input"
input_dbkey = incoming.get("dbkey", "?")
for name, data in reversed(list(inp_data.items())):
if not data:
Expand All @@ -432,7 +434,7 @@ def execute(
data = data.to_history_dataset_association(None)
inp_data[name] = data

if tool.profile < 16.04:
if Version(str(tool.profile)) < Version("16.04"):
input_ext = data.ext

if data.dbkey not in [None, "?"]:
Expand Down
4 changes: 3 additions & 1 deletion lib/galaxy/tools/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
Union,
)

from packaging.version import Version

from galaxy import model
from galaxy.authnz.util import provider_name_to_backend
from galaxy.job_execution.compute_environment import ComputeEnvironment
Expand Down Expand Up @@ -741,7 +743,7 @@ def _build_param_file(self):
param_dict = self.param_dict
directory = self.local_working_directory
command = self.tool.command
if self.tool.profile < 16.04 and command and "$param_file" in command:
if Version(str(self.tool.profile)) < Version("16.04") and command and "$param_file" in command:
with tempfile.NamedTemporaryFile(mode="w", dir=directory, delete=False) as param:
for key, value in param_dict.items():
# parameters can be strings or lists of strings, coerce to list
Expand Down
3 changes: 2 additions & 1 deletion lib/galaxy/tools/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
)

from boltons.iterutils import remap
from packaging.version import Version

from galaxy import model
from galaxy.exceptions import ToolInputsNotOKException
Expand Down Expand Up @@ -310,7 +311,7 @@ def output_name(self, trans, history, params, output):
return output_collection_name

def sliced_input_collection_structure(self, input_name):
unqualified_recurse = self.tool.profile < 18.09 and "|" not in input_name
unqualified_recurse = Version(str(self.tool.profile)) < Version("18.09") and "|" not in input_name

def find_collection(input_dict, input_name):
for key, value in input_dict.items():
Expand Down
5 changes: 3 additions & 2 deletions lib/galaxy/tools/parameters/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
Union,
)

from packaging.version import Version
from webob.compat import cgi_FieldStorage

from galaxy import util
Expand Down Expand Up @@ -589,7 +590,7 @@ def __init__(self, tool, input_source):
super().__init__(tool, input_source)
truevalue = input_source.get("truevalue", "true")
falsevalue = input_source.get("falsevalue", "false")
if tool and tool.profile >= 23.1:
if tool and Version(str(tool.profile)) >= Version("23.1"):
if truevalue == falsevalue:
raise ParameterValueError("Cannot set true and false to the same value", self.name)
if truevalue.lower() == "false":
Expand Down Expand Up @@ -1020,7 +1021,7 @@ def from_json(self, value, trans, other_values=None, require_legal_value=True):
"an invalid option (None) was selected, please verify", self.name, None, is_dynamic=self.is_dynamic
)
elif not legal_values:
if self.optional and self.tool.profile < 18.09:
if self.optional and Version(str(self.tool.profile)) < Version("18.09"):
# Covers optional parameters with default values that reference other optional parameters.
# These will have a value but no legal_values.
# See https://github.com/galaxyproject/tools-iuc/pull/1842#issuecomment-394083768 for context.
Expand Down
4 changes: 3 additions & 1 deletion lib/galaxy/tools/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
Union,
)

from packaging.version import Version

from galaxy.model import (
DatasetCollection,
DatasetCollectionElement,
Expand Down Expand Up @@ -128,7 +130,7 @@ def __init__(
and input.type == "text"
and input.optional
and input.optionality_inferred
and (profile is None or profile < 23.0)
and (profile is None or Version(str(profile)) < Version("23.0"))
):
# Tools with old profile versions may treat an optional text parameter as `""`
value = ""
Expand Down

0 comments on commit d02c11a

Please sign in to comment.