-
Notifications
You must be signed in to change notification settings - Fork 2k
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
farmer|rpc: Introduce get_harvesters_summary
RPC endpoint
#11245
farmer|rpc: Introduce get_harvesters_summary
RPC endpoint
#11245
Conversation
e53dedd
to
b2838c8
Compare
counts_only
parameter to get_harvesters
get_harvesters_summary
RPC endpoint
b2838c8
to
a1b737e
Compare
a1b737e
to
d303f5e
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.
Just some thoughts about optional (maybe later) adjustments.
"failed_to_open_filenames": self._invalid, | ||
"no_key_filenames": self._keys_missing, | ||
"duplicates": self._duplicates, | ||
"plots": get_list_or_len(list(self._plots.values()), counts_only), |
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.
Maybe drop the helper function?
"plots": get_list_or_len(list(self._plots.values()), counts_only), | |
"plots": len(self._plots) if counts_only else list(self._plots.values())), |
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.
Look at the tests, imagine how it looks if i write it explicitly everywhere and tell me again if you really want to drop it :)
@@ -68,3 +71,7 @@ def prompt_yes_no(prompt: str = "(y/n) ") -> bool: | |||
return True | |||
elif ch == "n": | |||
return False | |||
|
|||
|
|||
def get_list_or_len(list_in: Sequence[object], length: bool) -> Union[int, Sequence[object]]: |
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 think Collection
is sufficient here to get the len()
ability. Also, that should be a TypeVar
to indicate that the output type is the same as the input type. Also, also, with typing_extensions.Literal
for True
and False
we could skip the Union
and use overloads to express which thing will come out based on the length
parameter.
def get_list_or_len(list_in: Sequence[object], length: bool) -> Union[int, Sequence[object]]: | |
def get_list_or_len(list_in: Collection[object], length: bool) -> Union[int, Collection[object]]: |
Or we could delete this as use the ternary directly when needed. :]
@@ -102,8 +103,9 @@ async def test_get_routes(harvester_farmer_environment): | |||
await validate_get_routes(harvester_rpc_client, harvester_rpc_api) | |||
|
|||
|
|||
@pytest.mark.parametrize("endpoint", ["get_harvesters", "get_harvesters_summary"]) |
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.
Could be FarmerRpcApi.get_harvesters
instead of strings and getattr()
below. (or whatever the proper class is) Then you endpoint(instance, parameters)
to call it and pass the instance into self
.
This will be later used by the GUI as part of the GUI improvements to support large farms.