/setuptools-0.6c16dev3.egg/setuptools/command/develop.py

https://github.com/jsgf/tahoe-lafs
Python | 165 lines | 104 code | 48 blank | 13 comment | 19 complexity | ed45def2b3507d9d684f79efe0a400ee MD5 | raw file
  1. from setuptools.command.easy_install import easy_install
  2. from distutils.util import convert_path
  3. from pkg_resources import Distribution, PathMetadata, normalize_path
  4. from distutils import log
  5. from distutils.errors import *
  6. import sys, os, setuptools, glob
  7. class develop(easy_install):
  8. """Set up package for development"""
  9. description = "install package in 'development mode'"
  10. user_options = easy_install.user_options + [
  11. ("uninstall", "u", "Uninstall this source package"),
  12. ("egg-path=", None, "Set the path to be used in the .egg-link file"),
  13. ]
  14. boolean_options = easy_install.boolean_options + ['uninstall']
  15. command_consumes_arguments = False # override base
  16. def run(self):
  17. self.old_run()
  18. if sys.platform == "win32":
  19. from setuptools.command.scriptsetup import do_scriptsetup
  20. do_scriptsetup()
  21. def old_run(self):
  22. if self.uninstall:
  23. self.multi_version = True
  24. self.uninstall_link()
  25. else:
  26. self.install_for_development()
  27. self.warn_deprecated_options()
  28. def initialize_options(self):
  29. self.uninstall = None
  30. self.egg_path = None
  31. easy_install.initialize_options(self)
  32. self.setup_path = None
  33. self.always_copy_from = '.' # always copy eggs installed in curdir
  34. def finalize_options(self):
  35. ei = self.get_finalized_command("egg_info")
  36. if ei.broken_egg_info:
  37. raise DistutilsError(
  38. "Please rename %r to %r before using 'develop'"
  39. % (ei.egg_info, ei.broken_egg_info)
  40. )
  41. self.args = [ei.egg_name]
  42. easy_install.finalize_options(self)
  43. # pick up setup-dir .egg files only: no .egg-info
  44. self.package_index.scan(glob.glob('*.egg'))
  45. self.egg_link = os.path.join(self.install_dir, ei.egg_name+'.egg-link')
  46. self.egg_base = ei.egg_base
  47. if self.egg_path is None:
  48. self.egg_path = os.path.abspath(ei.egg_base)
  49. target = normalize_path(self.egg_base)
  50. if normalize_path(os.path.join(self.install_dir, self.egg_path)) != target:
  51. raise DistutilsOptionError(
  52. "--egg-path must be a relative path from the install"
  53. " directory to "+target
  54. )
  55. # Make a distribution for the package's source
  56. self.dist = Distribution(
  57. target,
  58. PathMetadata(target, os.path.abspath(ei.egg_info)),
  59. project_name = ei.egg_name
  60. )
  61. p = self.egg_base.replace(os.sep,'/')
  62. if p!= os.curdir:
  63. p = '../' * (p.count('/')+1)
  64. self.setup_path = p
  65. p = normalize_path(os.path.join(self.install_dir, self.egg_path, p))
  66. if p != normalize_path(os.curdir):
  67. raise DistutilsOptionError(
  68. "Can't get a consistent path to setup script from"
  69. " installation directory", p, normalize_path(os.curdir))
  70. def install_for_development(self):
  71. # Ensure metadata is up-to-date
  72. self.run_command('egg_info')
  73. # Build extensions in-place
  74. self.reinitialize_command('build_ext', inplace=1)
  75. self.run_command('build_ext')
  76. self.install_site_py() # ensure that target dir is site-safe
  77. if setuptools.bootstrap_install_from:
  78. self.easy_install(setuptools.bootstrap_install_from)
  79. setuptools.bootstrap_install_from = None
  80. # create an .egg-link in the installation dir, pointing to our egg
  81. log.info("Creating %s (link to %s)", self.egg_link, self.egg_base)
  82. if not self.dry_run:
  83. f = open(self.egg_link,"w")
  84. f.write(self.egg_path + "\n" + self.setup_path)
  85. f.close()
  86. # postprocess the installed distro, fixing up .pth, installing scripts,
  87. # and handling requirements
  88. self.process_distribution(None, self.dist, not self.no_deps)
  89. def uninstall_link(self):
  90. if os.path.exists(self.egg_link):
  91. log.info("Removing %s (link to %s)", self.egg_link, self.egg_base)
  92. contents = [line.rstrip() for line in file(self.egg_link)]
  93. if contents not in ([self.egg_path], [self.egg_path, self.setup_path]):
  94. log.warn("Link points to %s: uninstall aborted", contents)
  95. return
  96. if not self.dry_run:
  97. os.unlink(self.egg_link)
  98. if not self.dry_run:
  99. self.update_pth(self.dist) # remove any .pth link to us
  100. if self.distribution.scripts:
  101. # XXX should also check for entry point scripts!
  102. log.warn("Note: you must uninstall or replace scripts manually!")
  103. def install_egg_scripts(self, dist):
  104. if dist is not self.dist:
  105. # Installing a dependency, so fall back to normal behavior
  106. return easy_install.install_egg_scripts(self,dist)
  107. # create wrapper scripts in the script dir, pointing to dist.scripts
  108. # new-style...
  109. self.install_wrapper_scripts(dist)
  110. # ...and old-style
  111. for script_name in self.distribution.scripts or []:
  112. script_path = os.path.abspath(convert_path(script_name))
  113. script_name = os.path.basename(script_path)
  114. f = open(script_path,'rU')
  115. script_text = f.read()
  116. f.close()
  117. self.install_script(dist, script_name, script_text, script_path)