Merge lp:~mbp/bzr/ui-factory into lp:bzr
| Status: | Merged | ||||
|---|---|---|---|---|---|
| Approved by: | Vincent Ladeuil on 2010-09-14 | ||||
| Approved revision: | 5426 | ||||
| Merged at revision: | 5426 | ||||
| Proposed branch: | lp:~mbp/bzr/ui-factory | ||||
| Merge into: | lp:bzr | ||||
| Diff against target: |
397 lines (+211/-19) 8 files modified
bzrlib/builtins.py (+5/-2) bzrlib/lockdir.py (+3/-1) bzrlib/msgeditor.py (+4/-2) bzrlib/tests/blackbox/test_uncommit.py (+18/-1) bzrlib/tests/per_uifactory/__init__.py (+23/-0) bzrlib/tests/test_ui.py (+53/-9) bzrlib/ui/__init__.py (+68/-1) doc/developers/ui.txt (+37/-3) |
||||
| To merge this branch: | bzr merge lp:~mbp/bzr/ui-factory | ||||
| Related bugs: |
|
| Reviewer | Review Type | Date Requested | Status |
|---|---|---|---|
| Vincent Ladeuil | 2010-09-13 | Approve on 2010-09-14 | |
| Andrew Bennetts | 2010-09-09 | Needs Fixing on 2010-09-13 | |
|
Review via email:
|
|||
Commit Message
add structured confirmations to the ui_factory
Description of the Change
This is a start towards letting the ui factory know at a more abstract level "we're asking for user confirmation."
This should let us do a few things:
* systematically skip them when in noninteractive mode
* let users configure particular confirmations on and off
* possibly better test them
* perhaps present the messages differently in guis
Before landing I want to update the callers but I'd appreciate feedback now on the api.
| Vincent Ladeuil (vila) wrote : | # |
| Martin Pool (mbp) wrote : | # |
On 10 September 2010 02:19, Vincent Ladeuil <email address hidden> wrote:
> 117 + def confirm_
>
> s/args/kwargs/
>
> or even **kwargs like the others, there should be a way to make
> this compatible with 'default=True' (which isn't documented nor
> used by the way).
Thanks for the speedy review.
At the moment I really dislike using **kwargs as shorthand for a dict
to be passed to lower level code, eg to be passed in to string
interpolating. It makes things slightly easier on the caller it's
true, but it also tends to break by clashing with other arguments used
either at this level or in different implementations or as the code
changes later on.
> Oh wait, yes it *is* used in other implementations, ok.
>
> Hmm, I think that 'confirm' already implies that the default is
> True so this may be useless. Do you have a use case for
> default=False ?
That would imply an operation where we want confirmation from a user
and we won't proceed in non-interactive mode, which is conceivable but
unlikely. So perhaps I should just delete it.
>
> Adding confirm_action to uis sounds like a good idea, but this
> needs to be discussed with the qbzr/bzr-gtk people since they
> need a way to override it without calling get_boolean for which
> they probably also defines aspecific version...
>
> This may not be a bzrlib problem though...
I'll cc them and they may have a thought.
> As mentionned on IRC, I like the direction this is taking
> regarding make_test_
> fixture independent from the test itself.
>
> Regarding 'bzr.lock.
> arbitrary name space but sticking to the python module name space
> may be better suited in the long term (easier to discover and to maintain).
So bzrlib.
> Now, reagrding the relationships with config variables, we
> can (hypothetically):
>
> - define an alias between bzr and bzrlib or
> bzr.lock.
> even simpler, between bzrlib.
>
> - define (handwaving) a config var as bzrlib.
> and import it in bzrlib.lockdir
>
> Or any combination.
>
> Anyway, I now better understand what you mean for the application
> code and indeed this looks nice.
>
> Making the confirm_action implementation access the relevant
> config from the ID may still be a big tricky though (wt, branch
> ?).
>
> This may be addressed by setting some config attribute to the ui
> though... unless we need the context manager for that...
Interesting point. istm that you might want per-context configuration
to affect the ui in more than just confirmations...
So is the overall vote here 'tweak, plus check with gui maintainers,
plus update the other callers'?
--
Martin
| Vincent Ladeuil (vila) wrote : | # |
>>>>> Martin Pool <email address hidden> writes:
> On 10 September 2010 02:19, Vincent Ladeuil <email address hidden> wrote:
>> 117 + def confirm_
>>
>> s/args/kwargs/
>>
>> or even **kwargs like the others, there should be a way to make
>> this compatible with 'default=True' (which isn't documented nor
>> used by the way).
> Thanks for the speedy review.
> At the moment I really dislike using **kwargs as shorthand for a dict
> to be passed to lower level code, eg to be passed in to string
> interpolating. It makes things slightly easier on the caller it's
> true, but it also tends to break by clashing with other arguments used
> either at this level or in different implementations or as the code
> changes later on.
I see. Well, turning the callerrs x=2, y=3 into dict(x=2, y=3) won't
such a problem. But in this case, the migration from one to the other
should occur sooner rather than later, keeping different idioms in the
code base... is painful in the long run.
>> Oh wait, yes it *is* used in other implementations, ok.
>>
>> Hmm, I think that 'confirm' already implies that the default is
>> True so this may be useless. Do you have a use case for
>> default=False ?
> That would imply an operation where we want confirmation from a user
> and we won't proceed in non-interactive mode, which is conceivable but
> unlikely. So perhaps I should just delete it.
Then we could introduce deny_action when needed ?
>>
>> Adding confirm_action to uis sounds like a good idea, but this
>> needs to be discussed with the qbzr/bzr-gtk people since they
>> need a way to override it without calling get_boolean for which
>> they probably also defines aspecific version...
>>
>> This may not be a bzrlib problem though...
> I'll cc them and they may have a thought.
>> As mentionned on IRC, I like the direction this is taking
>> regarding make_test_
>> fixture independent from the test itself.
>>
>> Regarding 'bzr.lock.
>> arbitrary name space but sticking to the python module name space
>> may be better suited in the long term (easier to discover and to maintain).
> So bzrlib.
At least internally, but the caller itself may use an aliased form.
>> Now, reagrding the relationships with config variables, we
>> can (hypothetically):
>>
>> - define an alias between bzr and bzrlib or
>> bzr.lock.
>> even simpler, between bzrlib.
>>
>> - define (handwaving) a config var as bzrlib.
>> and import it in bzrlib.lockdir
>>
>> Or any combination.
>>
>> Anyway, I now better understand what you mean for the application
>> code and indeed this looks nice.
>>
>> Making the confirm_action implementation access the relevant
>> config from the ID may still be a big...
- 5418. By Martin Pool on 2010-09-10
-
Remove 'default' parameter from confirm_action
The noninteractive default is to always confirm - 5419. By Martin Pool on 2010-09-10
-
merge trunk
- 5420. By Martin Pool on 2010-09-10
-
Brief developer guide entry about confirmations
| Vincent Ladeuil (vila) wrote : | # |
116 + def confirm_
Grr, sorry to notice this so late, but isn't:
confirm_
more explicit (your docstring and dev doc focuses on the confirmation_id
which is also a good hint) ?
I.e. the confirmation id, followed by the prompt and its args ?
And regarding check with gui maintainers, yes.
| Martin Pool (mbp) wrote : | # |
> > At the moment I really dislike using **kwargs as shorthand for a dict
> > to be passed to lower level code, eg to be passed in to string
> > interpolating. It makes things slightly easier on the caller it's
> > true, but it also tends to break by clashing with other arguments used
> > either at this level or in different implementations or as the code
> > changes later on.
>
> I see. Well, turning the callerrs x=2, y=3 into dict(x=2, y=3) won't
> such a problem. But in this case, the migration from one to the other
> should occur sooner rather than later, keeping different idioms in the
> code base... is painful in the long run.
If you're talking about going back to clean up all existing cases like this, then it is a bit painful. I think not adding any more of them is worthwhile.
I think the coding guideline would be, don't mix kwargs where the caller could want provide any arbitrary value with other parameters. Use kwargs only for metaprogramming. Perhaps this is too harsh and needlessly closes off a useful tool though.
> >> Oh wait, yes it *is* used in other implementations, ok.
> >>
> >> Hmm, I think that 'confirm' already implies that the default is
> >> True so this may be useless. Do you have a use case for
> >> default=False ?
>
> > That would imply an operation where we want confirmation from a user
> > and we won't proceed in non-interactive mode, which is conceivable but
> > unlikely. So perhaps I should just delete it.
>
> Then we could introduce deny_action when needed ?
If we think we'll want it, perhaps we should keep the option now?
> > So bzrlib.
>
> At least internally, but the caller itself may use an aliased form.
I think having aliases for this might just cause confusion. My updated branch shows some suggested names.
| Gary van der Merwe (garyvdm) wrote : | # |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 09/09/2010 18:19, Vincent Ladeuil wrote:
> Adding confirm_action to uis sounds like a good idea, but this
> needs to be discussed with the qbzr/bzr-gtk people since they
> need a way to override it without calling get_boolean for which
> they probably also defines aspecific version...
The patch seems cool to me. I can override both got_boolean, and
confirm_action. It would be be cool if confirm_action showed a dialog
with a "Don't ask me this again." checkbox.
review:approve
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://
iEYEARECAAYFAky
NrEAnivrpxukezT
=MM58
-----END PGP SIGNATURE-----
| Vincent Ladeuil (vila) wrote : | # |
>>>>> Martin Pool <email address hidden> writes:
>> > At the moment I really dislike using **kwargs as shorthand for a dict
>> > to be passed to lower level code, eg to be passed in to string
>> > interpolating. It makes things slightly easier on the caller it's
>> > true, but it also tends to break by clashing with other arguments used
>> > either at this level or in different implementations or as the code
>> > changes later on.
>>
>> I see. Well, turning the callerrs x=2, y=3 into dict(x=2, y=3) won't
>> such a problem. But in this case, the migration from one to the other
>> should occur sooner rather than later, keeping different idioms in the
>> code base... is painful in the long run.
> If you're talking about going back to clean up all existing cases
> like this, then it is a bit painful. I think not adding any more
> of them is worthwhile.
It will be painful *once*, but less painful for new contributors that
won't wonder which one to use, for reviewers who won't have to say "you
picked the wrong one", etc. Just saying ;)
<snip/>
>> > That would imply an operation where we want confirmation from a user
>> > and we won't proceed in non-interactive mode, which is conceivable but
>> > unlikely. So perhaps I should just delete it.
>>
>> Then we could introduce deny_action when needed ?
> If we think we'll want it, perhaps we should keep the option now?
confirm_
deny_action()...
>> > So bzrlib.
>>
>> At least internally, but the caller itself may use an aliased form.
> I think having aliases for this might just cause confusion. My
> updated branch shows some suggested names.
Could be, let's see how it's used (but we already have many conf vars
that could benefit to be associated with a python name and then we'll
have to ensure backward compatibility anyway).
| Martin Pool (mbp) wrote : | # |
On 10 September 2010 18:43, Vincent Ladeuil <email address hidden> wrote:
>>>>>> Martin Pool <email address hidden> writes:
>
> >> > At the moment I really dislike using **kwargs as shorthand for a dict
> >> > to be passed to lower level code, eg to be passed in to string
> >> > interpolating. It makes things slightly easier on the caller it's
> >> > true, but it also tends to break by clashing with other arguments used
> >> > either at this level or in different implementations or as the code
> >> > changes later on.
> >>
> >> I see. Well, turning the callerrs x=2, y=3 into dict(x=2, y=3) won't
> >> such a problem. But in this case, the migration from one to the other
> >> should occur sooner rather than later, keeping different idioms in the
> >> code base... is painful in the long run.
>
> > If you're talking about going back to clean up all existing cases
> > like this, then it is a bit painful. I think not adding any more
> > of them is worthwhile.
>
> It will be painful *once*, but less painful for new contributors that
> won't wonder which one to use, for reviewers who won't have to say "you
> picked the wrong one", etc. Just saying ;)
Let's see if we can work out a clear expression of the code guideline.
I don't want to ban kwargs altogether, but I think it's bad to
promise people can pass arbitrary dicts through to a lower level (eg a
format string), when the function also takes other arguments. You
should instead pass a dict.
--
Martin
| Andrew Bennetts (spiv) wrote : | # |
Regarding this patch: I'm in favour of it. There's a nit that default=True still exists in the signature of one of the implementations, so Needs Fixing.
I'm not worried about the slight inconvenience of an explicit dict rather than **kwargs. There just aren't enough places where we ask users to confirm an action for this to be a big issue. And I do like the explicit separation of function params vs. string interpolation params.
Regarding the general guidelines for kwargs: I think it should be used sparingly. I think it can be good when a function is delegating largely to another callable (e.g. it is some sort of higher order function, like TestCase.
I guess a short rule-of-thumb is: be wary of any **kwargs that aren't accompanied by a param called 'callable'.
- 5421. By Martin Pool on 2010-09-10
-
Add list of confirmation ids
| Martin Pool (mbp) wrote : | # |
thanks, I folded that text in to
https:/
- 5422. By Martin Pool on 2010-09-10
-
Change 'uncommit' command to use confirm_action not get_boolean
- 5423. By Martin Pool on 2010-09-13
-
Merge ScriptRunner interaction support
- 5424. By Martin Pool on 2010-09-13
-
Merge additional fixes for blank lines in scripts
- 5425. By Martin Pool on 2010-09-13
-
Add a test that uncommit confirms its action
- 5426. By Martin Pool on 2010-09-13
-
Use confirm_action before proceeding with an unedited commit message template
| Martin Pool (mbp) wrote : | # |
This now fixes up all the immediately obvious callers of get_boolean.
We could do more as far as configuration etc but I think it's good to land.
- 5427. By Martin Pool on 2010-09-14
-
Add ConfirmationUse
rInterfacePolic y that lets specific confirmations be configured off.
| Martin Pool (mbp) wrote : | # |
sent to pqm by email
| Martin Pool (mbp) wrote : | # |
sent to pqm by email
- 5428. By Martin Pool on 2010-09-15
-
Tweak uncommit doctest for python 2.4
| Martin Pool (mbp) wrote : | # |
sent to pqm by email
- 5429. By Martin Pool on 2010-09-15
-
merge trunk
| Martin Pool (mbp) wrote : | # |
sent to pqm by email

117 + def confirm_ action( self, prompt, confirmation_id, args, default=True):
s/args/kwargs/
or even **kwargs like the others, there should be a way to make
this compatible with 'default=True' (which isn't documented nor
used by the way).
Oh wait, yes it *is* used in other implementations, ok.
Hmm, I think that 'confirm' already implies that the default is
True so this may be useless. Do you have a use case for
default=False ?
Adding confirm_action to uis sounds like a good idea, but this
needs to be discussed with the qbzr/bzr-gtk people since they
need a way to override it without calling get_boolean for which
they probably also defines aspecific version...
This may not be a bzrlib problem though...
As mentionned on IRC, I like the direction this is taking ui_factory being a good step towards a
regarding make_test_
fixture independent from the test itself.
Regarding 'bzr.lock. break.confirm' , I'm fine with using an
arbitrary name space but sticking to the python module name space
may be better suited in the long term (easier to discover and to maintain).
Now, reagrding the relationships with config variables, we
can (hypothetically):
- define an alias between bzr and bzrlib or break.confirm and bzrlib. lock.confirm_ break or, lock.confirm_ break and confirm_break_lock
bzr.lock.
even simpler, between bzrlib.
- define (handwaving) a config var as bzrlib. lock.confirm_ break
and import it in bzrlib.lockdir
Or any combination.
Anyway, I now better understand what you mean for the application
code and indeed this looks nice.
Making the confirm_action implementation access the relevant
config from the ID may still be a big tricky though (wt, branch
?).
This may be addressed by setting some config attribute to the ui
though... unless we need the context manager for that...