-
Notifications
You must be signed in to change notification settings - Fork 191
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
Fix interactive and conditional options in click #1666
Conversation
Click uses the timestamp to see if the file has been modified in `click.edit()` but on some filesystems the timestamp has a precision of 1 second
to comply with the logic we expect. Tests have also been adapted as they were not always correct. Also, tests on empty_ok substituted with tests on empty string defaults as empty_ok has been removed from the code.
…k that all parameters passed to a builder are used.
E.g. when a previous option decides if the option should be printed or not Also fixed the tests. NOTE: if the wrong number of interactive options is passed in a test, this will enter an infinite loop and will hang the tests! To decide if we want to have a way to prevent this (e.g. a max_prompt_count variable?)
@sphuber @ltalirz I think the hanging in my case was due to an infinite loop in the prompt for interactive inputs in |
because now the 'verdi node description' was getting by default -D "" and therefore was setting an empty string rather than getting the current description
Codecov Report
@@ Coverage Diff @@
## verdi #1666 +/- ##
========================================
+ Coverage 60.2% 60.2% +<.01%
========================================
Files 294 297 +3
Lines 34065 34091 +26
========================================
+ Hits 20509 20526 +17
- Misses 13556 13565 +9
Continue to review full report at Codecov.
|
os.environ['VISUAL'] = 'vim -cwq' | ||
os.environ['EDITOR'] = 'vim -cwq' | ||
os.environ['VISUAL'] = 'sleep 1; vim -cwq' | ||
os.environ['EDITOR'] = 'sleep 1; vim -cwq' |
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.
since time is of the essence for unit tests, what about sleep 0.1
?
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.
Unfortunately the time precision on my Mac is 1 second, so a time >=1s is needed... Of course better approaches are accepted (even if probably they should become fixes to click.edit()
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 a PR pallets/click#1050 at click to fix this.
Once merged and released we can
- remove the
sleep 1
- I would also substitute
vim
withsed
(slimmer, no "window" open, ...) as I did in that PR
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.
vim was chosen because it is a file editor and therefore closer to the intended usage than the stream editor sed. Since this test turned out to be fragile, I agree that maybe sed is a better compromise between test reliability and testing the right thing.
Are there any particular things you want us to look at? |
@ltalirz not really, probably only if you are happy with the new (slightly changed) behaviour of the InteractiveOption (should be more consistent with click default behaviour and require less custom code) as tested by the tests, the removal of the |
Thanks for pointing this out. |
In most cases I think they should also go together.
I think the two should remain separate as concepts. Some usecases where the two might differ:
|
param_decls=None, | ||
switch=None, # | ||
prompt_fn=None, | ||
# empty_ok=False, |
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.
Probably best to remove the commented line and trailing comment character
@giovannipizzi Fine with the implementation, just put your explanations (and also the examples where they might differ) somewhere where one can find them |
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.
Minor comments, but looks good otherwise
|
||
# super | ||
# call super |
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 important to explain why we call super and why here than maybe we should write that as a comment. As it stands it is not very informative and I would remove it
As required in the comments of #1666, and also fixed a couple of other minor things required in the comments (mainly about comments)
@ltalirz this lays the needed classes to implement Note to be careful if you change the command, as tests might hang if you change the order/validation/number of parameters (see my previous comment). |
This should have been squashed and merged, not normally merged. Now we have a bunch of non-sensical commits in the branch. Please let's use squash properly when we can use it |
Sorry, you are right, I clicked on merge out of habit... |
|
||
# help option was passed on the cmdline | ||
if ctx.params.get('help'): | ||
return self.after_callback(ctx, param, value) |
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.
Is it tested somewhere that removing this never causes an InteractiveOption to enter the prompt loop before --help
gets processed?
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 it wasn't tested before, then no. It wasn't clear to me the purpose of that logic. Please feel free to add a test for what you have in mind.
code.set_prepend_text(self.prepend_text) | ||
code.set_append_text(self.append_text) | ||
# Complain if there are keys that are passed but not used | ||
if passed_keys - used: |
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 addition of this check it becomes necessary to be able to remove the additional keys.
Usecase:
ipython >> builder = CodeBuilder()
ipython >> builder.label = ...
# ... lines and lines of generating and adding the other keys
ipython >> builder.extraneous_key = ...
ipython >> builder.new()
CodeValidationError ...
ipython >> # Now the builder object that has been prepared in arduous work has become useless
ipython >> # And we need to start from scratch!
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 will turn this into an issue, seeing as the commit has already been merged.
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.
thanks.
I think it's just a matter of implementing __del__
for attributes and forwarding the del
call to the internal dictionary?
to comply with the expected behaviour, now also tested.