Skip to content
Snippets Groups Projects
Commit 6bd0d7c2 authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
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
No related branches found
No related tags found
No related merge requests found
...@@ -103,9 +103,6 @@ class FileTreeQuery(object): ...@@ -103,9 +103,6 @@ class FileTreeQuery(object):
idx = [] idx = []
for var in snvars: for var in snvars:
# TODO handle optional variables. Need
# an extra element on each axis which
# represents a missing value
val = match.variables[var] val = match.variables[var]
idx.append(snvaridxs[var][val]) idx.append(snvaridxs[var][val])
...@@ -194,10 +191,7 @@ def scan(tree): ...@@ -194,10 +191,7 @@ def scan(tree):
if not op.isfile(filename): if not op.isfile(filename):
continue continue
variables = tree.extract_variables(template, filename) variables = dict(tree.extract_variables(template, filename))
variables = {var : val
for var, val in variables.items()
if val is not None}
matches.append(Match(filename, template, variables)) matches.append(Match(filename, template, variables))
...@@ -232,7 +226,12 @@ def allVariables(tree, matches) -> Tuple[Dict[str, List], Dict[str, List]]: ...@@ -232,7 +226,12 @@ def allVariables(tree, matches) -> Tuple[Dict[str, List], Dict[str, List]]:
allvars[ var] .add(val) allvars[ var] .add(val)
allshortnames[m.short_name].add(var) 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()} for var, vals in allvars.items()}
allshortnames = {sn : list(sorted(vars)) allshortnames = {sn : list(sorted(vars))
for sn, vars in allshortnames.items()} for sn, vars in allshortnames.items()}
...@@ -261,7 +260,7 @@ class Match(object): ...@@ -261,7 +260,7 @@ class Match(object):
def __repr__(self): def __repr__(self):
"""Returns a string representation of this ``Match``. """ """Returns a string representation of this ``Match``. """
return 'Match({})'.format(self.filename) return 'Match({}) {}'.format(self.filename, self.variables)
def __str__(self): def __str__(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment