Commit 6bd0d7c2 authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

ENH,RF: Support for optional variables - a value of None is used for matches

for which an optional variable is not present
parent 689f5fc3
......@@ -103,9 +103,6 @@ class FileTreeQuery(object):
idx = []
for var in snvars:
# TODO handle optional variables. Need
# an extra element on each axis which
# represents a missing value
val = match.variables[var]
idx.append(snvaridxs[var][val])
......@@ -194,10 +191,7 @@ def scan(tree):
if not op.isfile(filename):
continue
variables = tree.extract_variables(template, filename)
variables = {var : val
for var, val in variables.items()
if val is not None}
variables = dict(tree.extract_variables(template, filename))
matches.append(Match(filename, template, variables))
......@@ -232,7 +226,12 @@ def allVariables(tree, matches) -> Tuple[Dict[str, List], Dict[str, List]]:
allvars[ var] .add(val)
allshortnames[m.short_name].add(var)
allvars = {var : list(sorted(vals))
# allow us to compare None with strings
def key(v):
if v is None: return ''
else: return v
allvars = {var : list(sorted(vals, key=key))
for var, vals in allvars.items()}
allshortnames = {sn : list(sorted(vars))
for sn, vars in allshortnames.items()}
......@@ -261,7 +260,7 @@ class Match(object):
def __repr__(self):
"""Returns a string representation of this ``Match``. """
return 'Match({})'.format(self.filename)
return 'Match({}) {}'.format(self.filename, self.variables)
def __str__(self):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment