Aluode/PerceptionLabPortable
0
1"""distutils.command.install_scripts2 3Implements the Distutils 'install_scripts' command, for installing4Python scripts."""5 6# contributed by Bastian Kleineidam7 8import os9from distutils._log import log10from stat import ST_MODE11from typing import ClassVar12 13from ..core import Command14 15 16class install_scripts(Command):17 description = "install scripts (Python or otherwise)"18 19 user_options = [20 ('install-dir=', 'd', "directory to install scripts to"),21 ('build-dir=', 'b', "build directory (where to install from)"),22 ('force', 'f', "force installation (overwrite existing files)"),23 ('skip-build', None, "skip the build steps"),24 ]25 26 boolean_options: ClassVar[list[str]] = ['force', 'skip-build']27 28 def initialize_options(self):29 self.install_dir = None30 self.force = False31 self.build_dir = None32 self.skip_build = None33 34 def finalize_options(self) -> None:35 self.set_undefined_options('build', ('build_scripts', 'build_dir'))36 self.set_undefined_options(37 'install',38 ('install_scripts', 'install_dir'),39 ('force', 'force'),40 ('skip_build', 'skip_build'),41 )42 43 def run(self) -> None:44 if not self.skip_build:45 self.run_command('build_scripts')46 self.outfiles = self.copy_tree(self.build_dir, self.install_dir)47 if os.name == 'posix':48 # Set the executable bits (owner, group, and world) on49 # all the scripts we just installed.50 for file in self.get_outputs():51 if self.dry_run:52 log.info("changing mode of %s", file)53 else:54 mode = ((os.stat(file)[ST_MODE]) | 0o555) & 0o777755 log.info("changing mode of %s to %o", file, mode)56 os.chmod(file, mode)57 58 def get_inputs(self):59 return self.distribution.scripts or []60 61 def get_outputs(self):62 return self.outfiles or []63 