codekingpro/portable-devtools
114k
1from distutils import log, dir_util2import os3 4from setuptools import Command5from setuptools import namespaces6from setuptools.archive_util import unpack_archive7from .._path import ensure_directory8 9 10class install_egg_info(namespaces.Installer, Command):11 """Install an .egg-info directory for the package"""12 13 description = "Install an .egg-info directory for the package"14 15 user_options = [16 ('install-dir=', 'd', "directory to install to"),17 ]18 19 def initialize_options(self):20 self.install_dir = None21 22 def finalize_options(self):23 self.set_undefined_options('install_lib', ('install_dir', 'install_dir'))24 ei_cmd = self.get_finalized_command("egg_info")25 basename = f"{ei_cmd._get_egg_basename()}.egg-info"26 self.source = ei_cmd.egg_info27 self.target = os.path.join(self.install_dir, basename)28 self.outputs = []29 30 def run(self):31 self.run_command('egg_info')32 if os.path.isdir(self.target) and not os.path.islink(self.target):33 dir_util.remove_tree(self.target, dry_run=self.dry_run)34 elif os.path.exists(self.target):35 self.execute(os.unlink, (self.target,), "Removing " + self.target)36 if not self.dry_run:37 ensure_directory(self.target)38 self.execute(self.copytree, (), "Copying %s to %s" % (self.source, self.target))39 self.install_namespaces()40 41 def get_outputs(self):42 return self.outputs43 44 def copytree(self):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 