mirror of
https://github.com/python/cpython.git
synced 2025-09-16 21:56:14 +00:00
Cleaned up/simplified error-handling:
- DistutilsOptionError is now documented as it's actually used, ie. to indicate bogus option values (usually user options, eg. from the command-line) - added DistutilsSetupError to indicate errors that definitely arise in the setup script - got rid of DistutilsValueError, and changed all usage of it to either DistutilsSetupError or ValueError as appropriate - simplified a bunch of option get/set methods in Command and Distribution classes -- just pass on AttributeError most of the time, rather than turning it into something else
This commit is contained in:
parent
4a3dd2dcc2
commit
02a1a2b077
7 changed files with 52 additions and 79 deletions
|
@ -161,38 +161,28 @@ class Command:
|
||||||
|
|
||||||
def get_option (self, option):
|
def get_option (self, option):
|
||||||
"""Return the value of a single option for this command. Raise
|
"""Return the value of a single option for this command. Raise
|
||||||
DistutilsOptionError if 'option' is not known."""
|
AttributeError if 'option' is not known."""
|
||||||
try:
|
|
||||||
return getattr (self, option)
|
return getattr (self, option)
|
||||||
except AttributeError:
|
|
||||||
raise DistutilsOptionError, \
|
|
||||||
"command %s: no such option %s" % \
|
|
||||||
(self.get_command_name(), option)
|
|
||||||
|
|
||||||
|
|
||||||
def get_options (self, *options):
|
def get_options (self, *options):
|
||||||
"""Return (as a tuple) the values of several options for this
|
"""Return (as a tuple) the values of several options for this
|
||||||
command. Raise DistutilsOptionError if any of the options in
|
command. Raise AttributeError if any of the options in
|
||||||
'options' are not known."""
|
'options' are not known."""
|
||||||
|
|
||||||
values = []
|
values = []
|
||||||
try:
|
|
||||||
for opt in options:
|
for opt in options:
|
||||||
values.append (getattr (self, opt))
|
values.append (getattr (self, opt))
|
||||||
except AttributeError, name:
|
|
||||||
raise DistutilsOptionError, \
|
|
||||||
"command %s: no such option %s" % \
|
|
||||||
(self.get_command_name(), name)
|
|
||||||
|
|
||||||
return tuple (values)
|
return tuple (values)
|
||||||
|
|
||||||
|
|
||||||
def set_option (self, option, value):
|
def set_option (self, option, value):
|
||||||
"""Set the value of a single option for this command. Raise
|
"""Set the value of a single option for this command. Raise
|
||||||
DistutilsOptionError if 'option' is not known."""
|
AttributeError if 'option' is not known."""
|
||||||
|
|
||||||
if not hasattr (self, option):
|
if not hasattr (self, option):
|
||||||
raise DistutilsOptionError, \
|
raise AttributeError, \
|
||||||
"command '%s': no such option '%s'" % \
|
"command '%s': no such option '%s'" % \
|
||||||
(self.get_command_name(), option)
|
(self.get_command_name(), option)
|
||||||
if value is not None:
|
if value is not None:
|
||||||
|
@ -200,7 +190,7 @@ class Command:
|
||||||
|
|
||||||
def set_options (self, **optval):
|
def set_options (self, **optval):
|
||||||
"""Set the values of several options for this command. Raise
|
"""Set the values of several options for this command. Raise
|
||||||
DistutilsOptionError if any of the options specified as
|
AttributeError if any of the options specified as
|
||||||
keyword arguments are not known."""
|
keyword arguments are not known."""
|
||||||
|
|
||||||
for k in optval.keys():
|
for k in optval.keys():
|
||||||
|
@ -236,14 +226,10 @@ class Command:
|
||||||
|
|
||||||
src_cmd_obj = self.distribution.find_command_obj (src_cmd)
|
src_cmd_obj = self.distribution.find_command_obj (src_cmd)
|
||||||
src_cmd_obj.ensure_ready ()
|
src_cmd_obj.ensure_ready ()
|
||||||
try:
|
|
||||||
for (src_option, dst_option) in option_pairs:
|
for (src_option, dst_option) in option_pairs:
|
||||||
if getattr (self, dst_option) is None:
|
if getattr (self, dst_option) is None:
|
||||||
self.set_option (dst_option,
|
self.set_option (dst_option,
|
||||||
src_cmd_obj.get_option (src_option))
|
src_cmd_obj.get_option (src_option))
|
||||||
except AttributeError, name:
|
|
||||||
# duh, which command?
|
|
||||||
raise DistutilsOptionError, "unknown option %s" % name
|
|
||||||
|
|
||||||
|
|
||||||
def find_peer (self, command, create=1):
|
def find_peer (self, command, create=1):
|
||||||
|
|
|
@ -115,33 +115,33 @@ class build_clib (Command):
|
||||||
"""Ensure that the list of libraries (presumably provided as a
|
"""Ensure that the list of libraries (presumably provided as a
|
||||||
command option 'libraries') is valid, i.e. it is a list of
|
command option 'libraries') is valid, i.e. it is a list of
|
||||||
2-tuples, where the tuples are (library_name, build_info_dict).
|
2-tuples, where the tuples are (library_name, build_info_dict).
|
||||||
Raise DistutilsValueError if the structure is invalid anywhere;
|
Raise DistutilsSetupError if the structure is invalid anywhere;
|
||||||
just returns otherwise."""
|
just returns otherwise."""
|
||||||
|
|
||||||
# Yechh, blecch, ackk: this is ripped straight out of build_ext.py,
|
# Yechh, blecch, ackk: this is ripped straight out of build_ext.py,
|
||||||
# with only names changed to protect the innocent!
|
# with only names changed to protect the innocent!
|
||||||
|
|
||||||
if type (libraries) is not ListType:
|
if type (libraries) is not ListType:
|
||||||
raise DistutilsValueError, \
|
raise DistutilsSetupError, \
|
||||||
"'libraries' option must be a list of tuples"
|
"'libraries' option must be a list of tuples"
|
||||||
|
|
||||||
for lib in libraries:
|
for lib in libraries:
|
||||||
if type (lib) is not TupleType and len (lib) != 2:
|
if type (lib) is not TupleType and len (lib) != 2:
|
||||||
raise DistutilsValueError, \
|
raise DistutilsSetupError, \
|
||||||
"each element of 'libraries' must a 2-tuple"
|
"each element of 'libraries' must a 2-tuple"
|
||||||
|
|
||||||
if type (lib[0]) is not StringType:
|
if type (lib[0]) is not StringType:
|
||||||
raise DistutilsValueError, \
|
raise DistutilsSetupError, \
|
||||||
"first element of each tuple in 'libraries' " + \
|
"first element of each tuple in 'libraries' " + \
|
||||||
"must be a string (the library name)"
|
"must be a string (the library name)"
|
||||||
if '/' in lib[0] or (os.sep != '/' and os.sep in lib[0]):
|
if '/' in lib[0] or (os.sep != '/' and os.sep in lib[0]):
|
||||||
raise DistutilsValueError, \
|
raise DistutilsSetupError, \
|
||||||
("bad library name '%s': " +
|
("bad library name '%s': " +
|
||||||
"may not contain directory separators") % \
|
"may not contain directory separators") % \
|
||||||
lib[0]
|
lib[0]
|
||||||
|
|
||||||
if type (lib[1]) is not DictionaryType:
|
if type (lib[1]) is not DictionaryType:
|
||||||
raise DistutilsValueError, \
|
raise DistutilsSetupError, \
|
||||||
"second element of each tuple in 'libraries' " + \
|
"second element of each tuple in 'libraries' " + \
|
||||||
"must be a dictionary (build info)"
|
"must be a dictionary (build info)"
|
||||||
# for lib
|
# for lib
|
||||||
|
@ -171,7 +171,7 @@ class build_clib (Command):
|
||||||
for (lib_name, build_info) in libraries:
|
for (lib_name, build_info) in libraries:
|
||||||
sources = build_info.get ('sources')
|
sources = build_info.get ('sources')
|
||||||
if sources is None or type (sources) not in (ListType, TupleType):
|
if sources is None or type (sources) not in (ListType, TupleType):
|
||||||
raise DistutilsValueError, \
|
raise DistutilsSetupError, \
|
||||||
("in 'libraries' option (library '%s'), " +
|
("in 'libraries' option (library '%s'), " +
|
||||||
"'sources' must be present and must be " +
|
"'sources' must be present and must be " +
|
||||||
"a list of source filenames") % lib_name
|
"a list of source filenames") % lib_name
|
||||||
|
|
|
@ -205,26 +205,26 @@ class build_ext (Command):
|
||||||
"""Ensure that the list of extensions (presumably provided as a
|
"""Ensure that the list of extensions (presumably provided as a
|
||||||
command option 'extensions') is valid, i.e. it is a list of
|
command option 'extensions') is valid, i.e. it is a list of
|
||||||
2-tuples, where the tuples are (extension_name, build_info_dict).
|
2-tuples, where the tuples are (extension_name, build_info_dict).
|
||||||
Raise DistutilsValueError if the structure is invalid anywhere;
|
Raise DistutilsSetupError if the structure is invalid anywhere;
|
||||||
just returns otherwise."""
|
just returns otherwise."""
|
||||||
|
|
||||||
if type (extensions) is not ListType:
|
if type (extensions) is not ListType:
|
||||||
raise DistutilsValueError, \
|
raise DistutilsSetupError, \
|
||||||
"'ext_modules' option must be a list of tuples"
|
"'ext_modules' option must be a list of tuples"
|
||||||
|
|
||||||
for ext in extensions:
|
for ext in extensions:
|
||||||
if type (ext) is not TupleType and len (ext) != 2:
|
if type (ext) is not TupleType and len (ext) != 2:
|
||||||
raise DistutilsValueError, \
|
raise DistutilsSetupError, \
|
||||||
"each element of 'ext_modules' option must be a 2-tuple"
|
"each element of 'ext_modules' option must be a 2-tuple"
|
||||||
|
|
||||||
if not (type (ext[0]) is StringType and
|
if not (type (ext[0]) is StringType and
|
||||||
extension_name_re.match (ext[0])):
|
extension_name_re.match (ext[0])):
|
||||||
raise DistutilsValueError, \
|
raise DistutilsSetupError, \
|
||||||
"first element of each tuple in 'ext_modules' " + \
|
"first element of each tuple in 'ext_modules' " + \
|
||||||
"must be the extension name (a string)"
|
"must be the extension name (a string)"
|
||||||
|
|
||||||
if type (ext[1]) is not DictionaryType:
|
if type (ext[1]) is not DictionaryType:
|
||||||
raise DistutilsValueError, \
|
raise DistutilsSetupError, \
|
||||||
"second element of each tuple in 'ext_modules' " + \
|
"second element of each tuple in 'ext_modules' " + \
|
||||||
"must be a dictionary (build info)"
|
"must be a dictionary (build info)"
|
||||||
|
|
||||||
|
@ -274,7 +274,7 @@ class build_ext (Command):
|
||||||
for (extension_name, build_info) in self.extensions:
|
for (extension_name, build_info) in self.extensions:
|
||||||
sources = build_info.get ('sources')
|
sources = build_info.get ('sources')
|
||||||
if sources is None or type (sources) not in (ListType, TupleType):
|
if sources is None or type (sources) not in (ListType, TupleType):
|
||||||
raise DistutilsValueError, \
|
raise DistutilsSetupError, \
|
||||||
("in 'ext_modules' option (extension '%s'), " +
|
("in 'ext_modules' option (extension '%s'), " +
|
||||||
"'sources' must be present and must be " +
|
"'sources' must be present and must be " +
|
||||||
"a list of source filenames") % extension_name
|
"a list of source filenames") % extension_name
|
||||||
|
|
|
@ -152,7 +152,7 @@ class Distribution:
|
||||||
if hasattr (self, key):
|
if hasattr (self, key):
|
||||||
setattr (self, key, val)
|
setattr (self, key, val)
|
||||||
else:
|
else:
|
||||||
raise DistutilsOptionError, \
|
raise DistutilsSetupError, \
|
||||||
"invalid distribution option '%s'" % key
|
"invalid distribution option '%s'" % key
|
||||||
|
|
||||||
# __init__ ()
|
# __init__ ()
|
||||||
|
@ -447,27 +447,18 @@ class Distribution:
|
||||||
|
|
||||||
def get_option (self, option):
|
def get_option (self, option):
|
||||||
"""Return the value of a distribution option. Raise
|
"""Return the value of a distribution option. Raise
|
||||||
DistutilsOptionError if 'option' is not known."""
|
AttributeError if 'option' is not known."""
|
||||||
|
|
||||||
try:
|
|
||||||
return getattr (self, opt)
|
return getattr (self, opt)
|
||||||
except AttributeError:
|
|
||||||
raise DistutilsOptionError, \
|
|
||||||
"unknown distribution option %s" % option
|
|
||||||
|
|
||||||
|
|
||||||
def get_options (self, *options):
|
def get_options (self, *options):
|
||||||
"""Return (as a tuple) the values of several distribution
|
"""Return (as a tuple) the values of several distribution
|
||||||
options. Raise DistutilsOptionError if any element of
|
options. Raise AttributeError if any element of
|
||||||
'options' is not known."""
|
'options' is not known."""
|
||||||
|
|
||||||
values = []
|
values = []
|
||||||
try:
|
|
||||||
for opt in options:
|
for opt in options:
|
||||||
values.append (getattr (self, opt))
|
values.append (getattr (self, opt))
|
||||||
except AttributeError, name:
|
|
||||||
raise DistutilsOptionError, \
|
|
||||||
"unknown distribution option %s" % name
|
|
||||||
|
|
||||||
return tuple (values)
|
return tuple (values)
|
||||||
|
|
||||||
|
@ -498,17 +489,12 @@ class Distribution:
|
||||||
def get_command_option (self, command, option):
|
def get_command_option (self, command, option):
|
||||||
"""Create a command object for 'command' if necessary, ensure that
|
"""Create a command object for 'command' if necessary, ensure that
|
||||||
its option values are all set to their final values, and return
|
its option values are all set to their final values, and return
|
||||||
the value of its 'option' option. Raise DistutilsOptionError if
|
the value of its 'option' option. Raise AttributeError if
|
||||||
'option' is not known for that 'command'."""
|
'option' is not known for that 'command'."""
|
||||||
|
|
||||||
cmd_obj = self.find_command_obj (command)
|
cmd_obj = self.find_command_obj (command)
|
||||||
cmd_obj.ensure_ready ()
|
cmd_obj.ensure_ready ()
|
||||||
return cmd_obj.get_option (option)
|
return cmd_obj.get_option (option)
|
||||||
try:
|
|
||||||
return getattr (cmd_obj, option)
|
|
||||||
except AttributeError:
|
|
||||||
raise DistutilsOptionError, \
|
|
||||||
"command %s: no such option %s" % (command, option)
|
|
||||||
|
|
||||||
|
|
||||||
def get_command_options (self, command, *options):
|
def get_command_options (self, command, *options):
|
||||||
|
@ -521,12 +507,8 @@ class Distribution:
|
||||||
cmd_obj = self.find_command_obj (command)
|
cmd_obj = self.find_command_obj (command)
|
||||||
cmd_obj.ensure_ready ()
|
cmd_obj.ensure_ready ()
|
||||||
values = []
|
values = []
|
||||||
try:
|
|
||||||
for opt in options:
|
for opt in options:
|
||||||
values.append (getattr (cmd_obj, option))
|
values.append (getattr (cmd_obj, option))
|
||||||
except AttributeError, name:
|
|
||||||
raise DistutilsOptionError, \
|
|
||||||
"command %s: no such option %s" % (command, name)
|
|
||||||
|
|
||||||
return tuple (values)
|
return tuple (values)
|
||||||
|
|
||||||
|
|
|
@ -46,15 +46,18 @@ if type (RuntimeError) is types.ClassType:
|
||||||
class DistutilsFileError (DistutilsError):
|
class DistutilsFileError (DistutilsError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# DistutilsOptionError is raised anytime an attempt is made to access
|
# DistutilsOptionError is raised for syntactic/semantic errors in
|
||||||
# (get or set) an option that does not exist for a particular command
|
# command options, such as use of mutually conflicting options, or
|
||||||
# (or for the distribution itself).
|
# inconsistent options, badly-spelled values, etc. No distinction is
|
||||||
|
# made between option values originating in the setup script, the
|
||||||
|
# command line, config files, or what-have-you.
|
||||||
class DistutilsOptionError (DistutilsError):
|
class DistutilsOptionError (DistutilsError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# DistutilsValueError is raised anytime an option value (presumably
|
# DistutilsSetupError is raised for errors that can be definitely
|
||||||
# provided by setup.py) is invalid.
|
# blamed on the setup script, such as invalid keyword arguments to
|
||||||
class DistutilsValueError (DistutilsError):
|
# 'setup()'.
|
||||||
|
class DistutilsSetupError (DistutilsError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# DistutilsPlatformError is raised when we find that we don't
|
# DistutilsPlatformError is raised when we find that we don't
|
||||||
|
@ -82,7 +85,6 @@ else:
|
||||||
DistutilsArgError = 'DistutilsArgError'
|
DistutilsArgError = 'DistutilsArgError'
|
||||||
DistutilsFileError = 'DistutilsFileError'
|
DistutilsFileError = 'DistutilsFileError'
|
||||||
DistutilsOptionError = 'DistutilsOptionError'
|
DistutilsOptionError = 'DistutilsOptionError'
|
||||||
DistutilsValueError = 'DistutilsValueError'
|
|
||||||
DistutilsPlatformError = 'DistutilsPlatformError'
|
DistutilsPlatformError = 'DistutilsPlatformError'
|
||||||
DistutilsExecError = 'DistutilsExecError'
|
DistutilsExecError = 'DistutilsExecError'
|
||||||
DistutilsInternalError = 'DistutilsInternalError'
|
DistutilsInternalError = 'DistutilsInternalError'
|
||||||
|
|
|
@ -360,6 +360,9 @@ class MSVCCompiler (CCompiler) :
|
||||||
if extra_postargs:
|
if extra_postargs:
|
||||||
ld_args.extend (extra_postargs)
|
ld_args.extend (extra_postargs)
|
||||||
|
|
||||||
|
print "link_shared_object():"
|
||||||
|
print " output_filename =", output_filename
|
||||||
|
print " mkpath'ing:", os.path.dirname (output_filename)
|
||||||
self.mkpath (os.path.dirname (output_filename))
|
self.mkpath (os.path.dirname (output_filename))
|
||||||
self.spawn ([self.link] + ld_args)
|
self.spawn ([self.link] + ld_args)
|
||||||
|
|
||||||
|
|
|
@ -40,16 +40,16 @@ def native_path (pathname):
|
||||||
using the current directory separator. Needed because filenames in
|
using the current directory separator. Needed because filenames in
|
||||||
the setup script are always supplied in Unix style, and have to be
|
the setup script are always supplied in Unix style, and have to be
|
||||||
converted to the local convention before we can actually use them in
|
converted to the local convention before we can actually use them in
|
||||||
the filesystem. Raises DistutilsValueError if 'pathname' is
|
the filesystem. Raises ValueError if 'pathname' is
|
||||||
absolute (starts with '/') or contains local directory separators
|
absolute (starts with '/') or contains local directory separators
|
||||||
(unless the local separator is '/', of course)."""
|
(unless the local separator is '/', of course)."""
|
||||||
|
|
||||||
if pathname[0] == '/':
|
if pathname[0] == '/':
|
||||||
raise DistutilsValueError, "path '%s' cannot be absolute" % pathname
|
raise ValueError, "path '%s' cannot be absolute" % pathname
|
||||||
if pathname[-1] == '/':
|
if pathname[-1] == '/':
|
||||||
raise DistutilsValueError, "path '%s' cannot end with '/'" % pathname
|
raise ValueError, "path '%s' cannot end with '/'" % pathname
|
||||||
if os.sep != '/' and os.sep in pathname:
|
if os.sep != '/' and os.sep in pathname:
|
||||||
raise DistutilsValueError, \
|
raise ValueError, \
|
||||||
"path '%s' cannot contain '%c' character" % \
|
"path '%s' cannot contain '%c' character" % \
|
||||||
(pathname, os.sep)
|
(pathname, os.sep)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue