Mercurial > cpython-lru_cache-weakref
annotate Lib/distutils/core.py @ 25838:8540887bcec6 2.2
Backport of 2.183:
Fix memory leak in add_subclass() found by NealN with valgrind.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 18 Oct 2002 13:42:21 +0000 |
| parents | 7a7f557b4d54 |
| children | ca87119255eb |
| 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 |
|
324450ea5450
First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
9 # created 1999/03/01, Greg Ward |
|
324450ea5450
First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
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 * |
|
10435
324450ea5450
First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
15 from distutils.errors import * |
|
12978
77c651131984
Oops, import 'grok_environment_error()'.
Greg Ward <gward@python.net>
parents:
12936
diff
changeset
|
16 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
|
17 |
|
eef2b918d07a
Import the new Extension class, so setup scripts can
Greg Ward <gward@python.net>
parents:
12794
diff
changeset
|
18 # 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
|
19 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
|
20 from distutils.cmd import Command |
|
12801
eef2b918d07a
Import the new Extension class, so setup scripts can
Greg Ward <gward@python.net>
parents:
12794
diff
changeset
|
21 from distutils.extension import Extension |
|
eef2b918d07a
Import the new Extension class, so setup scripts can
Greg Ward <gward@python.net>
parents:
12794
diff
changeset
|
22 |
|
10435
324450ea5450
First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
23 |
|
11816
50f12883cdd7
Changed references to the command class 'options' attribute to 'user_options'.
Greg Ward <gward@python.net>
parents:
11814
diff
changeset
|
24 # 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
|
25 # 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
|
26 # 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
|
27 # 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
|
28 USAGE = """\ |
|
d9643e9c90eb
Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents:
12978
diff
changeset
|
29 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
|
30 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
|
31 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
|
32 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
|
33 """ |
|
10435
324450ea5450
First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
34 |
|
324450ea5450
First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
35 |
|
12761
da02a892d611
Added the DEBUG global (set from the DISTUTILS_DEBUG environment variable).
Greg Ward <gward@python.net>
parents:
12734
diff
changeset
|
36 # If DISTUTILS_DEBUG is anything other than the empty string, we run in |
|
da02a892d611
Added the DEBUG global (set from the DISTUTILS_DEBUG environment variable).
Greg Ward <gward@python.net>
parents:
12734
diff
changeset
|
37 # debug mode. |
|
da02a892d611
Added the DEBUG global (set from the DISTUTILS_DEBUG environment variable).
Greg Ward <gward@python.net>
parents:
12734
diff
changeset
|
38 DEBUG = os.environ.get('DISTUTILS_DEBUG') |
|
da02a892d611
Added the DEBUG global (set from the DISTUTILS_DEBUG environment variable).
Greg Ward <gward@python.net>
parents:
12734
diff
changeset
|
39 |
|
14237
d9643e9c90eb
Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents:
12978
diff
changeset
|
40 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
|
41 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
|
42 return USAGE % vars() |
|
d9643e9c90eb
Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents:
12978
diff
changeset
|
43 |
|
12761
da02a892d611
Added the DEBUG global (set from the DISTUTILS_DEBUG environment variable).
Greg Ward <gward@python.net>
parents:
12734
diff
changeset
|
44 |
|
14319
ddaef45595e2
Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents:
14237
diff
changeset
|
45 # 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
|
46 _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
|
47 _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
|
48 |
|
ddaef45595e2
Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents:
14237
diff
changeset
|
49 |
|
10435
324450ea5450
First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
50 def setup (**attrs): |
|
12822
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12801
diff
changeset
|
51 """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
|
52 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
|
53 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
|
54 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
|
55 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
|
56 the command line. |
|
10435
324450ea5450
First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
57 |
|
12822
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12801
diff
changeset
|
58 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
|
59 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
|
60 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
|
61 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
|
62 attributes of the Distribution instance. |
|
10435
324450ea5450
First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
63 |
|
12822
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12801
diff
changeset
|
64 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
|
65 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
|
66 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
|
67 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
|
68 (for command 'foo_bar') class 'foo_bar' in module |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12801
diff
changeset
|
69 '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
|
70 '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
|
71 '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
|
72 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
|
73 object. |
|
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 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
|
76 '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
|
77 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
|
78 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
|
79 command-specific options that became attributes of each command |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12801
diff
changeset
|
80 object. |
|
723df0c801d1
Reformatted and updated many docstrings.
Greg Ward <gward@python.net>
parents:
12801
diff
changeset
|
81 """ |
|
10435
324450ea5450
First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
82 |
|
14319
ddaef45595e2
Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents:
14237
diff
changeset
|
83 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
|
84 |
|
10435
324450ea5450
First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
85 # Determine the distribution class -- either caller-supplied or |
|
324450ea5450
First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
86 # our Distribution (see below). |
|
14860
18b3def6c4b8
Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents:
14319
diff
changeset
|
87 klass = attrs.get('distclass') |
|
10435
324450ea5450
First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
88 if klass: |
|
324450ea5450
First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
89 del attrs['distclass'] |
|
324450ea5450
First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
90 else: |
|
324450ea5450
First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
91 klass = Distribution |
|
324450ea5450
First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
92 |
|
14237
d9643e9c90eb
Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents:
12978
diff
changeset
|
93 if not attrs.has_key('script_name'): |
|
d9643e9c90eb
Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents:
12978
diff
changeset
|
94 attrs['script_name'] = sys.argv[0] |
|
d9643e9c90eb
Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents:
12978
diff
changeset
|
95 if not attrs.has_key('script_args'): |
|
d9643e9c90eb
Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents:
12978
diff
changeset
|
96 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
|
97 |
|
10435
324450ea5450
First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
98 # Create the Distribution instance, using the remaining arguments |
|
324450ea5450
First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
99 # (ie. everything except distclass) to initialize it |
|
12841
645d57ef1639
Catch DistutilSetupError from the Distribution constructor.
Greg Ward <gward@python.net>
parents:
12825
diff
changeset
|
100 try: |
|
14860
18b3def6c4b8
Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents:
14319
diff
changeset
|
101 _setup_distribution = dist = klass(attrs) |
|
12841
645d57ef1639
Catch DistutilSetupError from the Distribution constructor.
Greg Ward <gward@python.net>
parents:
12825
diff
changeset
|
102 except DistutilsSetupError, msg: |
|
645d57ef1639
Catch DistutilSetupError from the Distribution constructor.
Greg Ward <gward@python.net>
parents:
12825
diff
changeset
|
103 raise SystemExit, "error in setup script: %s" % msg |
|
10435
324450ea5450
First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
104 |
|
14319
ddaef45595e2
Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents:
14237
diff
changeset
|
105 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
|
106 return dist |
|
ddaef45595e2
Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents:
14237
diff
changeset
|
107 |
|
12674
116fc4305a39
Call 'parse_config_files()' at the appropriate point.
Gregory P. Smith <greg@mad-scientist.com>
parents:
12452
diff
changeset
|
108 # 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
|
109 # 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
|
110 dist.parse_config_files() |
| 21267 | 111 |
|
12825
c9298ec637c5
Use Distribution method 'dump_option_dicts()' for debugging output, and only
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
112 if DEBUG: |
|
c9298ec637c5
Use Distribution method 'dump_option_dicts()' for debugging output, and only
Greg Ward <gward@python.net>
parents:
12822
diff
changeset
|
113 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
|
114 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
|
115 |
|
14319
ddaef45595e2
Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents:
14237
diff
changeset
|
116 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
|
117 return dist |
|
ddaef45595e2
Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents:
14237
diff
changeset
|
118 |
|
12674
116fc4305a39
Call 'parse_config_files()' at the appropriate point.
Gregory P. Smith <greg@mad-scientist.com>
parents:
12452
diff
changeset
|
119 # 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
|
120 # 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
|
121 try: |
|
14237
d9643e9c90eb
Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents:
12978
diff
changeset
|
122 ok = dist.parse_command_line() |
|
10435
324450ea5450
First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
123 except DistutilsArgError, msg: |
|
14237
d9643e9c90eb
Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents:
12978
diff
changeset
|
124 script = os.path.basename(dist.script_name) |
|
d9643e9c90eb
Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents:
12978
diff
changeset
|
125 raise SystemExit, \ |
|
d9643e9c90eb
Added 'script_name' and 'script_args' instance attributes to Distribution.
Greg Ward <gward@python.net>
parents:
12978
diff
changeset
|
126 gen_usage(dist.script_name) + "\nerror: %s" % msg |
|
10435
324450ea5450
First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
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 command line):" |
|
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 == "commandline": |
|
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 |
|
10435
324450ea5450
First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
135 # 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
|
136 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
|
137 try: |
|
14860
18b3def6c4b8
Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents:
14319
diff
changeset
|
138 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
|
139 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
|
140 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
|
141 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
|
142 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
|
143 |
|
da02a892d611
Added the DEBUG global (set from the DISTUTILS_DEBUG environment variable).
Greg Ward <gward@python.net>
parents:
12734
diff
changeset
|
144 if DEBUG: |
|
da02a892d611
Added the DEBUG global (set from the DISTUTILS_DEBUG environment variable).
Greg Ward <gward@python.net>
parents:
12734
diff
changeset
|
145 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
|
146 raise |
|
da02a892d611
Added the DEBUG global (set from the DISTUTILS_DEBUG environment variable).
Greg Ward <gward@python.net>
parents:
12734
diff
changeset
|
147 else: |
|
da02a892d611
Added the DEBUG global (set from the DISTUTILS_DEBUG environment variable).
Greg Ward <gward@python.net>
parents:
12734
diff
changeset
|
148 raise SystemExit, error |
| 21267 | 149 |
|
12450
16dc80731c23
Catch DistutilsOptionError in 'setup()' -- it's thrown either because of
Greg Ward <gward@python.net>
parents:
12297
diff
changeset
|
150 except (DistutilsExecError, |
|
16dc80731c23
Catch DistutilsOptionError in 'setup()' -- it's thrown either because of
Greg Ward <gward@python.net>
parents:
12297
diff
changeset
|
151 DistutilsFileError, |
|
12794
074819afdc95
Catch CCompiler exceptions in 'setup()'.
Greg Ward <gward@python.net>
parents:
12761
diff
changeset
|
152 DistutilsOptionError, |
|
074819afdc95
Catch CCompiler exceptions in 'setup()'.
Greg Ward <gward@python.net>
parents:
12761
diff
changeset
|
153 CCompilerError), msg: |
|
12761
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 raise |
|
da02a892d611
Added the DEBUG global (set from the DISTUTILS_DEBUG environment variable).
Greg Ward <gward@python.net>
parents:
12734
diff
changeset
|
156 else: |
|
da02a892d611
Added the DEBUG global (set from the DISTUTILS_DEBUG environment variable).
Greg Ward <gward@python.net>
parents:
12734
diff
changeset
|
157 raise SystemExit, "error: " + str(msg) |
|
10435
324450ea5450
First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
158 |
|
14319
ddaef45595e2
Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents:
14237
diff
changeset
|
159 return dist |
|
ddaef45595e2
Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents:
14237
diff
changeset
|
160 |
|
10435
324450ea5450
First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
161 # setup () |
|
14319
ddaef45595e2
Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents:
14237
diff
changeset
|
162 |
|
ddaef45595e2
Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents:
14237
diff
changeset
|
163 |
|
ddaef45595e2
Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents:
14237
diff
changeset
|
164 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
|
165 """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
|
166 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
|
167 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
|
168 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
|
169 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
|
170 |
|
ddaef45595e2
Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents:
14237
diff
changeset
|
171 '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
|
172 '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
|
173 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
|
174 '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
|
175 the call. |
|
ddaef45595e2
Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents:
14237
diff
changeset
|
176 |
|
ddaef45595e2
Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents:
14237
diff
changeset
|
177 '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
|
178 values: |
|
ddaef45595e2
Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents:
14237
diff
changeset
|
179 init |
|
ddaef45595e2
Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents:
14237
diff
changeset
|
180 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
|
181 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
|
182 config |
|
ddaef45595e2
Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents:
14237
diff
changeset
|
183 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
|
184 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
|
185 commandline |
|
ddaef45595e2
Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents:
14237
diff
changeset
|
186 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
|
187 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
|
188 run [default] |
|
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 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
|
190 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
|
191 |
|
ddaef45595e2
Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents:
14237
diff
changeset
|
192 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
|
193 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
|
194 """ |
|
ddaef45595e2
Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents:
14237
diff
changeset
|
195 if stop_after not in ('init', 'config', 'commandline', 'run'): |
|
ddaef45595e2
Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents:
14237
diff
changeset
|
196 raise ValueError, "invalid value for 'stop_after': %s" % `stop_after` |
|
ddaef45595e2
Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents:
14237
diff
changeset
|
197 |
|
ddaef45595e2
Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents:
14237
diff
changeset
|
198 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
|
199 _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
|
200 |
|
ddaef45595e2
Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents:
14237
diff
changeset
|
201 save_argv = sys.argv |
|
ddaef45595e2
Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents:
14237
diff
changeset
|
202 g = {} |
|
ddaef45595e2
Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents:
14237
diff
changeset
|
203 l = {} |
|
ddaef45595e2
Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents:
14237
diff
changeset
|
204 try: |
|
ddaef45595e2
Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents:
14237
diff
changeset
|
205 try: |
|
ddaef45595e2
Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents:
14237
diff
changeset
|
206 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
|
207 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
|
208 sys.argv[1:] = script_args |
|
ddaef45595e2
Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents:
14237
diff
changeset
|
209 execfile(script_name, g, l) |
|
ddaef45595e2
Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents:
14237
diff
changeset
|
210 finally: |
|
ddaef45595e2
Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents:
14237
diff
changeset
|
211 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
|
212 _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
|
213 except SystemExit: |
|
ddaef45595e2
Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents:
14237
diff
changeset
|
214 # 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
|
215 # (ie. error)? |
|
ddaef45595e2
Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents:
14237
diff
changeset
|
216 pass |
|
ddaef45595e2
Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents:
14237
diff
changeset
|
217 except: |
|
ddaef45595e2
Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents:
14237
diff
changeset
|
218 raise |
|
ddaef45595e2
Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents:
14237
diff
changeset
|
219 |
|
ddaef45595e2
Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents:
14237
diff
changeset
|
220 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
|
221 raise RuntimeError, \ |
|
ddaef45595e2
Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents:
14237
diff
changeset
|
222 ("'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
|
223 "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
|
224 script_name |
|
ddaef45595e2
Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents:
14237
diff
changeset
|
225 |
|
ddaef45595e2
Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents:
14237
diff
changeset
|
226 # 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
|
227 # 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
|
228 #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
|
229 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
|
230 |
|
ddaef45595e2
Added 'run_setup()' to allow outsiders to run a setup script under
Greg Ward <gward@python.net>
parents:
14237
diff
changeset
|
231 # run_setup () |
