Skip to content

Commit

Permalink
Fix path validation
Browse files Browse the repository at this point in the history
  • Loading branch information
birc-aeh committed Sep 20, 2023
1 parent b3ad50c commit 10f29e7
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/gwf/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ class AnonymousTarget:
spec: str = attrs.field(default="")


def _validate_path(instance, attribute, value):
for path in _flatten(value):
_check_path(path)


@attrs.define(eq=False)
class Target:
"""Represents a target.
Expand All @@ -216,7 +221,7 @@ class Target:
foo = Target(
name='foo',
inputs={'A': ['a1', 'a2'], 'B': 'b'},
outputs={'C': ['a1b', 'a2b], 'D': 'd},
outputs={'C': ['a1b', 'a2b'], 'D': 'd'},
)
This is useful for referring the outputs of a target::
Expand Down Expand Up @@ -247,8 +252,8 @@ class Target:
"""

name: str = attrs.field()
inputs: list = attrs.field()
outputs: list = attrs.field()
inputs: list = attrs.field(validator=_validate_path)
outputs: list = attrs.field(validator=_validate_path)
options: dict = attrs.field()
working_dir: str = attrs.field(default=".")
protect: set = attrs.field(factory=set, converter=set)
Expand All @@ -268,12 +273,6 @@ def _validate_name(self, attribute, value):
if not is_valid_name(self.name):
raise GWFError(f"Target defined with invalid name: {value}")

@inputs.validator
@outputs.validator
def _validate_inputs(self, attribute, value):
for path in value:
_check_path(path)

@working_dir.validator
def _validate_working_dir(self, attribute, value):
_check_path(value)
Expand Down

0 comments on commit 10f29e7

Please sign in to comment.