install_egg_info.py 2.2 KB

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