Skip to content

Commit

Permalink
trigger FileCoercion lint for Directory
Browse files Browse the repository at this point in the history
  • Loading branch information
mlin committed Sep 3, 2020
1 parent 5b87c33 commit 2e4ee08
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
18 changes: 10 additions & 8 deletions WDL/Lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,11 @@ def _compound_coercion(to_type, from_type, base_to_type, extra_from_type=None):
to_type.right_type, from_type.right_type, base_to_type, extra_from_type
)
if isinstance(to_type, base_to_type):
coercible = list(base_to_type)
if extra_from_type:
return not isinstance(from_type, (base_to_type, extra_from_type, Type.Any))
return not isinstance(from_type, (base_to_type, Type.Any))
coercible.append(extra_from_type)
coercible.append(Type.Any)
return not isinstance(from_type, tuple(coercible))
return False


Expand All @@ -215,7 +217,7 @@ def decl(self, obj: Tree.Decl) -> Any:
if obj.expr and _compound_coercion(
obj.type,
obj.expr.type,
Type.String,
(Type.String,),
(Type.File if isinstance(_parent_executable(obj), Tree.Task) else None),
):
self.add(obj, "{} {} = :{}:".format(str(obj.type), obj.name, str(obj.expr.type)))
Expand Down Expand Up @@ -259,7 +261,7 @@ def expr(self, obj: Expr.Base) -> Any:
if _compound_coercion(
F_i,
arg_i.type,
Type.String,
(Type.String,),
(Type.File if isinstance(_parent_executable(obj), Tree.Task) else None),
):
msg = "{} argument of {}() = :{}:".format(
Expand Down Expand Up @@ -287,7 +289,7 @@ def expr(self, obj: Expr.Base) -> Any:
def call(self, obj: Tree.Call) -> Any:
for name, inp_expr in obj.inputs.items():
decl = _find_input_decl(obj, name)
if _compound_coercion(decl.type, inp_expr.type, Type.String):
if _compound_coercion(decl.type, inp_expr.type, (Type.String,)):
msg = "input {} {} = :{}:".format(str(decl.type), decl.name, str(inp_expr.type))
self.add(obj, msg, inp_expr.pos)

Expand Down Expand Up @@ -316,7 +318,7 @@ def decl(self, obj: Tree.Decl) -> Any:
super().decl(obj)
if (
obj.expr
and _compound_coercion(obj.type, obj.expr.type, Type.File)
and _compound_coercion(obj.type, obj.expr.type, (Type.File, Type.Directory))
and not (
isinstance(obj.expr, Expr.String)
and obj.expr.literal
Expand All @@ -334,7 +336,7 @@ def expr(self, obj: Expr.Base) -> Any:
for i in range(min(len(F.argument_types), len(obj.arguments))):
F_i = F.argument_types[i]
arg_i = obj.arguments[i]
if _compound_coercion(F_i, arg_i.type, Type.File):
if _compound_coercion(F_i, arg_i.type, (Type.File, Type.Directory)):
msg = "{} argument of {}() = :{}:".format(str(F_i), F.name, str(arg_i.type))
self.add(obj, msg, arg_i.pos)
elif obj.function_name == "size":
Expand All @@ -354,7 +356,7 @@ def call(self, obj: Tree.Call) -> Any:
super().call(obj)
for name, inp_expr in obj.inputs.items():
decl = _find_input_decl(obj, name)
if _compound_coercion(decl.type, inp_expr.type, Type.File):
if _compound_coercion(decl.type, inp_expr.type, (Type.File, Type.Directory)):
msg = "input {} {} = :{}:".format(str(decl.type), decl.name, str(inp_expr.type))
self.add(obj, msg, inp_expr.pos)

Expand Down
3 changes: 2 additions & 1 deletion WDL/Value.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,8 @@ def rewrite_env_paths(
env: Env.Bindings[Base], f: Callable[[Union[File, Directory]], str]
) -> Env.Bindings[Base]:
"""
Produce a deep copy of the given Value Env with all File names rewritten by the given function.
Produce a deep copy of the given Value Env with all File & Directory paths rewritten by the
given function.
"""
return env.map(lambda binding: Env.Binding(binding.name, rewrite_paths(binding.value, f)))

Expand Down

0 comments on commit 2e4ee08

Please sign in to comment.