-
Notifications
You must be signed in to change notification settings - Fork 13
Simplify the command type #183
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
Conversation
9784ea0 to
05850cc
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #183 +/- ##
==========================================
- Coverage 83.26% 83.25% -0.02%
==========================================
Files 35 35
Lines 3705 3702 -3
==========================================
- Hits 3085 3082 -3
Misses 620 620
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
05850cc to
3a49fbe
Compare
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.
Before I continue reviewing, it doesn't seem to pass these simple tests:
def test_empty_command() -> None:
command = fieldtypes.command()
assert command.executable == None
assert command.args == None
def test_empty_string_command() -> None:
command = fieldtypes.command("")
assert command.executable == ""
assert command.args == []Would error with:
flow/record/fieldtypes/__init__.py:766: in __init__
self.executable, self.args = self._split(self._raw)
^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = (executable=None, args=None), value = ''
def _split(self, value: str) -> tuple[path, list[str]]:
> executable, *args = shlex.split(value, posix=self._posix)
^^^^^^^^^^^^^^^^^
E ValueError: not enough values to unpack (expected at least 1, got 0)
Also i'm not sure if my asserts would match with what one would expect. That is up for debate.
Seems i forgot to add those simple tests, added them now
I don't think I'd expect everything to be |
4a1a0cb to
3b32ade
Compare
9acd2b0 to
79a8256
Compare
79a8256 to
ed5187c
Compare
ed5187c to
7361ec0
Compare
yunzheng
left a comment
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.
I made some slight changes.
There is one thing though, it's that command.args is mutable.
But when you mutate it and pack/serialize it again, it's not taken into account. So not sure if it should be a tuple or fix it that it works correctly.
Probably should be a tuple then? |
I think that would be better indeed. @Miauwkeru can you make it so? |
I changed it to a tuple |
Thanks, the attributes are still settable though, for instance you can do: cmd.executable = "cat"
cmd.args = ("hello.txt",)Which works, but does not serialize/deserialize properly when writing the record. Maybe it's also better to make |
|
Is this PR still in progress? |
kept the from_windows and from_posix classmethods to enforce the path type
Co-authored-by: Yun Zheng Hu <[email protected]>
* Move the `str` type check into __init__ * Make the command value explicity `str` type. So cannot be initialized using None * mark `path_type` keyword argument only for clarity
0da2c1f to
97b10c3
Compare
97b10c3 to
c7994de
Compare
| _path_type = posix_path | ||
| @executable.setter | ||
| def executable(self, val: str | path | None) -> None: | ||
| self.__executable = self.__path_type(val) |
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.
with the latest merged PR #200 we should be able to directly initialize path with the value to determine the correct path type. Then you can als get rid of __path_type.
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.
Do you mean removing the whole __path_type in general? As in that case, there will be issues with for example hello_world.exe that will be interpreted differently depending on what system it gets run on.
If you just mean this specific case, this could still be an issue because the whole type can change from windows to posix path and vise versa. Tho I already have an idea on how to fix that specific issue.
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.
ah wait I thought __path_type was a function to determine the path type.
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.
ah, no. It is a type[path], so either a windows_path or a posix_path :)
Instead of changing the behaviour of the adapters to accomodate the command type like in #130
I opt instead to simplify the command type itself and make the structure completely flat.
If we ever want to change how it gets formatted for an adapter, it feels like this should happen at the adapter level
instead of the packing level