Skip to content
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

[cli] Add prompt command for CLI logger. #9897

Merged
merged 5 commits into from
Aug 31, 2020

Conversation

robertnishihara
Copy link
Collaborator

Similar to cli_logger.confirm, but instead this allows arbitrary string answers. I haven't touched this class before, so this should be reviewed carefully. Also, it probably could be made more colorful.

@AmplabJenkins
Copy link

Can one of the admins verify this patch?

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/29354/
Test FAILed.

Copy link
Contributor

@maximsmol maximsmol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a great addition! I left some comments, most very small changes.

One thing I want to add is that confirm currently aligns user input, so that it starts at the same horizontal position without re-printing the message (it just prints a bunch of spaces in place of the message). I'm not sure if prompt should do the same, but it's certainly worth noting.

python/ray/autoscaler/cli_logger.py Outdated Show resolved Hide resolved

complete_str = cf.underlined(msg + ":") + " "

self._print(complete_str, linefeed=False)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see we need linefeed=False here so we couldn't just use print. The downside is that we have to call _format_msg(msg, *args, **kwargs) ourselves since _print does not format the message it prints.

python/ray/autoscaler/cli_logger.py Outdated Show resolved Hide resolved
ans = ans.strip()
except KeyboardInterrupt:
self.newline()
res = default
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default is undefined as far as I can see. confirm gets it from the _default keyword argument.

It might be a good idea to drop defaults completely, by returning "" both when the user presses "enter" with no input and when the user "^C"s.

Otherwise, we should display the default value somehow, but very long defaults will be a problem.

P.S.
I am actually leaning towards having an optional _default parameter, so if there is a default with prompt we don't forget to print it, but if there is not one we should keep asking until we get user input.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left this as is. I don't feel strongly about this, but in a lot of cases, validating the input will be more complex than just checking if it's an empty string or not (e.g., maybe it needs to be an int or something), so either we would need to pass in a lambda for validation or we should do the validation outside of the prompt function. So I left it as is for now.

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/29451/
Test FAILed.

@rkooo567 rkooo567 added @author-action-required The PR author is responsible for the next step. Remove tag to send back to the reviewer. and removed @author-action-required The PR author is responsible for the next step. Remove tag to send back to the reviewer. labels Aug 23, 2020
@richardliaw richardliaw added the @author-action-required The PR author is responsible for the next step. Remove tag to send back to the reviewer. label Aug 31, 2020
@richardliaw richardliaw changed the title Add prompt command for CLI logger. [cli] Add prompt command for CLI logger. Aug 31, 2020
@richardliaw richardliaw merged commit 0bba548 into ray-project:master Aug 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@author-action-required The PR author is responsible for the next step. Remove tag to send back to the reviewer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants