annotate Lib/distutils/command/install_lib.py @ 51684:27268ef04708 legacy-trunk

#2279 added the plain path case for data_files
author Tarek Ziadé <ziade.tarek@gmail.com>
date Tue, 17 Feb 2009 09:42:44 +0000
parents 4e82fb1aeb02
children c60cda3418b5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
51048
4e82fb1aeb02 added missing module docstring
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51047
diff changeset
1 """distutils.command.install_lib
4e82fb1aeb02 added missing module docstring
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51047
diff changeset
2
4e82fb1aeb02 added missing module docstring
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51047
diff changeset
3 Implements the Distutils 'install_lib' command
4e82fb1aeb02 added missing module docstring
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51047
diff changeset
4 (install all Python modules)."""
4e82fb1aeb02 added missing module docstring
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51047
diff changeset
5
11897
017e592c0fd2 Changed '__rcsid__' to '__revision__'.
Greg Ward <gward@python.net>
parents: 11859
diff changeset
6 __revision__ = "$Id$"
10437
3bc8f53041c0 First checkin of real Distutils command modules.
Greg Ward <gward@python.net>
parents:
diff changeset
7
45468
1d84bf5f9478 Patch #2167 from calvin: Remove unused imports
Christian Heimes <christian@cheimes.de>
parents: 34082
diff changeset
8 import os
14961
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
9 from types import IntType
10437
3bc8f53041c0 First checkin of real Distutils command modules.
Greg Ward <gward@python.net>
parents:
diff changeset
10 from distutils.core import Command
14961
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
11 from distutils.errors import DistutilsOptionError
10437
3bc8f53041c0 First checkin of real Distutils command modules.
Greg Ward <gward@python.net>
parents:
diff changeset
12
32841
0856d98e2a68 Since build_py handles package data installation, the list of outputs
Fred Drake <fdrake@acm.org>
parents: 26285
diff changeset
13
0856d98e2a68 Since build_py handles package data installation, the list of outputs
Fred Drake <fdrake@acm.org>
parents: 26285
diff changeset
14 # Extension for Python source files.
34082
d2f26eaace2c Restore Python 2.1 compatibility (os.extsep was introduced in Python 2.2).
Marc-André Lemburg <mal@egenix.com>
parents: 33965
diff changeset
15 if hasattr(os, 'extsep'):
d2f26eaace2c Restore Python 2.1 compatibility (os.extsep was introduced in Python 2.2).
Marc-André Lemburg <mal@egenix.com>
parents: 33965
diff changeset
16 PYTHON_SOURCE_EXTENSION = os.extsep + "py"
d2f26eaace2c Restore Python 2.1 compatibility (os.extsep was introduced in Python 2.2).
Marc-André Lemburg <mal@egenix.com>
parents: 33965
diff changeset
17 else:
d2f26eaace2c Restore Python 2.1 compatibility (os.extsep was introduced in Python 2.2).
Marc-André Lemburg <mal@egenix.com>
parents: 33965
diff changeset
18 PYTHON_SOURCE_EXTENSION = ".py"
32841
0856d98e2a68 Since build_py handles package data installation, the list of outputs
Fred Drake <fdrake@acm.org>
parents: 26285
diff changeset
19
12042
5caccace1dcf Fixed the class name.
Greg Ward <gward@python.net>
parents: 11897
diff changeset
20 class install_lib (Command):
10437
3bc8f53041c0 First checkin of real Distutils command modules.
Greg Ward <gward@python.net>
parents:
diff changeset
21
12730
147d0b4144ea Fixed command description.
Greg Ward <gward@python.net>
parents: 12721
diff changeset
22 description = "install all Python modules (extensions and pure Python)"
11683
47f75a17b103 Added 'description' class attribute to every command class (to help the
Greg Ward <gward@python.net>
parents: 11680
diff changeset
23
14961
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
24 # The byte-compilation options are a tad confusing. Here are the
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
25 # possible scenarios:
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
26 # 1) no compilation at all (--no-compile --no-optimize)
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
27 # 2) compile .pyc only (--compile --no-optimize; default)
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
28 # 3) compile .pyc and "level 1" .pyo (--compile --optimize)
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
29 # 4) compile "level 1" .pyo only (--no-compile --optimize)
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
30 # 5) compile .pyc and "level 2" .pyo (--compile --optimize-more)
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
31 # 6) compile "level 2" .pyo only (--no-compile --optimize-more)
21268
d296e6bb17e5 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 14984
diff changeset
32 #
14961
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
33 # The UI for this is two option, 'compile' and 'optimize'.
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
34 # 'compile' is strictly boolean, and only decides whether to
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
35 # generate .pyc files. 'optimize' is three-way (0, 1, or 2), and
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
36 # decides both whether to generate .pyo files and what level of
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
37 # optimization to use.
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
38
11815
03902bc0214a Renamed all 'options' class attributes to 'user_options'.
Greg Ward <gward@python.net>
parents: 11813
diff changeset
39 user_options = [
03902bc0214a Renamed all 'options' class attributes to 'user_options'.
Greg Ward <gward@python.net>
parents: 11813
diff changeset
40 ('install-dir=', 'd', "directory to install to"),
03902bc0214a Renamed all 'options' class attributes to 'user_options'.
Greg Ward <gward@python.net>
parents: 11813
diff changeset
41 ('build-dir=','b', "build directory (where to install from)"),
14540
35ae8dff8ed0 Added --force (-f) option to force installation (including bytecode
Greg Ward <gward@python.net>
parents: 13871
diff changeset
42 ('force', 'f', "force installation (overwrite existing files)"),
14961
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
43 ('compile', 'c', "compile .py to .pyc [default]"),
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
44 ('no-compile', None, "don't compile .py files"),
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
45 ('optimize=', 'O',
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
46 "also compile with optimization: -O1 for \"python -O\", "
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
47 "-O2 for \"python -OO\", and -O0 to disable [default: -O0]"),
12680
b89da202d18d Added --skip-build option, so lazy debuggers/testers (mainly me) don't
Gregory P. Smith <greg@mad-scientist.com>
parents: 12603
diff changeset
48 ('skip-build', None, "skip the build steps"),
11815
03902bc0214a Renamed all 'options' class attributes to 'user_options'.
Greg Ward <gward@python.net>
parents: 11813
diff changeset
49 ]
21268
d296e6bb17e5 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 14984
diff changeset
50
14961
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
51 boolean_options = ['force', 'compile', 'skip-build']
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
52 negative_opt = {'no-compile' : 'compile'}
14829
b1f220f636ed Added 'boolean_options' list to support config file parsing.
Greg Ward <gward@python.net>
parents: 14780
diff changeset
53
10437
3bc8f53041c0 First checkin of real Distutils command modules.
Greg Ward <gward@python.net>
parents:
diff changeset
54
11817
476eaa38e2d6 Renamed 'set_default_options()' to 'initialize_options()', and
Greg Ward <gward@python.net>
parents: 11815
diff changeset
55 def initialize_options (self):
10437
3bc8f53041c0 First checkin of real Distutils command modules.
Greg Ward <gward@python.net>
parents:
diff changeset
56 # let the 'install' command dictate our installation directory
11338
42941e2eb9d8 Renamed many options to be consistent across commands.
Greg Ward <gward@python.net>
parents: 11283
diff changeset
57 self.install_dir = None
10437
3bc8f53041c0 First checkin of real Distutils command modules.
Greg Ward <gward@python.net>
parents:
diff changeset
58 self.build_dir = None
14540
35ae8dff8ed0 Added --force (-f) option to force installation (including bytecode
Greg Ward <gward@python.net>
parents: 13871
diff changeset
59 self.force = 0
14961
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
60 self.compile = None
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
61 self.optimize = None
12680
b89da202d18d Added --skip-build option, so lazy debuggers/testers (mainly me) don't
Gregory P. Smith <greg@mad-scientist.com>
parents: 12603
diff changeset
62 self.skip_build = None
10437
3bc8f53041c0 First checkin of real Distutils command modules.
Greg Ward <gward@python.net>
parents:
diff changeset
63
11817
476eaa38e2d6 Renamed 'set_default_options()' to 'initialize_options()', and
Greg Ward <gward@python.net>
parents: 11815
diff changeset
64 def finalize_options (self):
10437
3bc8f53041c0 First checkin of real Distutils command modules.
Greg Ward <gward@python.net>
parents:
diff changeset
65
11283
cdd928d2293c Changed selection of installation directories (in 'set_final_options()')
Greg Ward <gward@python.net>
parents: 11248
diff changeset
66 # Get all the information we need to install pure Python modules
cdd928d2293c Changed selection of installation directories (in 'set_final_options()')
Greg Ward <gward@python.net>
parents: 11248
diff changeset
67 # from the umbrella 'install' command -- build (source) directory,
cdd928d2293c Changed selection of installation directories (in 'set_final_options()')
Greg Ward <gward@python.net>
parents: 11248
diff changeset
68 # install (target) directory, and whether to compile .py files.
14779
7ba493bc24a0 Whitespace tweaks.
Greg Ward <gward@python.net>
parents: 14540
diff changeset
69 self.set_undefined_options('install',
7ba493bc24a0 Whitespace tweaks.
Greg Ward <gward@python.net>
parents: 14540
diff changeset
70 ('build_lib', 'build_dir'),
7ba493bc24a0 Whitespace tweaks.
Greg Ward <gward@python.net>
parents: 14540
diff changeset
71 ('install_lib', 'install_dir'),
7ba493bc24a0 Whitespace tweaks.
Greg Ward <gward@python.net>
parents: 14540
diff changeset
72 ('force', 'force'),
14961
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
73 ('compile', 'compile'),
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
74 ('optimize', 'optimize'),
14779
7ba493bc24a0 Whitespace tweaks.
Greg Ward <gward@python.net>
parents: 14540
diff changeset
75 ('skip_build', 'skip_build'),
7ba493bc24a0 Whitespace tweaks.
Greg Ward <gward@python.net>
parents: 14540
diff changeset
76 )
10437
3bc8f53041c0 First checkin of real Distutils command modules.
Greg Ward <gward@python.net>
parents:
diff changeset
77
14961
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
78 if self.compile is None:
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
79 self.compile = 1
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
80 if self.optimize is None:
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
81 self.optimize = 0
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
82
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
83 if type(self.optimize) is not IntType:
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
84 try:
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
85 self.optimize = int(self.optimize)
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
86 assert 0 <= self.optimize <= 2
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
87 except (ValueError, AssertionError):
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
88 raise DistutilsOptionError, "optimize must be 0, 1, or 2"
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
89
10437
3bc8f53041c0 First checkin of real Distutils command modules.
Greg Ward <gward@python.net>
parents:
diff changeset
90 def run (self):
3bc8f53041c0 First checkin of real Distutils command modules.
Greg Ward <gward@python.net>
parents:
diff changeset
91
12098
881257d1e854 Be sure to run both 'build_py' and 'build_ext', now that this command
Greg Ward <gward@python.net>
parents: 12042
diff changeset
92 # Make sure we have built everything we need first
14780
064e434e744f Split 'run()' up into 'build()', 'install()', and 'bytecompile()' (for
Greg Ward <gward@python.net>
parents: 14779
diff changeset
93 self.build()
21268
d296e6bb17e5 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 14984
diff changeset
94
14780
064e434e744f Split 'run()' up into 'build()', 'install()', and 'bytecompile()' (for
Greg Ward <gward@python.net>
parents: 14779
diff changeset
95 # Install everything: simply dump the entire contents of the build
064e434e744f Split 'run()' up into 'build()', 'install()', and 'bytecompile()' (for
Greg Ward <gward@python.net>
parents: 14779
diff changeset
96 # directory to the installation directory (that's the beauty of
064e434e744f Split 'run()' up into 'build()', 'install()', and 'bytecompile()' (for
Greg Ward <gward@python.net>
parents: 14779
diff changeset
97 # having a build directory!)
064e434e744f Split 'run()' up into 'build()', 'install()', and 'bytecompile()' (for
Greg Ward <gward@python.net>
parents: 14779
diff changeset
98 outfiles = self.install()
064e434e744f Split 'run()' up into 'build()', 'install()', and 'bytecompile()' (for
Greg Ward <gward@python.net>
parents: 14779
diff changeset
99
064e434e744f Split 'run()' up into 'build()', 'install()', and 'bytecompile()' (for
Greg Ward <gward@python.net>
parents: 14779
diff changeset
100 # (Optionally) compile .py to .pyc
14959
b031abca3e91 From 'run()', only call 'bytecompile()' if we actually have
Greg Ward <gward@python.net>
parents: 14952
diff changeset
101 if outfiles is not None and self.distribution.has_pure_modules():
14961
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
102 self.byte_compile(outfiles)
14780
064e434e744f Split 'run()' up into 'build()', 'install()', and 'bytecompile()' (for
Greg Ward <gward@python.net>
parents: 14779
diff changeset
103
064e434e744f Split 'run()' up into 'build()', 'install()', and 'bytecompile()' (for
Greg Ward <gward@python.net>
parents: 14779
diff changeset
104 # run ()
064e434e744f Split 'run()' up into 'build()', 'install()', and 'bytecompile()' (for
Greg Ward <gward@python.net>
parents: 14779
diff changeset
105
064e434e744f Split 'run()' up into 'build()', 'install()', and 'bytecompile()' (for
Greg Ward <gward@python.net>
parents: 14779
diff changeset
106
064e434e744f Split 'run()' up into 'build()', 'install()', and 'bytecompile()' (for
Greg Ward <gward@python.net>
parents: 14779
diff changeset
107 # -- Top-level worker functions ------------------------------------
064e434e744f Split 'run()' up into 'build()', 'install()', and 'bytecompile()' (for
Greg Ward <gward@python.net>
parents: 14779
diff changeset
108 # (called from 'run()')
064e434e744f Split 'run()' up into 'build()', 'install()', and 'bytecompile()' (for
Greg Ward <gward@python.net>
parents: 14779
diff changeset
109
064e434e744f Split 'run()' up into 'build()', 'install()', and 'bytecompile()' (for
Greg Ward <gward@python.net>
parents: 14779
diff changeset
110 def build (self):
12680
b89da202d18d Added --skip-build option, so lazy debuggers/testers (mainly me) don't
Gregory P. Smith <greg@mad-scientist.com>
parents: 12603
diff changeset
111 if not self.skip_build:
b89da202d18d Added --skip-build option, so lazy debuggers/testers (mainly me) don't
Gregory P. Smith <greg@mad-scientist.com>
parents: 12603
diff changeset
112 if self.distribution.has_pure_modules():
14779
7ba493bc24a0 Whitespace tweaks.
Greg Ward <gward@python.net>
parents: 14540
diff changeset
113 self.run_command('build_py')
12680
b89da202d18d Added --skip-build option, so lazy debuggers/testers (mainly me) don't
Gregory P. Smith <greg@mad-scientist.com>
parents: 12603
diff changeset
114 if self.distribution.has_ext_modules():
14779
7ba493bc24a0 Whitespace tweaks.
Greg Ward <gward@python.net>
parents: 14540
diff changeset
115 self.run_command('build_ext')
21268
d296e6bb17e5 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 14984
diff changeset
116
14780
064e434e744f Split 'run()' up into 'build()', 'install()', and 'bytecompile()' (for
Greg Ward <gward@python.net>
parents: 14779
diff changeset
117 def install (self):
12721
a598ace01943 Check if the claimed build directory doesn't exist, and warn that we don't
Greg Ward <gward@python.net>
parents: 12696
diff changeset
118 if os.path.isdir(self.build_dir):
14779
7ba493bc24a0 Whitespace tweaks.
Greg Ward <gward@python.net>
parents: 14540
diff changeset
119 outfiles = self.copy_tree(self.build_dir, self.install_dir)
12721
a598ace01943 Check if the claimed build directory doesn't exist, and warn that we don't
Greg Ward <gward@python.net>
parents: 12696
diff changeset
120 else:
a598ace01943 Check if the claimed build directory doesn't exist, and warn that we don't
Greg Ward <gward@python.net>
parents: 12696
diff changeset
121 self.warn("'%s' does not exist -- no Python modules to install" %
a598ace01943 Check if the claimed build directory doesn't exist, and warn that we don't
Greg Ward <gward@python.net>
parents: 12696
diff changeset
122 self.build_dir)
a598ace01943 Check if the claimed build directory doesn't exist, and warn that we don't
Greg Ward <gward@python.net>
parents: 12696
diff changeset
123 return
14780
064e434e744f Split 'run()' up into 'build()', 'install()', and 'bytecompile()' (for
Greg Ward <gward@python.net>
parents: 14779
diff changeset
124 return outfiles
12098
881257d1e854 Be sure to run both 'build_py' and 'build_ext', now that this command
Greg Ward <gward@python.net>
parents: 12042
diff changeset
125
14961
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
126 def byte_compile (self, files):
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
127 from distutils.util import byte_compile
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
128
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
129 # Get the "--root" directory supplied to the "install" command,
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
130 # and use it as a prefix to strip off the purported filename
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
131 # encoded in bytecode files. This is far from complete, but it
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
132 # should at least generate usable bytecode in RPM distributions.
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
133 install_root = self.get_finalized_command('install').root
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
134
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
135 if self.compile:
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
136 byte_compile(files, optimize=0,
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23587
diff changeset
137 force=self.force, prefix=install_root,
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23587
diff changeset
138 dry_run=self.dry_run)
14961
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
139 if self.optimize > 0:
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
140 byte_compile(files, optimize=self.optimize,
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23587
diff changeset
141 force=self.force, prefix=install_root,
14961
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
142 verbose=self.verbose, dry_run=self.dry_run)
14780
064e434e744f Split 'run()' up into 'build()', 'install()', and 'bytecompile()' (for
Greg Ward <gward@python.net>
parents: 14779
diff changeset
143
10437
3bc8f53041c0 First checkin of real Distutils command modules.
Greg Ward <gward@python.net>
parents:
diff changeset
144
14780
064e434e744f Split 'run()' up into 'build()', 'install()', and 'bytecompile()' (for
Greg Ward <gward@python.net>
parents: 14779
diff changeset
145 # -- Utility methods -----------------------------------------------
12098
881257d1e854 Be sure to run both 'build_py' and 'build_ext', now that this command
Greg Ward <gward@python.net>
parents: 12042
diff changeset
146
881257d1e854 Be sure to run both 'build_py' and 'build_ext', now that this command
Greg Ward <gward@python.net>
parents: 12042
diff changeset
147 def _mutate_outputs (self, has_any, build_cmd, cmd_option, output_dir):
881257d1e854 Be sure to run both 'build_py' and 'build_ext', now that this command
Greg Ward <gward@python.net>
parents: 12042
diff changeset
148
881257d1e854 Be sure to run both 'build_py' and 'build_ext', now that this command
Greg Ward <gward@python.net>
parents: 12042
diff changeset
149 if not has_any:
881257d1e854 Be sure to run both 'build_py' and 'build_ext', now that this command
Greg Ward <gward@python.net>
parents: 12042
diff changeset
150 return []
881257d1e854 Be sure to run both 'build_py' and 'build_ext', now that this command
Greg Ward <gward@python.net>
parents: 12042
diff changeset
151
14779
7ba493bc24a0 Whitespace tweaks.
Greg Ward <gward@python.net>
parents: 14540
diff changeset
152 build_cmd = self.get_finalized_command(build_cmd)
12098
881257d1e854 Be sure to run both 'build_py' and 'build_ext', now that this command
Greg Ward <gward@python.net>
parents: 12042
diff changeset
153 build_files = build_cmd.get_outputs()
14779
7ba493bc24a0 Whitespace tweaks.
Greg Ward <gward@python.net>
parents: 14540
diff changeset
154 build_dir = getattr(build_cmd, cmd_option)
12098
881257d1e854 Be sure to run both 'build_py' and 'build_ext', now that this command
Greg Ward <gward@python.net>
parents: 12042
diff changeset
155
14779
7ba493bc24a0 Whitespace tweaks.
Greg Ward <gward@python.net>
parents: 14540
diff changeset
156 prefix_len = len(build_dir) + len(os.sep)
12098
881257d1e854 Be sure to run both 'build_py' and 'build_ext', now that this command
Greg Ward <gward@python.net>
parents: 12042
diff changeset
157 outputs = []
881257d1e854 Be sure to run both 'build_py' and 'build_ext', now that this command
Greg Ward <gward@python.net>
parents: 12042
diff changeset
158 for file in build_files:
14779
7ba493bc24a0 Whitespace tweaks.
Greg Ward <gward@python.net>
parents: 14540
diff changeset
159 outputs.append(os.path.join(output_dir, file[prefix_len:]))
12098
881257d1e854 Be sure to run both 'build_py' and 'build_ext', now that this command
Greg Ward <gward@python.net>
parents: 12042
diff changeset
160
881257d1e854 Be sure to run both 'build_py' and 'build_ext', now that this command
Greg Ward <gward@python.net>
parents: 12042
diff changeset
161 return outputs
881257d1e854 Be sure to run both 'build_py' and 'build_ext', now that this command
Greg Ward <gward@python.net>
parents: 12042
diff changeset
162
881257d1e854 Be sure to run both 'build_py' and 'build_ext', now that this command
Greg Ward <gward@python.net>
parents: 12042
diff changeset
163 # _mutate_outputs ()
12696
a49e450688e2 Added '_bytecode_filenames()' method, and use it in 'get_outputs()'
Gregory P. Smith <greg@mad-scientist.com>
parents: 12680
diff changeset
164
a49e450688e2 Added '_bytecode_filenames()' method, and use it in 'get_outputs()'
Gregory P. Smith <greg@mad-scientist.com>
parents: 12680
diff changeset
165 def _bytecode_filenames (self, py_filenames):
a49e450688e2 Added '_bytecode_filenames()' method, and use it in 'get_outputs()'
Gregory P. Smith <greg@mad-scientist.com>
parents: 12680
diff changeset
166 bytecode_files = []
a49e450688e2 Added '_bytecode_filenames()' method, and use it in 'get_outputs()'
Gregory P. Smith <greg@mad-scientist.com>
parents: 12680
diff changeset
167 for py_file in py_filenames:
32841
0856d98e2a68 Since build_py handles package data installation, the list of outputs
Fred Drake <fdrake@acm.org>
parents: 26285
diff changeset
168 # Since build_py handles package data installation, the
0856d98e2a68 Since build_py handles package data installation, the list of outputs
Fred Drake <fdrake@acm.org>
parents: 26285
diff changeset
169 # list of outputs can contain more than just .py files.
0856d98e2a68 Since build_py handles package data installation, the list of outputs
Fred Drake <fdrake@acm.org>
parents: 26285
diff changeset
170 # Make sure we only report bytecode for the .py files.
0856d98e2a68 Since build_py handles package data installation, the list of outputs
Fred Drake <fdrake@acm.org>
parents: 26285
diff changeset
171 ext = os.path.splitext(os.path.normcase(py_file))[1]
0856d98e2a68 Since build_py handles package data installation, the list of outputs
Fred Drake <fdrake@acm.org>
parents: 26285
diff changeset
172 if ext != PYTHON_SOURCE_EXTENSION:
0856d98e2a68 Since build_py handles package data installation, the list of outputs
Fred Drake <fdrake@acm.org>
parents: 26285
diff changeset
173 continue
14961
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
174 if self.compile:
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
175 bytecode_files.append(py_file + "c")
14964
54ec5ec32352 Typo fix.
Greg Ward <gward@python.net>
parents: 14961
diff changeset
176 if self.optimize > 0:
14961
ebaeb19e0380 Finished the overhaul of byte-compilation options: there's now a 6-way
Greg Ward <gward@python.net>
parents: 14959
diff changeset
177 bytecode_files.append(py_file + "o")
12696
a49e450688e2 Added '_bytecode_filenames()' method, and use it in 'get_outputs()'
Gregory P. Smith <greg@mad-scientist.com>
parents: 12680
diff changeset
178
a49e450688e2 Added '_bytecode_filenames()' method, and use it in 'get_outputs()'
Gregory P. Smith <greg@mad-scientist.com>
parents: 12680
diff changeset
179 return bytecode_files
21268
d296e6bb17e5 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 14984
diff changeset
180
14780
064e434e744f Split 'run()' up into 'build()', 'install()', and 'bytecompile()' (for
Greg Ward <gward@python.net>
parents: 14779
diff changeset
181
064e434e744f Split 'run()' up into 'build()', 'install()', and 'bytecompile()' (for
Greg Ward <gward@python.net>
parents: 14779
diff changeset
182 # -- External interface --------------------------------------------
064e434e744f Split 'run()' up into 'build()', 'install()', and 'bytecompile()' (for
Greg Ward <gward@python.net>
parents: 14779
diff changeset
183 # (called by outsiders)
064e434e744f Split 'run()' up into 'build()', 'install()', and 'bytecompile()' (for
Greg Ward <gward@python.net>
parents: 14779
diff changeset
184
12098
881257d1e854 Be sure to run both 'build_py' and 'build_ext', now that this command
Greg Ward <gward@python.net>
parents: 12042
diff changeset
185 def get_outputs (self):
881257d1e854 Be sure to run both 'build_py' and 'build_ext', now that this command
Greg Ward <gward@python.net>
parents: 12042
diff changeset
186 """Return the list of files that would be installed if this command
881257d1e854 Be sure to run both 'build_py' and 'build_ext', now that this command
Greg Ward <gward@python.net>
parents: 12042
diff changeset
187 were actually run. Not affected by the "dry-run" flag or whether
14779
7ba493bc24a0 Whitespace tweaks.
Greg Ward <gward@python.net>
parents: 14540
diff changeset
188 modules have actually been built yet.
7ba493bc24a0 Whitespace tweaks.
Greg Ward <gward@python.net>
parents: 14540
diff changeset
189 """
12098
881257d1e854 Be sure to run both 'build_py' and 'build_ext', now that this command
Greg Ward <gward@python.net>
parents: 12042
diff changeset
190 pure_outputs = \
14779
7ba493bc24a0 Whitespace tweaks.
Greg Ward <gward@python.net>
parents: 14540
diff changeset
191 self._mutate_outputs(self.distribution.has_pure_modules(),
7ba493bc24a0 Whitespace tweaks.
Greg Ward <gward@python.net>
parents: 14540
diff changeset
192 'build_py', 'build_lib',
7ba493bc24a0 Whitespace tweaks.
Greg Ward <gward@python.net>
parents: 14540
diff changeset
193 self.install_dir)
12696
a49e450688e2 Added '_bytecode_filenames()' method, and use it in 'get_outputs()'
Gregory P. Smith <greg@mad-scientist.com>
parents: 12680
diff changeset
194 if self.compile:
a49e450688e2 Added '_bytecode_filenames()' method, and use it in 'get_outputs()'
Gregory P. Smith <greg@mad-scientist.com>
parents: 12680
diff changeset
195 bytecode_outputs = self._bytecode_filenames(pure_outputs)
a49e450688e2 Added '_bytecode_filenames()' method, and use it in 'get_outputs()'
Gregory P. Smith <greg@mad-scientist.com>
parents: 12680
diff changeset
196 else:
a49e450688e2 Added '_bytecode_filenames()' method, and use it in 'get_outputs()'
Gregory P. Smith <greg@mad-scientist.com>
parents: 12680
diff changeset
197 bytecode_outputs = []
12098
881257d1e854 Be sure to run both 'build_py' and 'build_ext', now that this command
Greg Ward <gward@python.net>
parents: 12042
diff changeset
198
881257d1e854 Be sure to run both 'build_py' and 'build_ext', now that this command
Greg Ward <gward@python.net>
parents: 12042
diff changeset
199 ext_outputs = \
14779
7ba493bc24a0 Whitespace tweaks.
Greg Ward <gward@python.net>
parents: 14540
diff changeset
200 self._mutate_outputs(self.distribution.has_ext_modules(),
7ba493bc24a0 Whitespace tweaks.
Greg Ward <gward@python.net>
parents: 14540
diff changeset
201 'build_ext', 'build_lib',
7ba493bc24a0 Whitespace tweaks.
Greg Ward <gward@python.net>
parents: 14540
diff changeset
202 self.install_dir)
12098
881257d1e854 Be sure to run both 'build_py' and 'build_ext', now that this command
Greg Ward <gward@python.net>
parents: 12042
diff changeset
203
12696
a49e450688e2 Added '_bytecode_filenames()' method, and use it in 'get_outputs()'
Gregory P. Smith <greg@mad-scientist.com>
parents: 12680
diff changeset
204 return pure_outputs + bytecode_outputs + ext_outputs
12098
881257d1e854 Be sure to run both 'build_py' and 'build_ext', now that this command
Greg Ward <gward@python.net>
parents: 12042
diff changeset
205
881257d1e854 Be sure to run both 'build_py' and 'build_ext', now that this command
Greg Ward <gward@python.net>
parents: 12042
diff changeset
206 # get_outputs ()
881257d1e854 Be sure to run both 'build_py' and 'build_ext', now that this command
Greg Ward <gward@python.net>
parents: 12042
diff changeset
207
12154
78e36e06e536 Added 'get_inputs()'.
Greg Ward <gward@python.net>
parents: 12106
diff changeset
208 def get_inputs (self):
78e36e06e536 Added 'get_inputs()'.
Greg Ward <gward@python.net>
parents: 12106
diff changeset
209 """Get the list of files that are input to this command, ie. the
78e36e06e536 Added 'get_inputs()'.
Greg Ward <gward@python.net>
parents: 12106
diff changeset
210 files that get installed as they are named in the build tree.
78e36e06e536 Added 'get_inputs()'.
Greg Ward <gward@python.net>
parents: 12106
diff changeset
211 The files in this list correspond one-to-one to the output
14779
7ba493bc24a0 Whitespace tweaks.
Greg Ward <gward@python.net>
parents: 14540
diff changeset
212 filenames returned by 'get_outputs()'.
7ba493bc24a0 Whitespace tweaks.
Greg Ward <gward@python.net>
parents: 14540
diff changeset
213 """
12154
78e36e06e536 Added 'get_inputs()'.
Greg Ward <gward@python.net>
parents: 12106
diff changeset
214 inputs = []
21268
d296e6bb17e5 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 14984
diff changeset
215
12154
78e36e06e536 Added 'get_inputs()'.
Greg Ward <gward@python.net>
parents: 12106
diff changeset
216 if self.distribution.has_pure_modules():
14779
7ba493bc24a0 Whitespace tweaks.
Greg Ward <gward@python.net>
parents: 14540
diff changeset
217 build_py = self.get_finalized_command('build_py')
7ba493bc24a0 Whitespace tweaks.
Greg Ward <gward@python.net>
parents: 14540
diff changeset
218 inputs.extend(build_py.get_outputs())
12154
78e36e06e536 Added 'get_inputs()'.
Greg Ward <gward@python.net>
parents: 12106
diff changeset
219
78e36e06e536 Added 'get_inputs()'.
Greg Ward <gward@python.net>
parents: 12106
diff changeset
220 if self.distribution.has_ext_modules():
14779
7ba493bc24a0 Whitespace tweaks.
Greg Ward <gward@python.net>
parents: 14540
diff changeset
221 build_ext = self.get_finalized_command('build_ext')
7ba493bc24a0 Whitespace tweaks.
Greg Ward <gward@python.net>
parents: 14540
diff changeset
222 inputs.extend(build_ext.get_outputs())
12154
78e36e06e536 Added 'get_inputs()'.
Greg Ward <gward@python.net>
parents: 12106
diff changeset
223
78e36e06e536 Added 'get_inputs()'.
Greg Ward <gward@python.net>
parents: 12106
diff changeset
224 return inputs
78e36e06e536 Added 'get_inputs()'.
Greg Ward <gward@python.net>
parents: 12106
diff changeset
225
12098
881257d1e854 Be sure to run both 'build_py' and 'build_ext', now that this command
Greg Ward <gward@python.net>
parents: 12042
diff changeset
226 # class install_lib