Skip to content

Commit

Permalink
Merge pull request #91 from cat-bro/helpers-for-tool-version-comparison
Browse files Browse the repository at this point in the history
Add helpers for tool version comparison
  • Loading branch information
cat-bro authored Apr 16, 2023
2 parents 6a6c554 + 8e9ce30 commit 403d204
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 2 deletions.
15 changes: 14 additions & 1 deletion tests/fixtures/mapping-rule-tool-limits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,20 @@ tools:
execute: |
from galaxy.jobs.mapper import JobNotReadyException
raise JobNotReadyException()
toolshed.g2.bx.psu.edu/repos/iuc/trinity/trinity/.*:
rules:
- if: helpers.tool_version_gte(tool, '2.15.1+galaxy0')
env:
version_gte_2.15.1+galaxy0: true
- if: helpers.tool_version_gt(tool, '2.15.1+galaxy0')
env:
version_gt_2.15.1+galaxy0: true
- if: helpers.tool_version_lt(tool, '2.10.1+galaxy7')
env:
version_lt_2.10.1+galaxy7: true
- if: helpers.tool_version_lte(tool, '2.10.1+galaxy7')
env:
version_lte_2.10.1+galaxy7: true

destinations:
local:
Expand Down
39 changes: 39 additions & 0 deletions tests/test_mapper_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,42 @@ def create_job(app, mock_user, mock_tool):
with self.assertRaises(JobNotReadyException):
tpv_config = os.path.join(os.path.dirname(__file__), 'fixtures/mapping-rule-tool-limits.yml')
self._map_to_destination(tool_total_limit_3, user_roosta, datasets, tpv_config_files=[tpv_config], app=app)

def test_tool_version_comparison_helpers(self):
tpv_config = os.path.join(os.path.dirname(__file__), 'fixtures/mapping-rule-tool-limits.yml')
user = mock_galaxy.User('ford', '[email protected]')
datasets = [mock_galaxy.DatasetAssociation("test", mock_galaxy.Dataset("test.txt", file_size=1*1024**3))]

def mock_trinity_with_version(version):
return mock_galaxy.Tool(
id=f'toolshed.g2.bx.psu.edu/repos/iuc/trinity/trinity/{version}',
version=version
)

env_keys = [ # env keys that may be added by cooked trinity rules
'version_gte_2.15.1+galaxy0',
'version_gt_2.15.1+galaxy0',
'version_lt_2.10.1+galaxy7',
'version_lte_2.10.1+galaxy7',
]
# trinity version 3.15.1+galaxy0
tool = mock_trinity_with_version('3.15.1+galaxy0')
destination = self._map_to_destination(tool, user, datasets, tpv_config_files=[tpv_config])
self.assertCountEqual(
[e.get('name') for e in destination.env if e.get('name') in env_keys],
['version_gte_2.15.1+galaxy0', 'version_gt_2.15.1+galaxy0'],
)
# trinity version 2.15.1+galaxy0
tool = mock_trinity_with_version('2.15.1+galaxy0')
destination = self._map_to_destination(tool, user, datasets, tpv_config_files=[tpv_config])
self.assertCountEqual(
[e.get('name') for e in destination.env if e.get('name') in env_keys],
['version_gte_2.15.1+galaxy0'],
)
# trinity version 2.10.1+galaxy6
tool = mock_trinity_with_version('2.10.1+galaxy6')
destination = self._map_to_destination(tool, user, datasets, tpv_config_files=[tpv_config])
self.assertCountEqual(
[e.get('name') for e in destination.env if e.get('name') in env_keys],
['version_lt_2.10.1+galaxy7', 'version_lte_2.10.1+galaxy7'],
)
3 changes: 2 additions & 1 deletion tpv/commands/test/mock_galaxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ def __init__(self, file_name, file_size):

# Tool mock and helpers=========================================
class Tool:
def __init__(self, id):
def __init__(self, id, version=None):
self.id = id
self.old_id = id
self.version = version
self.installed_tool_dependencies = []


Expand Down
17 changes: 17 additions & 0 deletions tpv/core/helpers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import packaging.version
import random
from functools import reduce
from galaxy import model
Expand Down Expand Up @@ -85,3 +86,19 @@ def tag_values_match(entity, match_tag_values=[], exclude_tag_values=[]):
all([any(entity.tpv_tags.filter(tag_value=tag_value)) for tag_value in match_tag_values])
and not any([any(entity.tpv_tags.filter(tag_value=tag_value)) for tag_value in exclude_tag_values])
)


def tool_version_lte(tool, version):
return packaging.version.parse(tool.version) <= packaging.version.parse(version)


def tool_version_lt(tool, version):
return packaging.version.parse(tool.version) < packaging.version.parse(version)


def tool_version_gte(tool, version):
return packaging.version.parse(tool.version) >= packaging.version.parse(version)


def tool_version_gt(tool, version):
return packaging.version.parse(tool.version) > packaging.version.parse(version)

0 comments on commit 403d204

Please sign in to comment.