CoolFace
Apppublic

Aluode/PerceptionLabPortable

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
install_data.py95 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 8from __future__ import annotations9 10import functools11import os12from collections.abc import Iterable13from typing import ClassVar14 15from ..core import Command16from ..util import change_root, convert_path17 18 19class install_data(Command):20    description = "install data files"21 22    user_options = [23        (24            'install-dir=',25            'd',26            "base directory for installing data files [default: installation base dir]",27        ),28        ('root=', None, "install everything relative to this alternate root directory"),29        ('force', 'f', "force installation (overwrite existing files)"),30    ]31 32    boolean_options: ClassVar[list[str]] = ['force']33 34    def initialize_options(self):35        self.install_dir = None36        self.outfiles = []37        self.root = None38        self.force = False39        self.data_files = self.distribution.data_files40        self.warn_dir = True41 42    def finalize_options(self) -> None:43        self.set_undefined_options(44            'install',45            ('install_data', 'install_dir'),46            ('root', 'root'),47            ('force', 'force'),48        )49 50    def run(self) -> None:51        self.mkpath(self.install_dir)52        for f in self.data_files:53            self._copy(f)54 55    @functools.singledispatchmethod56    def _copy(self, f: tuple[str | os.PathLike, Iterable[str | os.PathLike]]):57        # it's a tuple with path to install to and a list of files58        dir = convert_path(f[0])59        if not os.path.isabs(dir):60            dir = os.path.join(self.install_dir, dir)61        elif self.root:62            dir = change_root(self.root, dir)63        self.mkpath(dir)64 65        if f[1] == []:66            # If there are no files listed, the user must be67            # trying to create an empty directory, so add the68            # directory to the list of output files.69            self.outfiles.append(dir)70        else:71            # Copy files, adding them to the list of output files.72            for data in f[1]:73                data = convert_path(data)74                (out, _) = self.copy_file(data, dir)75                self.outfiles.append(out)76 77    @_copy.register(str)78    @_copy.register(os.PathLike)79    def _(self, f: str | os.PathLike):80        # it's a simple file, so copy it81        f = convert_path(f)82        if self.warn_dir:83            self.warn(84                "setup script did not provide a directory for "85                f"'{f}' -- installing right in '{self.install_dir}'"86            )87        (out, _) = self.copy_file(f, self.install_dir)88        self.outfiles.append(out)89 90    def get_inputs(self):91        return self.data_files or []92 93    def get_outputs(self):94        return self.outfiles95 
Aluode/PerceptionLabPortable · CoolFace