annotate Lib/distutils/core.py @ 80661:94de77bd0b4b 2.7

Issue #16194: document imp.load_dynamic problems when read several extension modules from the same binary object file.
author Andrew Svetlov <andrew.svetlov@gmail.com>
date Thu, 29 Nov 2012 19:51:28 +0200
parents a17b21c27a33
children
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
11897
017e592c0fd2 Changed '__rcsid__' to '__revision__'.
Greg Ward <gward@python.net>
parents: 11888
diff changeset
9 __revision__ = "$Id$"
10435
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
10
57847
3e2b7965ada9 massive import cleaning in Distutils
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 56923
diff changeset
11 import sys
3e2b7965ada9 massive import cleaning in Distutils
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 56923
diff changeset
12 import os
23683
61358f800b61 Define DEBUG as early as possible to avoid import problems.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23671
diff changeset
13
25212
12949eced55f Use distutils.debug.DEBUG instead of distutils.core.DEBUG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23683
diff changeset
14 from distutils.debug import DEBUG
57847
3e2b7965ada9 massive import cleaning in Distutils
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 56923
diff changeset
15 from distutils.errors import (DistutilsSetupError, DistutilsArgError,
3e2b7965ada9 massive import cleaning in Distutils
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 56923
diff changeset
16 DistutilsError, CCompilerError)
12978
77c651131984 Oops, import 'grok_environment_error()'.
Greg Ward <gward@python.net>
parents: 12936
diff changeset
17 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
18
eef2b918d07a Import the new Extension class, so setup scripts can
Greg Ward <gward@python.net>
parents: 12794
diff changeset
19 # 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
20 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
21 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
22 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
23 from distutils.extension import Extension
eef2b918d07a Import the new Extension class, so setup scripts can
Greg Ward <gward@python.net>
parents: 12794
diff changeset
24
11816
50f12883cdd7 Changed references to the command class 'options' attribute to 'user_options'.
Greg Ward <gward@python.net>
parents: 11814
diff changeset
25 # 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
26 # 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
27 # 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
28 # 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
29 USAGE = """\
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 12978
diff changeset
30 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
31 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
32 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
33 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
34 """
10435
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
35
57847
3e2b7965ada9 massive import cleaning in Distutils
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 56923
diff changeset
36 def gen_usage(script_name):
14237
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 12978
diff changeset
37 script = os.path.basename(script_name)
58450
fa69e891edf4 taking sysconfig out of distutils
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 57847
diff changeset
38 return USAGE % {'script': script}
14237
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 12978
diff changeset
39
12761
da02a892d611 Added the DEBUG global (set from the DISTUTILS_DEBUG environment variable).
Greg Ward <gward@python.net>
parents: 12734
diff changeset
40
14319
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
41 # 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
42 _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
43 _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
44
27416
20df24a13349 Remove the recently-added get_distutil_options(), and just
Andrew M. Kuchling <amk@amk.ca>
parents: 26285
diff changeset
45 # 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
46 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
47 '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
48 '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
49 'description', 'long_description', 'keywords',
34785
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 33965
diff changeset
50 'platforms', 'classifiers', 'download_url',
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 33965
diff changeset
51 'requires', 'provides', 'obsoletes',
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 33965
diff changeset
52 )
27416
20df24a13349 Remove the recently-added get_distutil_options(), and just
Andrew M. Kuchling <amk@amk.ca>
parents: 26285
diff changeset
53
20df24a13349 Remove the recently-added get_distutil_options(), and just
Andrew M. Kuchling <amk@amk.ca>
parents: 26285
diff changeset
54 # 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
55 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
56 'define_macros', 'undef_macros',
20df24a13349 Remove the recently-added get_distutil_options(), and just
Andrew M. Kuchling <amk@amk.ca>
parents: 26285
diff changeset
57 '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
58 '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
59 '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
60
57847
3e2b7965ada9 massive import cleaning in Distutils
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 56923
diff changeset
61 def setup(**attrs):
12822
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12801
diff changeset
62 """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
63 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
64 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
65 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
66 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
67 the command line.
10435
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
68
12822
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12801
diff changeset
69 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
70 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
71 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
72 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
73 attributes of the Distribution instance.
10435
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
74
12822
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12801
diff changeset
75 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
76 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
77 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
78 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
79 (for command 'foo_bar') class 'foo_bar' in module
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12801
diff changeset
80 '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
81 '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
82 '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
83 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
84 object.
10435
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
85
12822
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12801
diff changeset
86 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
87 '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
88 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
89 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
90 command-specific options that became attributes of each command
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12801
diff changeset
91 object.
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12801
diff changeset
92 """
10435
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
93
14319
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
94 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
95
10435
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
96 # Determine the distribution class -- either caller-supplied or
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
97 # our Distribution (see below).
14860
18b3def6c4b8 Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 14319
diff changeset
98 klass = attrs.get('distclass')
10435
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
99 if klass:
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
100 del attrs['distclass']
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
101 else:
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
102 klass = Distribution
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
103
45413
8a187f562959 Removed uses of dict.has_key() from distutils, and uses of
Guido van Rossum <guido@python.org>
parents: 34785
diff changeset
104 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
105 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
106 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
107 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
108
10435
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
109 # Create the Distribution instance, using the remaining arguments
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
110 # (ie. everything except distclass) to initialize it
12841
645d57ef1639 Catch DistutilSetupError from the Distribution constructor.
Greg Ward <gward@python.net>
parents: 12825
diff changeset
111 try:
14860
18b3def6c4b8 Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 14319
diff changeset
112 _setup_distribution = dist = klass(attrs)
12841
645d57ef1639 Catch DistutilSetupError from the Distribution constructor.
Greg Ward <gward@python.net>
parents: 12825
diff changeset
113 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
114 if 'name' in attrs:
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21267
diff changeset
115 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
116 (attrs['name'], msg)
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21267
diff changeset
117 else:
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21267
diff changeset
118 raise SystemExit, "error in setup command: %s" % msg
10435
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
119
14319
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
120 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
121 return dist
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
122
12674
116fc4305a39 Call 'parse_config_files()' at the appropriate point.
Gregory P. Smith <greg@mad-scientist.com>
parents: 12452
diff changeset
123 # 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
124 # 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
125 dist.parse_config_files()
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 14860
diff changeset
126
12825
c9298ec637c5 Use Distribution method 'dump_option_dicts()' for debugging output, and only
Greg Ward <gward@python.net>
parents: 12822
diff changeset
127 if DEBUG:
c9298ec637c5 Use Distribution method 'dump_option_dicts()' for debugging output, and only
Greg Ward <gward@python.net>
parents: 12822
diff changeset
128 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
129 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
130
14319
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
131 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
132 return dist
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
133
56923
fc5a7718433a Fixed #1180: Option to ignore ~/.pydistutils.cfg in Distutils
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51387
diff changeset
134 # Parse the command line and override config files; any
fc5a7718433a Fixed #1180: Option to ignore ~/.pydistutils.cfg in Distutils
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51387
diff changeset
135 # command-line errors are the end user's fault, so turn them into
fc5a7718433a Fixed #1180: Option to ignore ~/.pydistutils.cfg in Distutils
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51387
diff changeset
136 # 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
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
173
57847
3e2b7965ada9 massive import cleaning in Distutils
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 56923
diff changeset
174 def run_setup(script_name, script_args=None, stop_after="run"):
14319
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
175 """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
176 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
177 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
178 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
179 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
180
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
181 '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
182 '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
183 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
184 '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
185 the call.
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
186
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
187 '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
188 values:
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
189 init
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
190 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
191 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
192 config
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
193 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
194 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
195 commandline
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
196 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
197 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
198 run [default]
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
199 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
200 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
201
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
202 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
203 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
204 """
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
205 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
206 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
207
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
208 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
209 _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
210
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
211 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
212 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
213 l = {}
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
214 try:
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
215 try:
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
216 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
217 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
218 sys.argv[1:] = script_args
66008
a17b21c27a33 Merged revisions 86223-86224,86226,86234 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents: 58450
diff changeset
219 f = open(script_name)
a17b21c27a33 Merged revisions 86223-86224,86226,86234 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents: 58450
diff changeset
220 try:
a17b21c27a33 Merged revisions 86223-86224,86226,86234 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents: 58450
diff changeset
221 exec f.read() in g, l
a17b21c27a33 Merged revisions 86223-86224,86226,86234 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents: 58450
diff changeset
222 finally:
a17b21c27a33 Merged revisions 86223-86224,86226,86234 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents: 58450
diff changeset
223 f.close()
14319
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
224 finally:
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
225 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
226 _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
227 except SystemExit:
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
228 # 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
229 # (ie. error)?
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
230 pass
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
231 except:
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
232 raise
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
233
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
234 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
235 raise RuntimeError, \
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
236 ("'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
237 "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
238 script_name
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
239
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
240 # 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
241 # 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
242 return _setup_distribution