Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions tests/fixtures/mapping-inheritance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ tools:
inherits: ~
gpus: 5
kraken2:
env:
this_is_kraken2: yes
scheduling:
require:
- custom-indices
kraken2000:
env:
this_is_kraken2000: yes
scheduling:
require:
- custom-indices
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/mapping-invalid-regex.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ tools:
abstract: true
my_concrete_tool:
inherits: default
bwa\:
bwa[:
scheduling:
require:
- pulsar
Expand Down
2 changes: 1 addition & 1 deletion tests/test_mapper_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_map_tool_by_regex_mismatch(self):
def test_map_tool_with_invalid_regex(self):
tool = mock_galaxy.Tool('sometool')
config = os.path.join(os.path.dirname(__file__), 'fixtures/mapping-invalid-regex.yml')
with self.assertRaisesRegex(re.error, "bad escape"):
with self.assertRaisesRegex(re.error, "unterminated character set"):
self._map_to_destination(tool, tpv_config_path=config)

def test_map_abstract_tool_should_fail(self):
Expand Down
9 changes: 9 additions & 0 deletions tests/test_mapper_inheritance.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,12 @@ def test_general_destination_inheritance(self):
self.assertTrue('ABC' in [e.get('name') for e in destination.env])
self.assertEqual('extra-args', destination.params.get('docker_extra'))
self.assertEqual('k8s', destination.runner)

def test_noninheritance_of_tool_with_substring_id(self):
tool_id = 'kraken2000'
user = mock_galaxy.User('benjy', '[email protected]')
tool = mock_galaxy.Tool(tool_id)
datasets = [mock_galaxy.DatasetAssociation("test", mock_galaxy.Dataset("test.txt", file_size=5*1024**3))]
destination = self._map_to_destination(tool, user, datasets)
self.assertEqual(len([e for e in destination.env if e['name'] == 'this_is_kraken2000']), 1)
self.assertEqual(len([e for e in destination.env if e['name'] == 'this_is_kraken2']), 0)
9 changes: 6 additions & 3 deletions tpv/core/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ def __init__(self, loader: TPVConfigLoader):
self.destinations = loader.destinations
self.default_inherits = loader.global_settings.get('default_inherits')
self.global_context = loader.global_settings.get('context')
self.lookup_tool_regex = functools.lru_cache(maxsize=None)(self.__compile_tool_regex)
self.lookup_entity_regex = functools.lru_cache(maxsize=None)(self.__compile_entity_regex)
self.inherit_matching_entities = functools.lru_cache(maxsize=None)(self.__inherit_matching_entities)

def __compile_tool_regex(self, key):
def __compile_entity_regex(self, key):
# append an EOL anchor so that it's an exact match
if not key.endswith("$"):
key += "$"
try:
return re.compile(key)
except re.error:
Expand All @@ -40,7 +43,7 @@ def _find_entities_matching_id(self, entity_list, entity_name):
else:
matches = []
for key in entity_list.keys():
if self.lookup_tool_regex(key).match(entity_name):
if self.lookup_entity_regex(key).match(entity_name):
match = entity_list[key]
if match.abstract:
from galaxy.jobs.mapper import JobMappingException
Expand Down