[Python-checkins] CVS: distutils/distutils core.py,1.43,1.44 dist.py,1.33,1.34
Greg Ward
python-dev@python.org
Mon, 28 Aug 2000 18:15:21 -0700
Update of /cvsroot/python/distutils/distutils
In directory slayer.i.sourceforge.net:/tmp/cvs-serv21957
Modified Files:
core.py dist.py
Log Message:
Added 'script_name' and 'script_args' instance attributes to Distribution.
Changed 'core.setup()' so it sets them to reasonable defaults.
Tweaked how the "usage" string is generated: 'core' now provides
'gen_usage()', which is used instead of 'USAGE'.
Modified "build_py" and "sdist" commands to refer to
'self.distribution.script_name' rather than 'sys.argv[0]'.
Index: core.py
===================================================================
RCS file: /cvsroot/python/distutils/distutils/core.py,v
retrieving revision 1.43
retrieving revision 1.44
diff -C2 -r1.43 -r1.44
*** core.py 2000/06/21 02:59:14 1.43
--- core.py 2000/08/29 01:15:18 1.44
***************
*** 26,35 ****
# is generated with various --help options: global help, list commands,
# and per-command help.
! usage = """\
! usage: %s [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
! or: %s --help [cmd1 cmd2 ...]
! or: %s --help-commands
! or: %s cmd --help
! """ % ((os.path.basename(sys.argv[0]),) * 4)
--- 26,35 ----
# is generated with various --help options: global help, list commands,
# and per-command help.
! USAGE = """\
! usage: %(script)s [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
! or: %(script)s --help [cmd1 cmd2 ...]
! or: %(script)s --help-commands
! or: %(script)s cmd --help
! """
***************
*** 38,49 ****
DEBUG = os.environ.get('DISTUTILS_DEBUG')
def setup (**attrs):
"""The gateway to the Distutils: do everything your setup script needs
to do, in a highly flexible and user-driven way. Briefly: create a
Distribution instance; find and parse config files; parse the command
! line; run each of those commands using the options supplied to
! 'setup()' (as keyword arguments), in config files, and on the command
! line.
The Distribution instance might be an instance of a class supplied via
--- 38,53 ----
DEBUG = os.environ.get('DISTUTILS_DEBUG')
+ def gen_usage (script_name):
+ script = os.path.basename(script_name)
+ return USAGE % vars()
+
def setup (**attrs):
"""The gateway to the Distutils: do everything your setup script needs
to do, in a highly flexible and user-driven way. Briefly: create a
Distribution instance; find and parse config files; parse the command
! line; run each Distutils command found there, customized by the options
! supplied to 'setup()' (as keyword arguments), in config files, and on
! the command line.
The Distribution instance might be an instance of a class supplied via
***************
*** 80,83 ****
--- 84,92 ----
klass = Distribution
+ if not attrs.has_key('script_name'):
+ attrs['script_name'] = sys.argv[0]
+ if not attrs.has_key('script_args'):
+ attrs['script_args'] = sys.argv[1:]
+
# Create the Distribution instance, using the remaining arguments
# (ie. everything except distclass) to initialize it
***************
*** 98,105 ****
# fault, so turn them into SystemExit to suppress tracebacks.
try:
! ok = dist.parse_command_line (sys.argv[1:])
except DistutilsArgError, msg:
! sys.stderr.write (usage + "\n")
! raise SystemExit, "error: %s" % msg
if DEBUG:
--- 107,115 ----
# fault, so turn them into SystemExit to suppress tracebacks.
try:
! ok = dist.parse_command_line()
except DistutilsArgError, msg:
! script = os.path.basename(dist.script_name)
! raise SystemExit, \
! gen_usage(dist.script_name) + "\nerror: %s" % msg
if DEBUG:
Index: dist.py
===================================================================
RCS file: /cvsroot/python/distutils/distutils/dist.py,v
retrieving revision 1.33
retrieving revision 1.34
diff -C2 -r1.33 -r1.34
*** dist.py 2000/07/27 02:13:19 1.33
--- dist.py 2000/08/29 01:15:18 1.34
***************
*** 132,135 ****
--- 132,141 ----
self.cmdclass = {}
+ # 'script_name' and 'script_args' are usually set to sys.argv[0]
+ # and sys.argv[1:], but they can be overridden when the caller is
+ # not necessarily a setup script run from the command-line.
+ self.script_name = None
+ self.script_args = None
+
# 'command_options' is where we store command options between
# parsing them (from config files, the command-line, etc.) and when
***************
*** 327,348 ****
# -- Command-line parsing methods ----------------------------------
! def parse_command_line (self, args):
! """Parse the setup script's command line. 'args' must be a list
! of command-line arguments, most likely 'sys.argv[1:]' (see the
! 'setup()' function). This list is first processed for "global
! options" -- options that set attributes of the Distribution
! instance. Then, it is alternately scanned for Distutils
! commands and options for that command. Each new command
! terminates the options for the previous command. The allowed
! options for a command are determined by the 'user_options'
! attribute of the command class -- thus, we have to be able to
! load command classes in order to parse the command line. Any
! error in that 'options' attribute raises DistutilsGetoptError;
! any error on the 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 help).
"""
# We have to parse the command line a bit at a time -- global
--- 333,354 ----
# -- Command-line parsing methods ----------------------------------
! def parse_command_line (self):
! """Parse the setup script's command line, taken from the
! 'script_args' instance attribute (which defaults to 'sys.argv[1:]'
! -- see 'setup()' in core.py). This list is first processed for
! "global options" -- options that set attributes of the Distribution
! instance. Then, it is alternately scanned for Distutils commands
! and options for that command. Each new command terminates the
! options for the previous command. The allowed options for a
! command are determined by the 'user_options' attribute of the
! command class -- thus, we have to be able to load command classes
! in order to parse the command line. Any error in that 'options'
! attribute raises DistutilsGetoptError; any error on the
! 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
! help).
"""
# We have to parse the command line a bit at a time -- global
***************
*** 357,361 ****
parser.set_negative_aliases (self.negative_opt)
parser.set_aliases ({'license': 'licence'})
! args = parser.getopt (object=self)
option_order = parser.get_option_order()
--- 363,367 ----
parser.set_negative_aliases (self.negative_opt)
parser.set_aliases ({'license': 'licence'})
! args = parser.getopt (args=self.script_args, object=self)
option_order = parser.get_option_order()
***************
*** 507,511 ****
"""
# late import because of mutual dependence between these modules
! from distutils.core import usage
from distutils.cmd import Command
--- 513,517 ----
"""
# late import because of mutual dependence between these modules
! from distutils.core import gen_usage
from distutils.cmd import Command
***************
*** 536,540 ****
print
! print usage
return
--- 542,546 ----
print
! print gen_usage(self.script_name)
return
***************
*** 548,552 ****
false.
"""
! from distutils.core import usage
# User just wants a list of commands -- we'll print it out and stop
--- 554,558 ----
false.
"""
! from distutils.core import gen_usage
# User just wants a list of commands -- we'll print it out and stop
***************
*** 556,560 ****
self.print_commands ()
print
! print usage
return 1
--- 562,566 ----
self.print_commands ()
print
! print gen_usage(self.script_name)
return 1