CoolFace
Apppublic

Aluode/PerceptionLabPortable

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
install_scripts.py68 linesDownload Raw Back to command
1from __future__ import annotations2 3import os4import sys5 6from .._path import ensure_directory7from ..dist import Distribution8 9import distutils.command.install_scripts as orig10from distutils import log11 12 13class install_scripts(orig.install_scripts):14    """Do normal script install, plus any egg_info wrapper scripts"""15 16    distribution: Distribution  # override distutils.dist.Distribution with setuptools.dist.Distribution17 18    def initialize_options(self) -> None:19        orig.install_scripts.initialize_options(self)20        self.no_ep = False21 22    def run(self) -> None:23        self.run_command("egg_info")24        if self.distribution.scripts:25            orig.install_scripts.run(self)  # run first to set up self.outfiles26        else:27            self.outfiles: list[str] = []28        if self.no_ep:29            # don't install entry point scripts into .egg file!30            return31        self._install_ep_scripts()32 33    def _install_ep_scripts(self):34        # Delay import side-effects35        from .. import _scripts36        from .._importlib import metadata37 38        ei_cmd = self.get_finalized_command("egg_info")39        dist = metadata.Distribution.at(path=ei_cmd.egg_info)40        bs_cmd = self.get_finalized_command('build_scripts')41        exec_param = getattr(bs_cmd, 'executable', None)42        writer = _scripts.ScriptWriter43        if exec_param == sys.executable:44            # In case the path to the Python executable contains a space, wrap45            # it so it's not split up.46            exec_param = [exec_param]47        # resolve the writer to the environment48        writer = writer.best()49        cmd = writer.command_spec_class.best().from_param(exec_param)50        for args in writer.get_args(dist, cmd.as_header()):51            self.write_script(*args)52 53    def write_script(self, script_name, contents, mode: str = "t", *ignored) -> None:54        """Write an executable file to the scripts directory"""55        from .._shutil import attempt_chmod_verbose as chmod, current_umask56 57        log.info("Installing %s script to %s", script_name, self.install_dir)58        target = os.path.join(self.install_dir, script_name)59        self.outfiles.append(target)60 61        encoding = None if "b" in mode else "utf-8"62        mask = current_umask()63        if not self.dry_run:64            ensure_directory(target)65            with open(target, "w" + mode, encoding=encoding) as f:66                f.write(contents)67            chmod(target, 0o777 - mask)68 
Aluode/PerceptionLabPortable · CoolFace