Skip to content

Commit

Permalink
[18.05] Fix sniff validation for dynamic compressed types.
Browse files Browse the repository at this point in the history
This was broken in a bad PR merge/rebase process since the validation mode didn't exist when the initial dynamic compressed types PR was opened.
  • Loading branch information
jmchilton committed May 8, 2018
1 parent de5ed28 commit 1083fa4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/galaxy/datatypes/registry.py
Expand Up @@ -323,7 +323,9 @@ def __import_module(full_path, datatype_module, datatype_class_name):
if sniff_compressed_types is None:
sniff_compressed_types = getattr(self.config, "sniff_compressed_dynamic_datatypes_default", True)
if not sniff_compressed_types:
attributes["sniff_prefix"] = lambda self, file_prefix: False
# Disable sniff on this type unless in validate_mode().
attributes["sniff_compressed"] = False

compressed_datatype_class = type(auto_compressed_type_name, (datatype_class, binary.CompressedArchive, ), attributes)
if edam_format:
compressed_datatype_class.edam_format = edam_format
Expand Down
17 changes: 15 additions & 2 deletions lib/galaxy/datatypes/sniff.py
Expand Up @@ -605,13 +605,26 @@ def search_str(self, query_str):


def build_sniff_from_prefix(klass):
# Build and attach a sniff function to this class (klass) from the sniff_prefix function
# expected to be defined for the class.
def auto_sniff(self, filename):
file_prefix = FilePrefix(filename)
datatype_compressed = getattr(self, "compressed", False)
if file_prefix.compressed_format and not datatype_compressed:
return False
if datatype_compressed and not file_prefix.compressed_format:
return False
if datatype_compressed:
if not file_prefix.compressed_format:
# This not a compressed file we are looking but the type expects it to be
# must return False.
return False

if not getattr(klass, "sniff_compressed", True) and not self.validate_mode():
# This datatype indicates that it shouldn't be auto-sniffed so return False.
# Do not take this shortcut if validate_mode is True, in that case we aren't
# trying to find a datatype for a file we are trying to verify a datatype
# selection and so should execute the underlying sniff_prefix.
return False

if hasattr(self, "compressed_format"):
if self.compressed_format != file_prefix.compressed_format:
return False
Expand Down

0 comments on commit 1083fa4

Please sign in to comment.