PageRenderTime 51ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/Lib/site-packages/setuptools/command/develop.py

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