1 """distutils.command.install_data
3 Implements the Distutils 'install_data' command, for installing
4 platform-independent data files."""
6 # contributed by Bastian Kleineidam
9 from ..core import Command
10 from ..util import change_root, convert_path
13 class install_data(Command):
15 description = "install data files"
21 "base directory for installing data files "
22 "(default: installation base dir)",
24 ('root=', None, "install everything relative to this alternate root directory"),
25 ('force', 'f', "force installation (overwrite existing files)"),
28 boolean_options = ['force']
30 def initialize_options(self):
31 self.install_dir = None
35 self.data_files = self.distribution.data_files
38 def finalize_options(self):
39 self.set_undefined_options(
41 ('install_data', 'install_dir'),
47 self.mkpath(self.install_dir)
48 for f in self.data_files:
49 if isinstance(f, str):
50 # it's a simple file, so copy it
54 "setup script did not provide a directory for "
55 "'%s' -- installing right in '%s'" % (f, self.install_dir)
57 (out, _) = self.copy_file(f, self.install_dir)
58 self.outfiles.append(out)
60 # it's a tuple with path to install to and a list of files
61 dir = convert_path(f[0])
62 if not os.path.isabs(dir):
63 dir = os.path.join(self.install_dir, dir)
65 dir = change_root(self.root, dir)
69 # If there are no files listed, the user must be
70 # trying to create an empty directory, so add the
71 # directory to the list of output files.
72 self.outfiles.append(dir)
74 # Copy files, adding them to the list of output files.
76 data = convert_path(data)
77 (out, _) = self.copy_file(data, dir)
78 self.outfiles.append(out)
81 return self.data_files or []
83 def get_outputs(self):