annotate Lib/distutils/core.py @ 58925:eecf1bef052d 2.6

Merged revisions 78207 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line #7930: fix stripid ........
author Ezio Melotti <ezio.melotti@gmail.com>
date Tue, 16 Feb 2010 23:29:44 +0000
parents fc90b581516e
children a5229237eb50
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10435
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
1 """distutils.core
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
2
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
3 The only module that needs to be imported to use the Distutils; provides
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents: 12159
diff changeset
4 the 'setup' function (which is to be called from the setup script). Also
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents: 12159
diff changeset
5 indirectly provides the Distribution and Command classes, although they are
12822
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12801
diff changeset
6 really defined in distutils.dist and distutils.cmd.
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12801
diff changeset
7 """
10435
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
8
33965
893d46576737 Update compatibility comments to 2.1, corresponding to PEP 291 1.13.
Martin v. Löwis <martin@v.loewis.de>
parents: 33759
diff changeset
9 # This module should be kept compatible with Python 2.1.
26285
42bfc98d295b Add comment to Distutil files about requiring 1.5.2 compatibility, as
Andrew M. Kuchling <amk@amk.ca>
parents: 26210
diff changeset
10
11897
017e592c0fd2 Changed '__rcsid__' to '__revision__'.
Greg Ward <gward@python.net>
parents: 11888
diff changeset
11 __revision__ = "$Id$"
10435
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
12
12452
3469b2f17624 Merged in code from the 0.1.5 release to handle IOError and OSError
Greg Ward <gward@python.net>
parents: 12450
diff changeset
13 import sys, os
11249
aede7b2dd42f Patch from Perry Stoll: import types module.
Greg Ward <gward@python.net>
parents: 11195
diff changeset
14 from types import *
23683
61358f800b61 Define DEBUG as early as possible to avoid import problems.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23671
diff changeset
15
25212
12949eced55f Use distutils.debug.DEBUG instead of distutils.core.DEBUG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23683
diff changeset
16 from distutils.debug import DEBUG
10435
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
17 from distutils.errors import *
12978
77c651131984 Oops, import 'grok_environment_error()'.
Greg Ward <gward@python.net>
parents: 12936
diff changeset
18 from distutils.util import grok_environment_error
12801
eef2b918d07a Import the new Extension class, so setup scripts can
Greg Ward <gward@python.net>
parents: 12794
diff changeset
19
eef2b918d07a Import the new Extension class, so setup scripts can
Greg Ward <gward@python.net>
parents: 12794
diff changeset
20 # Mainly import these so setup scripts can "from distutils.core import" them.
12225
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents: 12159
diff changeset
21 from distutils.dist import Distribution
c405dbdd26c9 Reorganization: moved the Distribution class from core.py to dist.py, and
Greg Ward <gward@python.net>
parents: 12159
diff changeset
22 from distutils.cmd import Command
46881
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
23 from distutils.config import PyPIRCCommand
12801
eef2b918d07a Import the new Extension class, so setup scripts can
Greg Ward <gward@python.net>
parents: 12794
diff changeset
24 from distutils.extension import Extension
eef2b918d07a Import the new Extension class, so setup scripts can
Greg Ward <gward@python.net>
parents: 12794
diff changeset
25
11816
50f12883cdd7 Changed references to the command class 'options' attribute to 'user_options'.
Greg Ward <gward@python.net>
parents: 11814
diff changeset
26 # This is a barebones help message generated displayed when the user
50f12883cdd7 Changed references to the command class 'options' attribute to 'user_options'.
Greg Ward <gward@python.net>
parents: 11814
diff changeset
27 # runs the setup script with no arguments at all. More useful help
50f12883cdd7 Changed references to the command class 'options' attribute to 'user_options'.
Greg Ward <gward@python.net>
parents: 11814
diff changeset
28 # is generated with various --help options: global help, list commands,
50f12883cdd7 Changed references to the command class 'options' attribute to 'user_options'.
Greg Ward <gward@python.net>
parents: 11814
diff changeset
29 # and per-command help.
14237
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 12978
diff changeset
30 USAGE = """\
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 12978
diff changeset
31 usage: %(script)s [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 12978
diff changeset
32 or: %(script)s --help [cmd1 cmd2 ...]
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 12978
diff changeset
33 or: %(script)s --help-commands
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 12978
diff changeset
34 or: %(script)s cmd --help
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 12978
diff changeset
35 """
10435
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
36
14237
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 12978
diff changeset
37 def gen_usage (script_name):
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 12978
diff changeset
38 script = os.path.basename(script_name)
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 12978
diff changeset
39 return USAGE % vars()
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 12978
diff changeset
40
12761
da02a892d611 Added the DEBUG global (set from the DISTUTILS_DEBUG environment variable).
Greg Ward <gward@python.net>
parents: 12734
diff changeset
41
14319
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
42 # Some mild magic to control the behaviour of 'setup()' from 'run_setup()'.
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
43 _setup_stop_after = None
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
44 _setup_distribution = None
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
45
27416
20df24a13349 Remove the recently-added get_distutil_options(), and just
Andrew M. Kuchling <amk@amk.ca>
parents: 26285
diff changeset
46 # Legal keyword arguments for the setup() function
20df24a13349 Remove the recently-added get_distutil_options(), and just
Andrew M. Kuchling <amk@amk.ca>
parents: 26285
diff changeset
47 setup_keywords = ('distclass', 'script_name', 'script_args', 'options',
20df24a13349 Remove the recently-added get_distutil_options(), and just
Andrew M. Kuchling <amk@amk.ca>
parents: 26285
diff changeset
48 'name', 'version', 'author', 'author_email',
20df24a13349 Remove the recently-added get_distutil_options(), and just
Andrew M. Kuchling <amk@amk.ca>
parents: 26285
diff changeset
49 'maintainer', 'maintainer_email', 'url', 'license',
20df24a13349 Remove the recently-added get_distutil_options(), and just
Andrew M. Kuchling <amk@amk.ca>
parents: 26285
diff changeset
50 'description', 'long_description', 'keywords',
34785
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 33965
diff changeset
51 'platforms', 'classifiers', 'download_url',
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 33965
diff changeset
52 'requires', 'provides', 'obsoletes',
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 33965
diff changeset
53 )
27416
20df24a13349 Remove the recently-added get_distutil_options(), and just
Andrew M. Kuchling <amk@amk.ca>
parents: 26285
diff changeset
54
20df24a13349 Remove the recently-added get_distutil_options(), and just
Andrew M. Kuchling <amk@amk.ca>
parents: 26285
diff changeset
55 # Legal keyword arguments for the Extension constructor
20df24a13349 Remove the recently-added get_distutil_options(), and just
Andrew M. Kuchling <amk@amk.ca>
parents: 26285
diff changeset
56 extension_keywords = ('name', 'sources', 'include_dirs',
20df24a13349 Remove the recently-added get_distutil_options(), and just
Andrew M. Kuchling <amk@amk.ca>
parents: 26285
diff changeset
57 'define_macros', 'undef_macros',
20df24a13349 Remove the recently-added get_distutil_options(), and just
Andrew M. Kuchling <amk@amk.ca>
parents: 26285
diff changeset
58 'library_dirs', 'libraries', 'runtime_library_dirs',
20df24a13349 Remove the recently-added get_distutil_options(), and just
Andrew M. Kuchling <amk@amk.ca>
parents: 26285
diff changeset
59 'extra_objects', 'extra_compile_args', 'extra_link_args',
33759
11d01fc650dc Patch 1046644 - improved distutils support for SWIG.
Anthony Baxter <anthonybaxter@gmail.com>
parents: 33744
diff changeset
60 'swig_opts', 'export_symbols', 'depends', 'language')
14319
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
61
10435
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
62 def setup (**attrs):
12822
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12801
diff changeset
63 """The gateway to the Distutils: do everything your setup script needs
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12801
diff changeset
64 to do, in a highly flexible and user-driven way. Briefly: create a
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12801
diff changeset
65 Distribution instance; find and parse config files; parse the command
14237
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 12978
diff changeset
66 line; run each Distutils command found there, customized by the options
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 12978
diff changeset
67 supplied to 'setup()' (as keyword arguments), in config files, and on
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 12978
diff changeset
68 the command line.
10435
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
69
12822
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12801
diff changeset
70 The Distribution instance might be an instance of a class supplied via
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12801
diff changeset
71 the 'distclass' keyword argument to 'setup'; if no such class is
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12801
diff changeset
72 supplied, then the Distribution class (in dist.py) is instantiated.
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12801
diff changeset
73 All other arguments to 'setup' (except for 'cmdclass') are used to set
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12801
diff changeset
74 attributes of the Distribution instance.
10435
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
75
12822
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12801
diff changeset
76 The 'cmdclass' argument, if supplied, is a dictionary mapping command
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12801
diff changeset
77 names to command classes. Each command encountered on the command line
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12801
diff changeset
78 will be turned into a command class, which is in turn instantiated; any
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12801
diff changeset
79 class found in 'cmdclass' is used in place of the default, which is
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12801
diff changeset
80 (for command 'foo_bar') class 'foo_bar' in module
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12801
diff changeset
81 'distutils.command.foo_bar'. The command class must provide a
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12801
diff changeset
82 'user_options' attribute which is a list of option specifiers for
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12801
diff changeset
83 'distutils.fancy_getopt'. Any command-line options between the current
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12801
diff changeset
84 and the next command are used to set attributes of the current command
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12801
diff changeset
85 object.
10435
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
86
12822
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12801
diff changeset
87 When the entire command-line has been successfully parsed, calls the
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12801
diff changeset
88 'run()' method on each command object in turn. This method will be
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12801
diff changeset
89 driven entirely by the Distribution object (which each command object
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12801
diff changeset
90 has a reference to, thanks to its constructor), and the
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12801
diff changeset
91 command-specific options that became attributes of each command
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12801
diff changeset
92 object.
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12801
diff changeset
93 """
10435
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
94
14319
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
95 global _setup_stop_after, _setup_distribution
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
96
10435
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
97 # Determine the distribution class -- either caller-supplied or
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
98 # our Distribution (see below).
14860
18b3def6c4b8 Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 14319
diff changeset
99 klass = attrs.get('distclass')
10435
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
100 if klass:
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
101 del attrs['distclass']
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
102 else:
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
103 klass = Distribution
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
104
45413
8a187f562959 Removed uses of dict.has_key() from distutils, and uses of
Guido van Rossum <guido@python.org>
parents: 34785
diff changeset
105 if 'script_name' not in attrs:
26095
f467427e03fa Fix a small bug when sys.argv[0] has an absolute path.
Thomas Heller <theller@ctypes.org>
parents: 26013
diff changeset
106 attrs['script_name'] = os.path.basename(sys.argv[0])
45413
8a187f562959 Removed uses of dict.has_key() from distutils, and uses of
Guido van Rossum <guido@python.org>
parents: 34785
diff changeset
107 if 'script_args' not in attrs:
14237
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 12978
diff changeset
108 attrs['script_args'] = sys.argv[1:]
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 12978
diff changeset
109
10435
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
110 # Create the Distribution instance, using the remaining arguments
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
111 # (ie. everything except distclass) to initialize it
12841
645d57ef1639 Catch DistutilSetupError from the Distribution constructor.
Greg Ward <gward@python.net>
parents: 12825
diff changeset
112 try:
14860
18b3def6c4b8 Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 14319
diff changeset
113 _setup_distribution = dist = klass(attrs)
12841
645d57ef1639 Catch DistutilSetupError from the Distribution constructor.
Greg Ward <gward@python.net>
parents: 12825
diff changeset
114 except DistutilsSetupError, msg:
45413
8a187f562959 Removed uses of dict.has_key() from distutils, and uses of
Guido van Rossum <guido@python.org>
parents: 34785
diff changeset
115 if 'name' in attrs:
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21267
diff changeset
116 raise SystemExit, "error in %s setup command: %s" % \
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21267
diff changeset
117 (attrs['name'], msg)
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21267
diff changeset
118 else:
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21267
diff changeset
119 raise SystemExit, "error in setup command: %s" % msg
10435
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
120
14319
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
121 if _setup_stop_after == "init":
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
122 return dist
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
123
12674
116fc4305a39 Call 'parse_config_files()' at the appropriate point.
Gregory P. Smith <greg@mad-scientist.com>
parents: 12452
diff changeset
124 # Find and parse the config file(s): they will override options from
116fc4305a39 Call 'parse_config_files()' at the appropriate point.
Gregory P. Smith <greg@mad-scientist.com>
parents: 12452
diff changeset
125 # the setup script, but be overridden by the command line.
116fc4305a39 Call 'parse_config_files()' at the appropriate point.
Gregory P. Smith <greg@mad-scientist.com>
parents: 12452
diff changeset
126 dist.parse_config_files()
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 14860
diff changeset
127
12825
c9298ec637c5 Use Distribution method 'dump_option_dicts()' for debugging output, and only
Greg Ward <gward@python.net>
parents: 12822
diff changeset
128 if DEBUG:
c9298ec637c5 Use Distribution method 'dump_option_dicts()' for debugging output, and only
Greg Ward <gward@python.net>
parents: 12822
diff changeset
129 print "options (after parsing config files):"
c9298ec637c5 Use Distribution method 'dump_option_dicts()' for debugging output, and only
Greg Ward <gward@python.net>
parents: 12822
diff changeset
130 dist.dump_option_dicts()
12734
cab22bcbf5b6 Added some debuging output (actually moved here from dist.py) --
Greg Ward <gward@python.net>
parents: 12727
diff changeset
131
14319
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
132 if _setup_stop_after == "config":
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
133 return dist
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
134
12674
116fc4305a39 Call 'parse_config_files()' at the appropriate point.
Gregory P. Smith <greg@mad-scientist.com>
parents: 12452
diff changeset
135 # Parse the command line; any command-line errors are the end user's
11261
6968fdbb1a3f Careful rethink of command options, distribution options, distribution
Greg Ward <gward@python.net>
parents: 11249
diff changeset
136 # fault, so turn them into SystemExit to suppress tracebacks.
10435
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
137 try:
14237
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 12978
diff changeset
138 ok = dist.parse_command_line()
10435
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
139 except DistutilsArgError, msg:
23671
8efa52e0a844 Fix unused local variables caught by pychecker.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
140 raise SystemExit, gen_usage(dist.script_name) + "\nerror: %s" % msg
10435
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
141
12825
c9298ec637c5 Use Distribution method 'dump_option_dicts()' for debugging output, and only
Greg Ward <gward@python.net>
parents: 12822
diff changeset
142 if DEBUG:
c9298ec637c5 Use Distribution method 'dump_option_dicts()' for debugging output, and only
Greg Ward <gward@python.net>
parents: 12822
diff changeset
143 print "options (after parsing command line):"
c9298ec637c5 Use Distribution method 'dump_option_dicts()' for debugging output, and only
Greg Ward <gward@python.net>
parents: 12822
diff changeset
144 dist.dump_option_dicts()
12734
cab22bcbf5b6 Added some debuging output (actually moved here from dist.py) --
Greg Ward <gward@python.net>
parents: 12727
diff changeset
145
14319
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
146 if _setup_stop_after == "commandline":
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
147 return dist
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
148
10435
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
149 # And finally, run all the commands found on the command line.
11541
b605c466d1c0 Made "verbose" mode the default; now you have to supply --quiet if you
Greg Ward <gward@python.net>
parents: 11404
diff changeset
150 if ok:
b605c466d1c0 Made "verbose" mode the default; now you have to supply --quiet if you
Greg Ward <gward@python.net>
parents: 11404
diff changeset
151 try:
14860
18b3def6c4b8 Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 14319
diff changeset
152 dist.run_commands()
11541
b605c466d1c0 Made "verbose" mode the default; now you have to supply --quiet if you
Greg Ward <gward@python.net>
parents: 11404
diff changeset
153 except KeyboardInterrupt:
b605c466d1c0 Made "verbose" mode the default; now you have to supply --quiet if you
Greg Ward <gward@python.net>
parents: 11404
diff changeset
154 raise SystemExit, "interrupted"
12452
3469b2f17624 Merged in code from the 0.1.5 release to handle IOError and OSError
Greg Ward <gward@python.net>
parents: 12450
diff changeset
155 except (IOError, os.error), exc:
12936
3427b0f85a7c Changed to use the new 'grok_environment_error()' function instead of
Greg Ward <gward@python.net>
parents: 12841
diff changeset
156 error = grok_environment_error(exc)
12761
da02a892d611 Added the DEBUG global (set from the DISTUTILS_DEBUG environment variable).
Greg Ward <gward@python.net>
parents: 12734
diff changeset
157
da02a892d611 Added the DEBUG global (set from the DISTUTILS_DEBUG environment variable).
Greg Ward <gward@python.net>
parents: 12734
diff changeset
158 if DEBUG:
da02a892d611 Added the DEBUG global (set from the DISTUTILS_DEBUG environment variable).
Greg Ward <gward@python.net>
parents: 12734
diff changeset
159 sys.stderr.write(error + "\n")
da02a892d611 Added the DEBUG global (set from the DISTUTILS_DEBUG environment variable).
Greg Ward <gward@python.net>
parents: 12734
diff changeset
160 raise
da02a892d611 Added the DEBUG global (set from the DISTUTILS_DEBUG environment variable).
Greg Ward <gward@python.net>
parents: 12734
diff changeset
161 else:
da02a892d611 Added the DEBUG global (set from the DISTUTILS_DEBUG environment variable).
Greg Ward <gward@python.net>
parents: 12734
diff changeset
162 raise SystemExit, error
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 14860
diff changeset
163
26115
9048207992f0 [Bug #233259] Ugly traceback for DistutilsPlatformError
Andrew M. Kuchling <amk@amk.ca>
parents: 26095
diff changeset
164 except (DistutilsError,
12794
074819afdc95 Catch CCompiler exceptions in 'setup()'.
Greg Ward <gward@python.net>
parents: 12761
diff changeset
165 CCompilerError), msg:
12761
da02a892d611 Added the DEBUG global (set from the DISTUTILS_DEBUG environment variable).
Greg Ward <gward@python.net>
parents: 12734
diff changeset
166 if DEBUG:
da02a892d611 Added the DEBUG global (set from the DISTUTILS_DEBUG environment variable).
Greg Ward <gward@python.net>
parents: 12734
diff changeset
167 raise
da02a892d611 Added the DEBUG global (set from the DISTUTILS_DEBUG environment variable).
Greg Ward <gward@python.net>
parents: 12734
diff changeset
168 else:
da02a892d611 Added the DEBUG global (set from the DISTUTILS_DEBUG environment variable).
Greg Ward <gward@python.net>
parents: 12734
diff changeset
169 raise SystemExit, "error: " + str(msg)
10435
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
170
14319
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
171 return dist
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
172
10435
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
173 # setup ()
14319
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
174
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
175
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
176 def run_setup (script_name, script_args=None, stop_after="run"):
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
177 """Run a setup script in a somewhat controlled environment, and
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
178 return the Distribution instance that drives things. This is useful
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
179 if you need to find out the distribution meta-data (passed as
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
180 keyword args from 'script' to 'setup()', or the contents of the
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
181 config files or command-line.
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
182
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
183 'script_name' is a file that will be run with 'execfile()';
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
184 'sys.argv[0]' will be replaced with 'script' for the duration of the
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
185 call. 'script_args' is a list of strings; if supplied,
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
186 'sys.argv[1:]' will be replaced by 'script_args' for the duration of
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
187 the call.
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
188
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
189 'stop_after' tells 'setup()' when to stop processing; possible
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
190 values:
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
191 init
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
192 stop after the Distribution instance has been created and
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
193 populated with the keyword arguments to 'setup()'
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
194 config
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
195 stop after config files have been parsed (and their data
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
196 stored in the Distribution instance)
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
197 commandline
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
198 stop after the command-line ('sys.argv[1:]' or 'script_args')
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
199 have been parsed (and the data stored in the Distribution)
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
200 run [default]
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
201 stop after all commands have been run (the same as if 'setup()'
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
202 had been called in the usual way
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
203
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
204 Returns the Distribution instance, which provides all information
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
205 used to drive the Distutils.
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
206 """
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
207 if stop_after not in ('init', 'config', 'commandline', 'run'):
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 27975
diff changeset
208 raise ValueError, "invalid value for 'stop_after': %r" % (stop_after,)
14319
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
209
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
210 global _setup_stop_after, _setup_distribution
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
211 _setup_stop_after = stop_after
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
212
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
213 save_argv = sys.argv
46285
fb3c9bb76b29 - Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents: 45413
diff changeset
214 g = {'__file__': script_name}
14319
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
215 l = {}
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
216 try:
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
217 try:
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
218 sys.argv[0] = script_name
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
219 if script_args is not None:
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
220 sys.argv[1:] = script_args
48282
fc90b581516e Restore Python 2.3 compatibility and remove "with" usage.
Marc-André Lemburg <mal@egenix.com>
parents: 48260
diff changeset
221 exec open(script_name, 'r').read() in g, l
14319
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
222 finally:
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
223 sys.argv = save_argv
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
224 _setup_stop_after = None
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
225 except SystemExit:
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
226 # Hmm, should we do something if exiting with a non-zero code
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
227 # (ie. error)?
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
228 pass
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
229 except:
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
230 raise
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
231
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
232 if _setup_distribution is None:
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
233 raise RuntimeError, \
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
234 ("'distutils.core.setup()' was never called -- "
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
235 "perhaps '%s' is not a Distutils setup script?") % \
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
236 script_name
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
237
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
238 # I wonder if the setup script's namespace -- g and l -- would be of
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
239 # any interest to callers?
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
240 #print "_setup_distribution:", _setup_distribution
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
241 return _setup_distribution
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
242
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
243 # run_setup ()