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

Issue #16194: document imp.load_dynamic problems when read several extension modules from the same binary object file.
author Andrew Svetlov <andrew.svetlov@gmail.com>
date Thu, 29 Nov 2012 19:51:28 +0200
parents 24b685318633
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12682
7c89ee40730f Added comment/docstring/revision header.
Gregory P. Smith <greg@mad-scientist.com>
parents: 12679
diff changeset
1 """distutils.command.install_data
7c89ee40730f Added comment/docstring/revision header.
Gregory P. Smith <greg@mad-scientist.com>
parents: 12679
diff changeset
2
7c89ee40730f Added comment/docstring/revision header.
Gregory P. Smith <greg@mad-scientist.com>
parents: 12679
diff changeset
3 Implements the Distutils 'install_data' command, for installing
7c89ee40730f Added comment/docstring/revision header.
Gregory P. Smith <greg@mad-scientist.com>
parents: 12679
diff changeset
4 platform-independent data files."""
7c89ee40730f Added comment/docstring/revision header.
Gregory P. Smith <greg@mad-scientist.com>
parents: 12679
diff changeset
5
7c89ee40730f Added comment/docstring/revision header.
Gregory P. Smith <greg@mad-scientist.com>
parents: 12679
diff changeset
6 # contributed by Bastian Kleineidam
7c89ee40730f Added comment/docstring/revision header.
Gregory P. Smith <greg@mad-scientist.com>
parents: 12679
diff changeset
7
7c89ee40730f Added comment/docstring/revision header.
Gregory P. Smith <greg@mad-scientist.com>
parents: 12679
diff changeset
8 __revision__ = "$Id$"
7c89ee40730f Added comment/docstring/revision header.
Gregory P. Smith <greg@mad-scientist.com>
parents: 12679
diff changeset
9
12744
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
10 import os
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
11 from distutils.core import Command
16320
0efa6c97a4fa Data pathnames were not converted from URL-style to local style. Fixed.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15216
diff changeset
12 from distutils.util import change_root, convert_path
12675
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
13
52586
9609ed7deaf8 added test to the install_data command
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51047
diff changeset
14 class install_data(Command):
12675
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
15
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
16 description = "install data files"
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
17
12744
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
18 user_options = [
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
19 ('install-dir=', 'd',
13725
449dd3a00bd7 Fixed a grab-bag of typos spotted by Rob Hooft.
Greg Ward <gward@python.net>
parents: 13004
diff changeset
20 "base directory for installing data files "
13004
37ba7056d4ab Print a warning if we install a data file right in install_dir.
Greg Ward <gward@python.net>
parents: 12981
diff changeset
21 "(default: installation base dir)"),
12744
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
22 ('root=', None,
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
23 "install everything relative to this alternate root directory"),
14540
35ae8dff8ed0 Added --force (-f) option to force installation (including bytecode
Greg Ward <gward@python.net>
parents: 13725
diff changeset
24 ('force', 'f', "force installation (overwrite existing files)"),
12744
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
25 ]
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
26
14829
b1f220f636ed Added 'boolean_options' list to support config file parsing.
Greg Ward <gward@python.net>
parents: 14576
diff changeset
27 boolean_options = ['force']
b1f220f636ed Added 'boolean_options' list to support config file parsing.
Greg Ward <gward@python.net>
parents: 14576
diff changeset
28
52586
9609ed7deaf8 added test to the install_data command
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51047
diff changeset
29 def initialize_options(self):
12744
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
30 self.install_dir = None
12981
9569c5625765 Build the 'outfiles' list so 'get_outputs()' has something to return.
Greg Ward <gward@python.net>
parents: 12861
diff changeset
31 self.outfiles = []
12744
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
32 self.root = None
14540
35ae8dff8ed0 Added --force (-f) option to force installation (including bytecode
Greg Ward <gward@python.net>
parents: 13725
diff changeset
33 self.force = 0
12744
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
34 self.data_files = self.distribution.data_files
14576
8369fcd79a64 Added 'warn_dir' option so other code can sneak in and disable
Greg Ward <gward@python.net>
parents: 14540
diff changeset
35 self.warn_dir = 1
12744
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
36
57745
24b685318633 cleaned up the module (PEP 8 + old fashion test removal)
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 52586
diff changeset
37 def finalize_options(self):
12744
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
38 self.set_undefined_options('install',
15216
a3975d2811f0 Untabified.
Greg Ward <gward@python.net>
parents: 14945
diff changeset
39 ('install_data', 'install_dir'),
a3975d2811f0 Untabified.
Greg Ward <gward@python.net>
parents: 14945
diff changeset
40 ('root', 'root'),
14540
35ae8dff8ed0 Added --force (-f) option to force installation (including bytecode
Greg Ward <gward@python.net>
parents: 13725
diff changeset
41 ('force', 'force'),
15216
a3975d2811f0 Untabified.
Greg Ward <gward@python.net>
parents: 14945
diff changeset
42 )
12675
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
43
52586
9609ed7deaf8 added test to the install_data command
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51047
diff changeset
44 def run(self):
12744
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
45 self.mkpath(self.install_dir)
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
46 for f in self.data_files:
57745
24b685318633 cleaned up the module (PEP 8 + old fashion test removal)
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 52586
diff changeset
47 if isinstance(f, str):
13004
37ba7056d4ab Print a warning if we install a data file right in install_dir.
Greg Ward <gward@python.net>
parents: 12981
diff changeset
48 # it's a simple file, so copy it
16320
0efa6c97a4fa Data pathnames were not converted from URL-style to local style. Fixed.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15216
diff changeset
49 f = convert_path(f)
14576
8369fcd79a64 Added 'warn_dir' option so other code can sneak in and disable
Greg Ward <gward@python.net>
parents: 14540
diff changeset
50 if self.warn_dir:
8369fcd79a64 Added 'warn_dir' option so other code can sneak in and disable
Greg Ward <gward@python.net>
parents: 14540
diff changeset
51 self.warn("setup script did not provide a directory for "
8369fcd79a64 Added 'warn_dir' option so other code can sneak in and disable
Greg Ward <gward@python.net>
parents: 14540
diff changeset
52 "'%s' -- installing right in '%s'" %
8369fcd79a64 Added 'warn_dir' option so other code can sneak in and disable
Greg Ward <gward@python.net>
parents: 14540
diff changeset
53 (f, self.install_dir))
14945
a59600a975d1 Expect a tuple (dest_name, copied) from 'copy_file()'.
Greg Ward <gward@python.net>
parents: 14829
diff changeset
54 (out, _) = self.copy_file(f, self.install_dir)
12981
9569c5625765 Build the 'outfiles' list so 'get_outputs()' has something to return.
Greg Ward <gward@python.net>
parents: 12861
diff changeset
55 self.outfiles.append(out)
12744
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
56 else:
13004
37ba7056d4ab Print a warning if we install a data file right in install_dir.
Greg Ward <gward@python.net>
parents: 12981
diff changeset
57 # it's a tuple with path to install to and a list of files
16320
0efa6c97a4fa Data pathnames were not converted from URL-style to local style. Fixed.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15216
diff changeset
58 dir = convert_path(f[0])
12744
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
59 if not os.path.isabs(dir):
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
60 dir = os.path.join(self.install_dir, dir)
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
61 elif self.root:
12749
bce49a6fa8b9 Fix to use 'change_root()' rather than directly mangling path.
Greg Ward <gward@python.net>
parents: 12744
diff changeset
62 dir = change_root(self.root, dir)
12744
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
63 self.mkpath(dir)
19700
fbaf4e55263f [Bug #444589] Record empty directories in the install_data command
Andrew M. Kuchling <amk@amk.ca>
parents: 16456
diff changeset
64
fbaf4e55263f [Bug #444589] Record empty directories in the install_data command
Andrew M. Kuchling <amk@amk.ca>
parents: 16456
diff changeset
65 if f[1] == []:
fbaf4e55263f [Bug #444589] Record empty directories in the install_data command
Andrew M. Kuchling <amk@amk.ca>
parents: 16456
diff changeset
66 # If there are no files listed, the user must be
fbaf4e55263f [Bug #444589] Record empty directories in the install_data command
Andrew M. Kuchling <amk@amk.ca>
parents: 16456
diff changeset
67 # trying to create an empty directory, so add the
fbaf4e55263f [Bug #444589] Record empty directories in the install_data command
Andrew M. Kuchling <amk@amk.ca>
parents: 16456
diff changeset
68 # directory to the list of output files.
fbaf4e55263f [Bug #444589] Record empty directories in the install_data command
Andrew M. Kuchling <amk@amk.ca>
parents: 16456
diff changeset
69 self.outfiles.append(dir)
fbaf4e55263f [Bug #444589] Record empty directories in the install_data command
Andrew M. Kuchling <amk@amk.ca>
parents: 16456
diff changeset
70 else:
fbaf4e55263f [Bug #444589] Record empty directories in the install_data command
Andrew M. Kuchling <amk@amk.ca>
parents: 16456
diff changeset
71 # Copy files, adding them to the list of output files.
fbaf4e55263f [Bug #444589] Record empty directories in the install_data command
Andrew M. Kuchling <amk@amk.ca>
parents: 16456
diff changeset
72 for data in f[1]:
fbaf4e55263f [Bug #444589] Record empty directories in the install_data command
Andrew M. Kuchling <amk@amk.ca>
parents: 16456
diff changeset
73 data = convert_path(data)
fbaf4e55263f [Bug #444589] Record empty directories in the install_data command
Andrew M. Kuchling <amk@amk.ca>
parents: 16456
diff changeset
74 (out, _) = self.copy_file(data, dir)
fbaf4e55263f [Bug #444589] Record empty directories in the install_data command
Andrew M. Kuchling <amk@amk.ca>
parents: 16456
diff changeset
75 self.outfiles.append(out)
12702
58ad6196d81f Added 'get_inputs()' methods, needed by the "install" command's
Gregory P. Smith <greg@mad-scientist.com>
parents: 12682
diff changeset
76
52586
9609ed7deaf8 added test to the install_data command
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51047
diff changeset
77 def get_inputs(self):
12744
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
78 return self.data_files or []
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
79
52586
9609ed7deaf8 added test to the install_data command
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51047
diff changeset
80 def get_outputs(self):
12981
9569c5625765 Build the 'outfiles' list so 'get_outputs()' has something to return.
Greg Ward <gward@python.net>
parents: 12861
diff changeset
81 return self.outfiles