Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
install_data.py85 linesDownload Raw Back to command
1"""distutils.command.install_data2 3Implements the Distutils 'install_data' command, for installing4platform-independent data files."""5 6# contributed by Bastian Kleineidam7 8import os9 10from ..core import Command11from ..util import change_root, convert_path12 13 14class install_data(Command):15    description = "install data files"16 17    user_options = [18        (19            'install-dir=',20            'd',21            "base directory for installing data files "22            "(default: installation base dir)",23        ),24        ('root=', None, "install everything relative to this alternate root directory"),25        ('force', 'f', "force installation (overwrite existing files)"),26    ]27 28    boolean_options = ['force']29 30    def initialize_options(self):31        self.install_dir = None32        self.outfiles = []33        self.root = None34        self.force = 035        self.data_files = self.distribution.data_files36        self.warn_dir = 137 38    def finalize_options(self):39        self.set_undefined_options(40            'install',41            ('install_data', 'install_dir'),42            ('root', 'root'),43            ('force', 'force'),44        )45 46    def run(self):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 it51                f = convert_path(f)52                if self.warn_dir:53                    self.warn(54                        "setup script did not provide a directory for "55                        f"'{f}' -- installing right in '{self.install_dir}'"56                    )57                (out, _) = self.copy_file(f, self.install_dir)58                self.outfiles.append(out)59            else:60                # it's a tuple with path to install to and a list of files61                dir = convert_path(f[0])62                if not os.path.isabs(dir):63                    dir = os.path.join(self.install_dir, dir)64                elif self.root:65                    dir = change_root(self.root, dir)66                self.mkpath(dir)67 68                if f[1] == []:69                    # If there are no files listed, the user must be70                    # trying to create an empty directory, so add the71                    # directory to the list of output files.72                    self.outfiles.append(dir)73                else:74                    # Copy files, adding them to the list of output files.75                    for data in f[1]:76                        data = convert_path(data)77                        (out, _) = self.copy_file(data, dir)78                        self.outfiles.append(out)79 80    def get_inputs(self):81        return self.data_files or []82 83    def get_outputs(self):84        return self.outfiles85 
codekingpro/portable-devtools · Team Ai