annotate Lib/distutils/command/install_data.py @ 87690:66c1c9f32567 default tip

Add use_weakref option to functools.lru_cache The use_weakref option makes lru_cache create weak references to the function arguments when creating the cache key, which prevents them from staying in the memory forever even after all other references to them are gone. This is a proof of concept for http://bugs.python.org/issue19859
author Radomir Dopieralski <devel@sheep.art.pl>
date Tue, 03 Dec 2013 16:02:48 +0100
parents 3e26c9033306
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
12744
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
8 import os
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
9 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
10 from distutils.util import change_root, convert_path
12675
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
11
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 41558
diff changeset
12 class install_data(Command):
12675
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
13
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
14 description = "install data files"
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
15
12744
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
16 user_options = [
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
17 ('install-dir=', 'd',
13725
449dd3a00bd7 Fixed a grab-bag of typos spotted by Rob Hooft.
Greg Ward <gward@python.net>
parents: 13004
diff changeset
18 "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
19 "(default: installation base dir)"),
12744
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
20 ('root=', None,
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
21 "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
22 ('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
23 ]
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
24
14829
b1f220f636ed Added 'boolean_options' list to support config file parsing.
Greg Ward <gward@python.net>
parents: 14576
diff changeset
25 boolean_options = ['force']
b1f220f636ed Added 'boolean_options' list to support config file parsing.
Greg Ward <gward@python.net>
parents: 14576
diff changeset
26
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 41558
diff changeset
27 def initialize_options(self):
12744
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
28 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
29 self.outfiles = []
12744
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
30 self.root = None
14540
35ae8dff8ed0 Added --force (-f) option to force installation (including bytecode
Greg Ward <gward@python.net>
parents: 13725
diff changeset
31 self.force = 0
12744
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
32 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
33 self.warn_dir = 1
12744
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
34
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 41558
diff changeset
35 def finalize_options(self):
12744
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
36 self.set_undefined_options('install',
15216
a3975d2811f0 Untabified.
Greg Ward <gward@python.net>
parents: 14945
diff changeset
37 ('install_data', 'install_dir'),
a3975d2811f0 Untabified.
Greg Ward <gward@python.net>
parents: 14945
diff changeset
38 ('root', 'root'),
14540
35ae8dff8ed0 Added --force (-f) option to force installation (including bytecode
Greg Ward <gward@python.net>
parents: 13725
diff changeset
39 ('force', 'force'),
15216
a3975d2811f0 Untabified.
Greg Ward <gward@python.net>
parents: 14945
diff changeset
40 )
12675
de435a59a4d5 Patch from Bastien Kleineidam:
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
41
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 41558
diff changeset
42 def run(self):
12744
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
43 self.mkpath(self.install_dir)
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
44 for f in self.data_files:
43577
ace45b361e87 Patch# 1258 by Christian Heimes: kill basestring.
Guido van Rossum <guido@python.org>
parents: 43026
diff changeset
45 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
46 # 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
47 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
48 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
49 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
50 "'%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
51 (f, self.install_dir))
14945
a59600a975d1 Expect a tuple (dest_name, copied) from 'copy_file()'.
Greg Ward <gward@python.net>
parents: 14829
diff changeset
52 (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
53 self.outfiles.append(out)
12744
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
54 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
55 # 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
56 dir = convert_path(f[0])
12744
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
57 if not os.path.isabs(dir):
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
58 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
59 elif self.root:
12749
bce49a6fa8b9 Fix to use 'change_root()' rather than directly mangling path.
Greg Ward <gward@python.net>
parents: 12744
diff changeset
60 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
61 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
62
fbaf4e55263f [Bug #444589] Record empty directories in the install_data command
Andrew M. Kuchling <amk@amk.ca>
parents: 16456
diff changeset
63 if f[1] == []:
fbaf4e55263f [Bug #444589] Record empty directories in the install_data command
Andrew M. Kuchling <amk@amk.ca>
parents: 16456
diff changeset
64 # 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
65 # 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
66 # 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
67 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
68 else:
fbaf4e55263f [Bug #444589] Record empty directories in the install_data command
Andrew M. Kuchling <amk@amk.ca>
parents: 16456
diff changeset
69 # 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
70 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
71 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
72 (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
73 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
74
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 41558
diff changeset
75 def get_inputs(self):
12744
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
76 return self.data_files or []
eeafab8c925b Bastian Kleineidam: the "build_scripts" command and changes
Greg Ward <gward@python.net>
parents: 12704
diff changeset
77
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 41558
diff changeset
78 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
79 return self.outfiles