codekingpro/portable-devtools
114k
1import os2 3from setuptools import Command, namespaces4from setuptools.archive_util import unpack_archive5 6from .._path import ensure_directory7 8from distutils import dir_util, log9 10 11class install_egg_info(namespaces.Installer, Command):12 """Install an .egg-info directory for the package"""13 14 description = "Install an .egg-info directory for the package"15 16 user_options = [17 ('install-dir=', 'd', "directory to install to"),18 ]19 20 def initialize_options(self):21 self.install_dir = None22 23 def finalize_options(self) -> None:24 self.set_undefined_options('install_lib', ('install_dir', 'install_dir'))25 ei_cmd = self.get_finalized_command("egg_info")26 basename = f"{ei_cmd._get_egg_basename()}.egg-info"27 self.source = ei_cmd.egg_info28 self.target = os.path.join(self.install_dir, basename)29 self.outputs: list[str] = []30 31 def run(self) -> None:32 self.run_command('egg_info')33 if os.path.isdir(self.target) and not os.path.islink(self.target):34 dir_util.remove_tree(self.target)35 elif os.path.exists(self.target):36 self.execute(os.unlink, (self.target,), "Removing " + self.target)37 ensure_directory(self.target)38 self.execute(self.copytree, (), f"Copying {self.source} to {self.target}")39 self.install_namespaces()40 41 def get_outputs(self):42 return self.outputs43 44 def copytree(self) -> None:45 # Copy the .egg-info tree to site-packages46 def skimmer(src, dst):47 # filter out source-control directories; note that 'src' is always48 # a '/'-separated path, regardless of platform. 'dst' is a49 # platform-specific path.50 for skip in '.svn/', 'CVS/':51 if src.startswith(skip) or '/' + skip in src:52 return None53 self.outputs.append(dst)54 log.debug("Copying %s to %s", src, dst)55 return dst56 57 unpack_archive(self.source, self.target, skimmer)58 