Title: "python cmd --verbose" does not set verbosity
Type: behavior Stage: patch review
Components: Distutils Versions: Python 3.4, Python 3.5, Python 2.7
Status: open Resolution:
Dependencies: Superseder:
Assigned To: tarek Nosy List: avi, dstufft, eric.araujo, potomak, tarek, zooko, zvyn
Priority: normal Keywords: easy, patch

Created on 2009-10-25 14:37 by zooko, last changed 2019-07-16 02:35 by potomak.

Pull Requests
URL Status Linked Edit
PR 14787 open potomak, 2019-07-16 02:29
Messages (6)
msg94453 - (view) Author: Zooko O'Whielacronx (zooko) Date: 2009-10-25 14:37
This command:

python --verbose darcsver

works as expected -- the presence of '--verbose' increases the verbosity
of logging.

This command:

python darcsver --verbose

does not increase the verbosity, nor does it tell me that the
"--verbose" option is an option unknown to the "darcsver" command.

This command:

python darcsver --quux

gives this helpful output:

usage: [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
or: --help [cmd1 cmd2 ...] or: --help-commands or: cmd --help

error: option --quux not recognized

I think that the middle command ("python darcsver --verbose")
ought to behave either like the first command by increasing the
verbosity, or like the last command by telling the user that "--verbose"
is not a known option in that position.

This is also
msg94518 - (view) Author: Tarek Ziadé (tarek) * (Python committer) Date: 2009-10-26 22:00
There's this comment in

# All commands support the global options too, just by adding
# in 'global_options'.

So, that's a bug. I'll do this:

- if a command has a global option (except help) it will be reapplied to
the distribtuion object

- if a command has a global option (except help) but also defines it as
a local command option, it will not be reapplied to the distribtuion object

- if a command has a global option (except help) and it was already
provided at the regular place, it will be ignored and a warning will be
msg221731 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-06-27 20:59
Assuming that this is still an issue would someone like to propose a patch?
msg346891 - (view) Author: Avinash Sajjanshetty (avi) * Date: 2019-06-29 17:50
I would like to take this up task and propose a patch. However, I am not able to reproduce this issue on my machine (3.7.1). Does the issue seem to be fixed?

Here is what I tried: 


python --verbose build

I got the verbose build, as expected. 


python build --verbose 

In this case, it seems to have ignored the verbose option, as I got a normal (non-verbose) output. 

3. since the issue is with `verbose`, I tried quiet. 

python --quiet build

I got a quiet build. 


python build --quiet 

it ignored the quiet option, as I got a normal output.

5. I also tried a non-existent option. In the following both cases, I got an error saying 

error: option --qqqp not recognized


python --qqqp build


python build --qqqp
msg347802 - (view) Author: Milan Oberkirch (zvyn) * Date: 2019-07-13 10:42
The help states:

> usage: [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]

so I would argue that ignoring global_opts after cmd1 is not a bug.

But I do think that the fact that "python build --dry-run" does not prevent the build from running is not ideal.

Maybe throwing an error for misplaced global options is the best solution?
msg347999 - (view) Author: Giovanni Cappellotto (potomak) * Date: 2019-07-16 02:35
I took a stab at this, see attached PR.

I was able encode the first two cases described by @tarek, but not the first one because `_parse_command_opts` doesn't have visibility to the list of global options that have already been parsed.


I had to move `log.set_verbosity(self.verbose)` after the call to `_parse_command_opts` in order to correctly apply the verbosity level after all command options are parsed. I think there should be a better way to handle this case, maybe by creating a `verbose` setter that re-runs `log.set_verbosity` every time `verbose` value is updated.
Date User Action Args
2019-07-16 02:35:40potomaksetnosy: + potomak
messages: + msg347999
2019-07-16 02:29:44potomaksetkeywords: + patch
stage: patch review
pull_requests: + pull_request14585
2019-07-13 10:42:35zvynsetnosy: + zvyn
messages: + msg347802
2019-06-29 17:50:20avisetnosy: + avi
messages: + msg346891
2019-03-15 23:58:10BreamoreBoysetnosy: - BreamoreBoy
2014-06-27 20:59:58BreamoreBoysetversions: + Python 3.4, Python 3.5, - 3rd party, Python 3.1, Python 3.2
nosy: + BreamoreBoy, dstufft

messages: + msg221731

components: - Distutils2
2010-11-18 01:51:08eric.araujosetversions: + 3rd party, Python 3.1, Python 2.7, Python 3.2
nosy: zooko, tarek, eric.araujo
title: "python MYCOMMAND --verbose" does not yield an unrecognized option error but also does not set the verbosity -> "python cmd --verbose" does not set verbosity
components: + Distutils2
type: behavior
keywords: + easy
resolution: accepted ->
2010-06-06 22:32:11eric.araujosetnosy: + eric.araujo
2009-10-26 22:00:59tareksetpriority: normal
resolution: accepted
messages: + msg94518
2009-10-25 14:37:07zookocreate