You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

install_egg_info.py 2.2KB

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