Skip to content

Commit

Permalink
Merge c48fef3 into 6d66bf4
Browse files Browse the repository at this point in the history
  • Loading branch information
mlin committed Jun 13, 2019
2 parents 6d66bf4 + c48fef3 commit f2f1376
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 23 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@
[submodule "tests/bash-tap"]
path = tests/bash-tap
url = https://github.com/illusori/bash-tap.git
[submodule "test_corpi/biowdl/tasks"]
path = test_corpi/biowdl/tasks
url = https://github.com/biowdl/tasks.git
4 changes: 2 additions & 2 deletions WDL/Lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,12 +654,12 @@ def decl(self, obj: WDL.Tree.Decl) -> Any:
if not (
(
isinstance(obj.type, WDL.Type.File)
and sum(1 for sfx in index_suffixes if obj.name.endswith(sfx))
and sum(1 for sfx in index_suffixes if obj.name.lower().endswith(sfx))
)
or (
isinstance(obj.type, WDL.Type.Array)
and isinstance(obj.type.item_type, WDL.Type.File)
and sum(1 for sfx in index_suffixes if obj.name.endswith(sfx))
and sum(1 for sfx in index_suffixes if obj.name.lower().endswith(sfx))
)
or (
isinstance(pt, WDL.Tree.Task)
Expand Down
9 changes: 6 additions & 3 deletions WDL/Tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,8 @@ def typecheck(self, doc: TVDocument, check_quant: bool) -> None:
# 5. typecheck the output expressions
if self.outputs:
output_names = set()
output_type_env = self._type_env
assert output_type_env
for output in self.outputs:
assert output.expr
if output.name in output_names:
Expand All @@ -835,10 +837,11 @@ def typecheck(self, doc: TVDocument, check_quant: bool) -> None:
)
errors.try1(
lambda output=output: output.typecheck(
self._type_env, check_quant=check_quant
output_type_env, check_quant=check_quant
)
)
output_names.add(output.name)
output_type_env = Env.bind(output_type_env, [], output.name, output.type)
# 6. check for cyclic dependencies
WDL._util.detect_cycles(_dependency_matrix(_decls_and_calls(self))) # pyre-fixme

Expand Down Expand Up @@ -1387,7 +1390,7 @@ def _resolve_struct_typedef(
try:
struct_typedef = Env.resolve(struct_typedefs, [], ty.type_name)
except KeyError:
raise Err.InvalidType(pos, "Unknown type " + ty.type_name)
raise Err.InvalidType(pos, "Unknown type " + ty.type_name) from None
ty.members = struct_typedef.members


Expand Down Expand Up @@ -1418,7 +1421,7 @@ def _initialize_struct_typedefs(struct_typedefs: Env.StructTypeDefs):
try:
_resolve_struct_typedefs(b.rhs.pos, member_ty, struct_typedefs)
except StopIteration:
raise Err.CircularDependencies(b.rhs)
raise Err.CircularDependencies(b.rhs) from None


def _add_struct_instance_to_type_env(
Expand Down
33 changes: 16 additions & 17 deletions WDL/_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,12 @@
// WDL tasks
input_decls: "input" "{" any_decl* "}"
output_decls: "output" "{" bound_decl* "}"
?task_sections1: input_decls
| output_decls
| meta_section
| runtime_section
| any_decl+ -> noninput_decls
?task_sections2: input_decls
| output_decls
| meta_section
| runtime_section
task: "task" CNAME "{" task_sections1* command task_sections2* "}"
?task_section: input_decls
| output_decls
| meta_section
| runtime_section
| any_decl -> noninput_decl
task: "task" CNAME "{" task_section* command task_section* "}"
tasks: task*
Expand Down Expand Up @@ -262,7 +258,7 @@ def parse(txt: str, start: str, version: Optional[str] = None) -> lark.Tree:
_lark_cache[(version, start)] = lark.Lark(
_grammar_for_version(version), start=start, parser="lalr", propagate_positions=True
)
return _lark_cache[(version, start)].parse(txt)
return _lark_cache[(version, start)].parse(txt + ("\n" if not txt.endswith("\n") else ""))


def sp(filename, meta) -> SourcePosition:
Expand Down Expand Up @@ -484,8 +480,8 @@ def decl(self, items, meta):
def input_decls(self, items, meta):
return {"inputs": items}

def noninput_decls(self, items, meta):
return {"decls": items}
def noninput_decl(self, items, meta):
return {"noninput_decl": items[0]}

def placeholder_option(self, items, meta):
assert len(items) == 2
Expand Down Expand Up @@ -547,15 +543,18 @@ def runtime_section(self, items, meta):
return {"runtime": d}

def task(self, items, meta):
d = {}
d = {"noninput_decls": []}
for item in items:
if isinstance(item, dict):
for k, v in item.items():
if k in d:
if k == "noninput_decl":
d["noninput_decls"].append(v)
elif k in d:
raise Err.MultipleDefinitions(
sp(self.filename, meta), "redundant sections in task"
)
d[k] = v
else:
d[k] = v
else:
assert isinstance(item, str)
assert "name" not in d
Expand All @@ -565,7 +564,7 @@ def task(self, items, meta):
sp(self.filename, meta),
d["name"],
d.get("inputs", None),
d.get("decls", []),
d["noninput_decls"],
d["command"],
d.get("outputs", []),
d.get("parameter_meta", {}),
Expand Down
1 change: 1 addition & 0 deletions test_corpi/biowdl/tasks
Submodule tasks added at 46385d
4 changes: 3 additions & 1 deletion tests/test_1doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1187,7 +1187,9 @@ def test_workflow_inputs(self):
y = y
}
output {
Int z = z
Int z = z+1
Int w = x+y
Array[Int] outs = [z,w]
}
}
"""
Expand Down
13 changes: 13 additions & 0 deletions tests/test_3corpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,16 @@ class Contrived(unittest.TestCase):
)
class Contrived2(unittest.TestCase):
pass

@test_corpus(
["test_corpi/biowdl/tasks/**"],
expected_lint={'OptionalCoercion': 4, 'NonemptyCoercion': 1, 'UnnecessaryQuantifier': 3, 'UnusedDeclaration': 9},
check_quant=False,
blacklist=[
# use Object
"common", "bamstats", "seqstat", "flash", "sampleconfig", "strelka",
"stringtie", "vardict", "manta", "somaticseq", "biopet",
],
)
class BioWDLTasks(unittest.TestCase):
pass

0 comments on commit f2f1376

Please sign in to comment.