1 """distutils.command.install_data
3 Implements the Distutils 'install_data' command, for installing
4 platform-independent data files."""
6 # contributed by Bastian Kleineidam
11 from distutils
.core
import Command
12 from distutils
.util
import change_root
, convert_path
14 class install_data(Command
):
16 description
= "install data files"
20 "base directory for installing data files "
21 "(default: installation base dir)"),
23 "install everything relative to this alternate root directory"),
24 ('force', 'f', "force installation (overwrite existing files)"),
27 boolean_options
= ['force']
29 def initialize_options(self
):
30 self
.install_dir
= None
34 self
.data_files
= self
.distribution
.data_files
37 def finalize_options(self
):
38 self
.set_undefined_options('install',
39 ('install_data', 'install_dir'),
45 self
.mkpath(self
.install_dir
)
46 for f
in self
.data_files
:
47 if isinstance(f
, str):
48 # it's a simple file, so copy it
51 self
.warn("setup script did not provide a directory for "
52 "'%s' -- installing right in '%s'" %
53 (f
, self
.install_dir
))
54 (out
, _
) = self
.copy_file(f
, self
.install_dir
)
55 self
.outfiles
.append(out
)
57 # it's a tuple with path to install to and a list of files
58 dir = convert_path(f
[0])
59 if not os
.path
.isabs(dir):
60 dir = os
.path
.join(self
.install_dir
, dir)
62 dir = change_root(self
.root
, dir)
66 # If there are no files listed, the user must be
67 # trying to create an empty directory, so add the
68 # directory to the list of output files.
69 self
.outfiles
.append(dir)
71 # Copy files, adding them to the list of output files.
73 data
= convert_path(data
)
74 (out
, _
) = self
.copy_file(data
, dir)
75 self
.outfiles
.append(out
)
78 return self
.data_files
or []
80 def get_outputs(self
):