install_egg_info.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. from distutils import log, dir_util
  2. import os
  3. from setuptools import Command
  4. from setuptools import namespaces
  5. from setuptools.archive_util import unpack_archive
  6. from .._path import ensure_directory
  7. class install_egg_info(namespaces.Installer, Command):
  8. """Install an .egg-info directory for the package"""
  9. description = "Install an .egg-info directory for the package"
  10. user_options = [
  11. ('install-dir=', 'd', "directory to install to"),
  12. ]
  13. def initialize_options(self):
  14. self.install_dir = None
  15. def finalize_options(self):
  16. self.set_undefined_options('install_lib', ('install_dir', 'install_dir'))
  17. ei_cmd = self.get_finalized_command("egg_info")
  18. basename = f"{ei_cmd._get_egg_basename()}.egg-info"
  19. self.source = ei_cmd.egg_info
  20. self.target = os.path.join(self.install_dir, basename)
  21. self.outputs = []
  22. def run(self):
  23. self.run_command('egg_info')
  24. if os.path.isdir(self.target) and not os.path.islink(self.target):
  25. dir_util.remove_tree(self.target, dry_run=self.dry_run)
  26. elif os.path.exists(self.target):
  27. self.execute(os.unlink, (self.target,), "Removing " + self.target)
  28. if not self.dry_run:
  29. ensure_directory(self.target)
  30. self.execute(self.copytree, (), "Copying %s to %s" % (self.source, self.target))
  31. self.install_namespaces()
  32. def get_outputs(self):
  33. return self.outputs
  34. def copytree(self):
  35. # Copy the .egg-info tree to site-packages
  36. def skimmer(src, dst):
  37. # filter out source-control directories; note that 'src' is always
  38. # a '/'-separated path, regardless of platform. 'dst' is a
  39. # platform-specific path.
  40. for skip in '.svn/', 'CVS/':
  41. if src.startswith(skip) or '/' + skip in src:
  42. return None
  43. self.outputs.append(dst)
  44. log.debug("Copying %s to %s", src, dst)
  45. return dst
  46. unpack_archive(self.source, self.target, skimmer)