[Python-checkins] CVS: distutils/distutils dist.py,1.36,1.37
Greg Ward
python-dev@python.org
Sun, 24 Sep 2000 18:24:05 -0700
Update of /cvsroot/python/distutils/distutils
In directory slayer.i.sourceforge.net:/tmp/cvs-serv1310
Modified Files:
dist.py
Log Message:
Fixed some bugs and mis-features in handling config files:
* options can now be spelled "foo-bar" or "foo_bar" (handled in
'parse_config_files()', just after we parse a file)
* added a "[global]" section so there's a place to set global
options like verbose/quiet and dry-run
* respect the "negative alias" dictionary so (eg.) "quiet=1" is
the same as "verbose=0" (this had to be done twice: once in
'parse_config_file()' for global options, and once in
'_set_command_options()' for per-command options)
* the other half of handling boolean options correctly: allow
commands to list their boolean options in a 'boolean_options'
class attribute, and use it to translate strings (like "yes", "1",
"no", "0", etc) to true or false
Index: dist.py
===================================================================
RCS file: /cvsroot/python/distutils/distutils/dist.py,v
retrieving revision 1.36
retrieving revision 1.37
diff -C2 -r1.36 -r1.37
*** dist.py 2000/09/16 15:27:17 1.36
--- dist.py 2000/09/25 01:23:52 1.37
***************
*** 16,20 ****
from distutils import sysconfig
from distutils.fancy_getopt import FancyGetopt, longopt_xlate
! from distutils.util import check_environ
--- 16,20 ----
from distutils import sysconfig
from distutils.fancy_getopt import FancyGetopt, longopt_xlate
! from distutils.util import check_environ, strtobool
***************
*** 322,326 ****
for opt in options:
if opt != '__name__':
! opt_dict[opt] = (filename, parser.get(section,opt))
# Make the ConfigParser forget everything (so we retain
--- 322,328 ----
for opt in options:
if opt != '__name__':
! val = parser.get(section,opt)
! opt = string.replace(opt, '-', '_')
! opt_dict[opt] = (filename, val)
# Make the ConfigParser forget everything (so we retain
***************
*** 330,334 ****
--- 332,352 ----
parser.__init__()
+ # If there was a "global" section in the config file, use it
+ # to set Distribution options.
+ if self.command_options.has_key('global'):
+ for (opt, (src, val)) in self.command_options['global'].items():
+ alias = self.negative_opt.get(opt)
+ try:
+ if alias:
+ setattr(self, alias, not strtobool(val))
+ elif opt in ('verbose', 'dry_run'): # ugh!
+ setattr(self, opt, strtobool(val))
+ except ValueError, msg:
+ raise DistutilsOptionError, msg
+
+ # parse_config_files ()
+
+
# -- Command-line parsing methods ----------------------------------
***************
*** 347,351 ****
command-line raises DistutilsArgError. If no Distutils commands
were found on the command line, raises DistutilsArgError. Return
! true if command-line were successfully parsed and we should carry
on with executing commands; false if no errors but we shouldn't
execute commands (currently, this only happens if user asks for
--- 365,369 ----
command-line raises DistutilsArgError. If no Distutils commands
were found on the command line, raises DistutilsArgError. Return
! true if command-line was successfully parsed and we should carry
on with executing commands; false if no errors but we shouldn't
execute commands (currently, this only happens if user asks for
***************
*** 715,719 ****
attributes of an instance ('command').
! 'command_obj' must be a Commnd instance. If 'option_dict' is not
supplied, uses the standard option dictionary for this command
(from 'self.command_options').
--- 733,737 ----
attributes of an instance ('command').
! 'command_obj' must be a Command instance. If 'option_dict' is not
supplied, uses the standard option dictionary for this command
(from 'self.command_options').
***************
*** 728,736 ****
for (option, (source, value)) in option_dict.items():
if DEBUG: print " %s = %s (from %s)" % (option, value, source)
! if not hasattr(command_obj, option):
! raise DistutilsOptionError, \
! ("error in %s: command '%s' has no such option '%s'") % \
! (source, command_name, option)
! setattr(command_obj, option, value)
def reinitialize_command (self, command, reinit_subcommands=0):
--- 746,771 ----
for (option, (source, value)) in option_dict.items():
if DEBUG: print " %s = %s (from %s)" % (option, value, source)
! try:
! bool_opts = command_obj.boolean_options
! except AttributeError:
! bool_opts = []
! try:
! neg_opt = command_obj.negative_opt
! except AttributeError:
! neg_opt = {}
!
! try:
! if neg_opt.has_key(option):
! setattr(command_obj, neg_opt[option], not strtobool(value))
! elif option in bool_opts:
! 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
def reinitialize_command (self, command, reinit_subcommands=0):