annotate Lib/distutils/core.py @ 78069:a8aa77458e12 3.2

Add c_size_t and c_ssize_t to the ctypes summary table.
author Antoine Pitrou <solipsis@pitrou.net>
date Thu, 12 Jul 2012 20:31:50 +0200
parents 3e26c9033306
children 47f98a550d42
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
71089
bd73edea78dc Issue #12451: distutils now opens the setup script in binary mode to read the
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68257
diff changeset
9 import os
bd73edea78dc Issue #12451: distutils now opens the setup script in binary mode to read the
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68257
diff changeset
10 import sys
23683
61358f800b61 Define DEBUG as early as possible to avoid import problems.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23671
diff changeset
11
25212
12949eced55f Use distutils.debug.DEBUG instead of distutils.core.DEBUG.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23683
diff changeset
12 from distutils.debug import DEBUG
10435
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
13 from distutils.errors import *
12978
77c651131984 Oops, import 'grok_environment_error()'.
Greg Ward <gward@python.net>
parents: 12936
diff changeset
14 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
15
eef2b918d07a Import the new Extension class, so setup scripts can
Greg Ward <gward@python.net>
parents: 12794
diff changeset
16 # 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
17 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
18 from distutils.cmd import Command
47067
960ade856078 Merged revisions 62998-63003,63005-63006,63009-63012,63014-63017,63019-63020,63022-63024,63026-63029,63031-63041,63043-63045,63047-63054,63056-63062 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 46304
diff changeset
19 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
20 from distutils.extension import Extension
eef2b918d07a Import the new Extension class, so setup scripts can
Greg Ward <gward@python.net>
parents: 12794
diff changeset
21
11816
50f12883cdd7 Changed references to the command class 'options' attribute to 'user_options'.
Greg Ward <gward@python.net>
parents: 11814
diff changeset
22 # 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
23 # 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
24 # 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
25 # 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
26 USAGE = """\
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 12978
diff changeset
27 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
28 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
29 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
30 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
31 """
10435
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
32
14237
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 12978
diff changeset
33 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
34 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
35 return USAGE % vars()
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 12978
diff changeset
36
12761
da02a892d611 Added the DEBUG global (set from the DISTUTILS_DEBUG environment variable).
Greg Ward <gward@python.net>
parents: 12734
diff changeset
37
14319
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
38 # 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
39 _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
40 _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
41
27416
20df24a13349 Remove the recently-added get_distutil_options(), and just
Andrew M. Kuchling <amk@amk.ca>
parents: 26285
diff changeset
42 # 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
43 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
44 '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
45 '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
46 'description', 'long_description', 'keywords',
34785
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 33965
diff changeset
47 'platforms', 'classifiers', 'download_url',
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 33965
diff changeset
48 'requires', 'provides', 'obsoletes',
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 33965
diff changeset
49 )
27416
20df24a13349 Remove the recently-added get_distutil_options(), and just
Andrew M. Kuchling <amk@amk.ca>
parents: 26285
diff changeset
50
20df24a13349 Remove the recently-added get_distutil_options(), and just
Andrew M. Kuchling <amk@amk.ca>
parents: 26285
diff changeset
51 # 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
52 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
53 'define_macros', 'undef_macros',
20df24a13349 Remove the recently-added get_distutil_options(), and just
Andrew M. Kuchling <amk@amk.ca>
parents: 26285
diff changeset
54 '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
55 '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
56 '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
57
10435
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
58 def setup (**attrs):
12822
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12801
diff changeset
59 """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
60 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
61 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
62 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
63 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
64 the command line.
10435
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
65
12822
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12801
diff changeset
66 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
67 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
68 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
69 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
70 attributes of the Distribution instance.
10435
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
71
12822
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12801
diff changeset
72 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
73 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
74 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
75 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
76 (for command 'foo_bar') class 'foo_bar' in module
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12801
diff changeset
77 '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
78 '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
79 '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
80 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
81 object.
10435
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
82
12822
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12801
diff changeset
83 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
84 '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
85 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
86 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
87 command-specific options that became attributes of each command
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12801
diff changeset
88 object.
723df0c801d1 Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents: 12801
diff changeset
89 """
10435
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
90
14319
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
91 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
92
10435
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
93 # Determine the distribution class -- either caller-supplied or
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
94 # our Distribution (see below).
14860
18b3def6c4b8 Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 14319
diff changeset
95 klass = attrs.get('distclass')
10435
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
96 if klass:
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
97 del attrs['distclass']
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
98 else:
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
99 klass = Distribution
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
100
39575
63237fcefd99 Get rid of dict.has_key(). Boy this has a lot of repercussions!
Guido van Rossum <guido@python.org>
parents: 34785
diff changeset
101 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
102 attrs['script_name'] = os.path.basename(sys.argv[0])
39575
63237fcefd99 Get rid of dict.has_key(). Boy this has a lot of repercussions!
Guido van Rossum <guido@python.org>
parents: 34785
diff changeset
103 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
104 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
105
10435
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
106 # Create the Distribution instance, using the remaining arguments
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
107 # (ie. everything except distclass) to initialize it
12841
645d57ef1639 Catch DistutilSetupError from the Distribution constructor.
Greg Ward <gward@python.net>
parents: 12825
diff changeset
108 try:
14860
18b3def6c4b8 Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 14319
diff changeset
109 _setup_distribution = dist = klass(attrs)
40587
6b18a095c2e7 SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents: 39575
diff changeset
110 except DistutilsSetupError as msg:
39575
63237fcefd99 Get rid of dict.has_key(). Boy this has a lot of repercussions!
Guido van Rossum <guido@python.org>
parents: 34785
diff changeset
111 if 'name' not in attrs:
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42552
diff changeset
112 raise SystemExit("error in setup command: %s" % msg)
42298
3bea8fac3a7c Fix a bug in distutils.core's error handling.
Collin Winter <collinw@gmail.com>
parents: 40775
diff changeset
113 else:
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42552
diff changeset
114 raise SystemExit("error in %s setup command: %s" % \
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42552
diff changeset
115 (attrs['name'], msg))
10435
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
116
14319
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
117 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
118 return dist
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
119
12674
116fc4305a39 Call 'parse_config_files()' at the appropriate point.
Gregory P. Smith <greg@mad-scientist.com>
parents: 12452
diff changeset
120 # 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
121 # 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
122 dist.parse_config_files()
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 14860
diff changeset
123
12825
c9298ec637c5 Use Distribution method 'dump_option_dicts()' for debugging output, and only
Greg Ward <gward@python.net>
parents: 12822
diff changeset
124 if DEBUG:
40775
4cdf21a0dbbc Fix most trivially-findable print statements.
Guido van Rossum <guido@python.org>
parents: 40587
diff changeset
125 print("options (after parsing config files):")
12825
c9298ec637c5 Use Distribution method 'dump_option_dicts()' for debugging output, and only
Greg Ward <gward@python.net>
parents: 12822
diff changeset
126 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
127
14319
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
128 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
129 return dist
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
130
12674
116fc4305a39 Call 'parse_config_files()' at the appropriate point.
Gregory P. Smith <greg@mad-scientist.com>
parents: 12452
diff changeset
131 # 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
132 # 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
133 try:
14237
d9643e9c90eb Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents: 12978
diff changeset
134 ok = dist.parse_command_line()
40587
6b18a095c2e7 SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents: 39575
diff changeset
135 except DistutilsArgError as msg:
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42552
diff changeset
136 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
137
12825
c9298ec637c5 Use Distribution method 'dump_option_dicts()' for debugging output, and only
Greg Ward <gward@python.net>
parents: 12822
diff changeset
138 if DEBUG:
40775
4cdf21a0dbbc Fix most trivially-findable print statements.
Guido van Rossum <guido@python.org>
parents: 40587
diff changeset
139 print("options (after parsing command line):")
12825
c9298ec637c5 Use Distribution method 'dump_option_dicts()' for debugging output, and only
Greg Ward <gward@python.net>
parents: 12822
diff changeset
140 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
141
14319
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
142 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
143 return dist
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
144
10435
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
145 # 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
146 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
147 try:
14860
18b3def6c4b8 Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents: 14319
diff changeset
148 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
149 except KeyboardInterrupt:
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42552
diff changeset
150 raise SystemExit("interrupted")
40587
6b18a095c2e7 SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents: 39575
diff changeset
151 except (IOError, os.error) as exc:
12936
3427b0f85a7c Changed to use the new 'grok_environment_error()' function instead of
Greg Ward <gward@python.net>
parents: 12841
diff changeset
152 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
153
da02a892d611 Added the DEBUG global (set from the DISTUTILS_DEBUG environment variable).
Greg Ward <gward@python.net>
parents: 12734
diff changeset
154 if DEBUG:
da02a892d611 Added the DEBUG global (set from the DISTUTILS_DEBUG environment variable).
Greg Ward <gward@python.net>
parents: 12734
diff changeset
155 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
156 raise
da02a892d611 Added the DEBUG global (set from the DISTUTILS_DEBUG environment variable).
Greg Ward <gward@python.net>
parents: 12734
diff changeset
157 else:
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42552
diff changeset
158 raise SystemExit(error)
21267
7a7f557b4d54 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 14860
diff changeset
159
26115
9048207992f0 [Bug #233259] Ugly traceback for DistutilsPlatformError
Andrew M. Kuchling <amk@amk.ca>
parents: 26095
diff changeset
160 except (DistutilsError,
40587
6b18a095c2e7 SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents: 39575
diff changeset
161 CCompilerError) as msg:
12761
da02a892d611 Added the DEBUG global (set from the DISTUTILS_DEBUG environment variable).
Greg Ward <gward@python.net>
parents: 12734
diff changeset
162 if DEBUG:
da02a892d611 Added the DEBUG global (set from the DISTUTILS_DEBUG environment variable).
Greg Ward <gward@python.net>
parents: 12734
diff changeset
163 raise
da02a892d611 Added the DEBUG global (set from the DISTUTILS_DEBUG environment variable).
Greg Ward <gward@python.net>
parents: 12734
diff changeset
164 else:
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42552
diff changeset
165 raise SystemExit("error: " + str(msg))
10435
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
166
14319
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
167 return dist
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
168
10435
324450ea5450 First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff changeset
169 # setup ()
14319
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
170
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
171
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
172 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
173 """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
174 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
175 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
176 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
177 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
178
42552
ac192f89c109 Kill execfile(), use exec() instead
Neal Norwitz <nnorwitz@gmail.com>
parents: 42298
diff changeset
179 'script_name' is a file that will be read and run with 'exec()';
14319
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
180 '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
181 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
182 '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
183 the call.
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
184
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
185 '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
186 values:
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
187 init
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
188 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
189 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
190 config
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
191 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
192 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
193 commandline
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
194 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
195 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
196 run [default]
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
197 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
198 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
199
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
200 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
201 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
202 """
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
203 if stop_after not in ('init', 'config', 'commandline', 'run'):
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42552
diff changeset
204 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
205
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
206 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
207 _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
208
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
209 save_argv = sys.argv
46304
3442e9e6b2cf Merged revisions 61440-61441,61443,61445-61448,61451-61452,61455-61457,61459-61464,61466-61467,61469-61470,61476-61477,61479,61481-61482,61485,61487,61490,61493-61494,61497,61499-61502,61505-61506,61508,61511-61514,61519,61521-61522,61530-61531,61533-61537,61541-61555,61557-61558,61561-61562,61566-61569,61572-61574,61578-61579,61583-61584,61588-61589,61592,61594,61598-61601,61603-61604,61607-61612,61617,61619-61620,61624,61626,61628-61630,61635-61638,61640-61643,61645,61648,61653-61655,61659-61662,61664,61666,61668-61671,61673,61675,61679-61680,61682,61685-61686,61689-61695,61697-61699,61701-61703,61706,61710,61713,61717,61723,61726-61730,61736,61738,61740,61742,61745-61752,61754-61760,61762-61764,61768,61770-61772,61774-61775,61784-61787,61789-61792,61794-61795,61797-61806,61808-61809,61811-61812,61814-61819,61824,61826-61833,61835-61840,61843-61845,61848,61850,61854-61862,61865-61866,61868,61872-61873,61876-61877,61883-61888,61890-61891,61893-61899,61901-61903,61905-61912,61914,61917,61920-61921,61927,61930,61932-61934,61939,61941-61942,61944-61951,61955,61960-61963,61980,61982-61983,61991,61994-61996,62001-62003,62008-62010,62016-62017,62022,62024,62027,62031-62034,62041,62045-62046,62055-62058,62060-62066,62068-62074,62076-62079,62081-62083,62086-62089,62092-62094,62098,62101,62104,62106-62109,62115-62122,62124-62125,62127-62128,62130,62132,62134-62137,62139-62142,62144,62146-62148,62150-62152,62155-62161 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents: 43026
diff changeset
210 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
211 l = {}
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
212 try:
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
213 try:
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
214 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
215 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
216 sys.argv[1:] = script_args
71089
bd73edea78dc Issue #12451: distutils now opens the setup script in binary mode to read the
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68257
diff changeset
217 with open(script_name, 'rb') as f:
66007
f5dd4a54d79b Merged revisions 86223-86224,86226,86234 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents: 47067
diff changeset
218 exec(f.read(), 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
219 finally:
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 = save_argv
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
221 _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
222 except SystemExit:
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
223 # 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
224 # (ie. error)?
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
225 pass
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
226 except:
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
227 raise
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
228
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
229 if _setup_distribution is None:
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42552
diff changeset
230 raise RuntimeError(("'distutils.core.setup()' was never called -- "
14319
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
231 "perhaps '%s' is not a Distutils setup script?") % \
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42552
diff changeset
232 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
233
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
234 # 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
235 # 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
236 #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
237 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
238
ddaef45595e2 Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents: 14237
diff changeset
239 # run_setup ()