-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: check not None path on datasamplespec #395
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -146,6 +146,30 @@ class DataSampleSpec(_Spec): | |||||||||||||||
def is_many(self): | ||||||||||||||||
return self.paths and len(self.paths) > 0 | ||||||||||||||||
|
||||||||||||||||
@pydantic.field_validator("paths") | ||||||||||||||||
@classmethod | ||||||||||||||||
def resolve_paths(cls, v: typing.Any) -> typing.Any: | ||||||||||||||||
"""Resolve given paths.""" | ||||||||||||||||
if v is None: | ||||||||||||||||
raise ValueError("'paths' cannot be set to None.") | ||||||||||||||||
|
||||||||||||||||
paths = [] | ||||||||||||||||
for path in v: | ||||||||||||||||
path = pathlib.Path(path) | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
pydantic already casts str to path when using the type There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh I didn't knew ! So nice... |
||||||||||||||||
paths.append(path.resolve()) | ||||||||||||||||
|
||||||||||||||||
return paths | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick: style change, you can disregard
Suggested change
|
||||||||||||||||
|
||||||||||||||||
@pydantic.field_validator("path") | ||||||||||||||||
@classmethod | ||||||||||||||||
def resolve_path(cls, v: typing.Any) -> typing.Any: | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
"""Resolve given path.""" | ||||||||||||||||
if v is None: | ||||||||||||||||
raise ValueError("'path' cannot be set to None.") | ||||||||||||||||
|
||||||||||||||||
path = pathlib.Path(v) | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
return path.resolve() | ||||||||||||||||
|
||||||||||||||||
@pydantic.model_validator(mode="before") | ||||||||||||||||
@classmethod | ||||||||||||||||
def exclusive_paths(cls, values: typing.Any) -> typing.Any: | ||||||||||||||||
|
@@ -156,24 +180,6 @@ def exclusive_paths(cls, values: typing.Any) -> typing.Any: | |||||||||||||||
raise ValueError("'path' or 'paths' field must be set.") | ||||||||||||||||
return values | ||||||||||||||||
|
||||||||||||||||
@pydantic.model_validator(mode="before") | ||||||||||||||||
@classmethod | ||||||||||||||||
def resolve_paths(cls, values: typing.Any) -> typing.Any: | ||||||||||||||||
"""Resolve given path is relative.""" | ||||||||||||||||
if "paths" in values: | ||||||||||||||||
paths = [] | ||||||||||||||||
for path in values["paths"]: | ||||||||||||||||
path = pathlib.Path(path) | ||||||||||||||||
paths.append(path.resolve()) | ||||||||||||||||
|
||||||||||||||||
values["paths"] = paths | ||||||||||||||||
|
||||||||||||||||
elif "path" in values: | ||||||||||||||||
path = pathlib.Path(values["path"]) | ||||||||||||||||
values["path"] = path.resolve() | ||||||||||||||||
|
||||||||||||||||
return values | ||||||||||||||||
|
||||||||||||||||
@contextlib.contextmanager | ||||||||||||||||
def build_request_kwargs(self, local): | ||||||||||||||||
# redefine kwargs builder to handle the local paths | ||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh great. And I removed the "optional" in that case, as, if the field is specified, this is not optional anymore to have a path. WDT ?