[Distutils] Option question

Thomas Heller thomas.heller@ion-tof.com
Thu Feb 14 14:40:02 2002


There's another bug related to options specified in the
configuration file. The following entry

  [install]
  verbose=0

will also lead to self.verbose having a value of '0' (string)
at the end of the finalize_options() method, and
The problem is in dist.py, near line 821:

            bool_opts = map(translate_longopt, command_obj.boolean_options)
            ...
            try:
                is_string = type(value) is StringType
                if neg_opt.has_key(option) and is_string:
                    setattr(command_obj, neg_opt[option], not strtobool(value))
                elif option in bool_opts and is_string:
                    setattr(command_obj, option, strtobool(value))
                elif hasattr(command_obj, option):
                    setattr(command_obj, option, value)
                else:
                    raise DistutilsOptionError, \
                          ("error in %s: command '%s' has no such option '%s'"
                           % (source, command_name, option))
            except ValueError, msg:
                raise DistutilsOptionError, msg

Since command_obj.boolean_options does not include 'verbose' (verbose
is an attribute of class Distribution), 'verbose' is not recognized as
a boolean option, and the value will not be converted by strtobool().

Hm, reading the dist.py source, I find about the [global] section...
It seems the [globals] section is not documented anywhere.
I should probably use

    [global]
    verbose=0

instead, but, nevertheless, the above also looks like a bug to me.
I propose the following fix (Note that the #ugh! comment is copied
from another, similar code on line 343 ;-)
Or should instead using global options in non-global sections of
the config file be forbidden?

Thomas

Index: dist.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/distutils/dist.py,v
retrieving revision 1.53
diff -c -r1.53 dist.py
*** dist.py 6 Dec 2001 20:51:35 -0000 1.53
--- dist.py 14 Feb 2002 19:35:25 -0000
***************
*** 822,828 ****
                  is_string = type(value) is StringType
                  if neg_opt.has_key(option) and is_string:
                      setattr(command_obj, neg_opt[option], not strtobool(value))
!                 elif option in bool_opts and is_string:
                      setattr(command_obj, option, strtobool(value))
                  elif hasattr(command_obj, option):
                      setattr(command_obj, option, value)
--- 822,828 ----
                  is_string = type(value) is StringType
                  if neg_opt.has_key(option) and is_string:
                      setattr(command_obj, neg_opt[option], not strtobool(value))
!                 elif (option in bool_opts + ['verbose', 'dry_run']) and is_string: # ugh!
                      setattr(command_obj, option, strtobool(value))
                  elif hasattr(command_obj, option):
                      setattr(command_obj, option, value)