-
Notifications
You must be signed in to change notification settings - Fork 6
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
Port dapp-runner
to pydantic
#100
Conversation
372bd38
to
b7e1752
Compare
b7e1752
to
3e8009c
Compare
dapp_runner/descriptor/dapp.py
Outdated
p = v.split(":") | ||
return {"remote_port": p.pop(), "local_port": p.pop() if p else None} |
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.
Using p.pop()
in this way requires way more attention, that it should... I would use more simple approach.
p = v.split(":") | |
return {"remote_port": p.pop(), "local_port": p.pop() if p else None} | |
p = v.split(":") | |
return { | |
"remote_port": p[0], | |
"local_port": p[1] if 2 <= len(p) else None, | |
} |
Also, regex should enforce pattern of %d[:%d]
.
pyproject.toml
Outdated
_tests_integration_env = "python -m venv .envs/goth" | ||
_tests_integration_requirements = ".envs/goth/bin/pip install --extra-index-url https://test.pypi.org/simple/ goth==0.14.1 pytest pytest-asyncio pexpect" | ||
_tests_integration_assets = ".envs/goth/bin/python -m goth create-assets tests/goth_tests/assets" | ||
tests_integration_init = ["_tests_integration_env", "_tests_integration_requirements", "_tests_integration_assets"] |
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.
To be consistent with other tasks.
_tests_integration_env = "python -m venv .envs/goth" | |
_tests_integration_requirements = ".envs/goth/bin/pip install --extra-index-url https://test.pypi.org/simple/ goth==0.14.1 pytest pytest-asyncio pexpect" | |
_tests_integration_assets = ".envs/goth/bin/python -m goth create-assets tests/goth_tests/assets" | |
tests_integration_init = ["_tests_integration_env", "_tests_integration_requirements", "_tests_integration_assets"] | |
tests_integration_init = ["_tests_integration_env", "_tests_integration_requirements", "_tests_integration_assets"] | |
_tests_integration_env = "python -m venv .envs/goth" | |
_tests_integration_requirements = ".envs/goth/bin/pip install --extra-index-url https://test.pypi.org/simple/ goth==0.14.1 pytest pytest-asyncio pexpect" | |
_tests_integration_assets = ".envs/goth/bin/python -m goth create-assets tests/goth_tests/assets" |
As diff looks terrible, the intention is to have parent task first, then children tasks.
dapp_runner/descriptor/dapp.py
Outdated
extra = "forbid" | ||
|
||
@validator("ports", pre=True, each_item=True) | ||
def __ports_preprocess(cls, v): |
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.
Name is not consistent with __field_name__action
.
dapp_runner/descriptor/dapp.py
Outdated
class SocketProxyDescriptor(ProxyDescriptor): | ||
"""TCP socket proxy descriptor.""" | ||
|
||
|
||
@dataclass | ||
class CommandDescriptor: | ||
def parse_command_descriptor(value: Union[str, List, Dict]): |
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.
Consider moving to classmethod of CommandDescriptor
.
dapp_runner/descriptor/dapp.py
Outdated
@dataclass | ||
class NetworkDescriptor(BaseDescriptor["NetworkDescriptor"]): | ||
@validator("init", pre=True) | ||
def __init_commands(cls, v): |
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.
Name is not consistent with __field_name__action
.
dapp_runner/descriptor/dapp.py
Outdated
class NetworkDescriptor(BaseDescriptor["NetworkDescriptor"]): | ||
@validator("init", pre=True) | ||
def __init_commands(cls, v): | ||
if len(v) > 0 and isinstance(v[0], str): |
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.
if len(v) > 0 and isinstance(v[0], str): | |
if len(v) and isinstance(v[0], str): |
self.__validate_nodes() | ||
self.__implicit_proxy_init() | ||
self.__implicit_vpn() | ||
self.__implicit_manifest_support() | ||
self._resolve_dependencies() |
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.
As this works, it could escape few behaviors as pydantic's author mentioned. This looks like not so complicated logic that could be implemented in pydantic's per-field validators. Also, back in my pydantic-like DTOs I've moved default values from parent models down to it's children. In result, I got simpler parent models. Consider similar approach for.
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.
as mentioned on a call, these checks are not per-field and cannot be moved to the children
048e410
to
6980a04
Compare
dapp_runner/descriptor/dapp.py
Outdated
m = re.match("^((\\d+)\\:)?(\\d+)$", v) | ||
if not m: | ||
raise ValueError("Expected format: `remote_port` or `remote_port:local_port`.") | ||
|
||
return {"remote_port": m.group(3), "local_port": m.group(2) if m.group(2) else None} |
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.
Looks like this regex can be improved.
m = re.match("^((\\d+)\\:)?(\\d+)$", v) | |
if not m: | |
raise ValueError("Expected format: `remote_port` or `remote_port:local_port`.") | |
return {"remote_port": m.group(3), "local_port": m.group(2) if m.group(2) else None} | |
m = re.match(r"^(?P<remote_port>\d+)(?::(?P<local_port>\d+))?$", v) | |
if not m: | |
raise ValueError("Expected format: `remote_port` or `remote_port:local_port`.") | |
return m.groupdict(} |
cabe001
to
ea2769c
Compare
dapp-runner
itselfBaseDescriptor
DappDescriptor
and its containing classes to pydanticConfigDescriptor
and its containing classes to pydantic