PageRenderTime 50ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/zc.recipe.egg_/src/zc/recipe/egg/egg.py

https://github.com/koodaamo/buildout
Python | 181 lines | 161 code | 5 blank | 15 comment | 5 complexity | 533d95f6c340abc163ef039d4d21f6fb MD5 | raw file
Possible License(s): GPL-2.0
  1. ##############################################################################
  2. #
  3. # Copyright (c) 2006 Zope Foundation and Contributors.
  4. # All Rights Reserved.
  5. #
  6. # This software is subject to the provisions of the Zope Public License,
  7. # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
  8. # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
  9. # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  10. # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
  11. # FOR A PARTICULAR PURPOSE.
  12. #
  13. ##############################################################################
  14. """Install packages as eggs
  15. """
  16. import logging
  17. import os
  18. import re
  19. import sys
  20. import zc.buildout.easy_install
  21. import zipfile
  22. class Eggs(object):
  23. def __init__(self, buildout, name, options):
  24. self.buildout = buildout
  25. self.name = name
  26. self.options = options
  27. b_options = buildout['buildout']
  28. links = options.get('find-links', b_options['find-links'])
  29. if links:
  30. links = links.split()
  31. options['find-links'] = '\n'.join(links)
  32. else:
  33. links = ()
  34. self.links = links
  35. index = options.get('index', b_options.get('index'))
  36. if index is not None:
  37. options['index'] = index
  38. self.index = index
  39. allow_hosts = b_options['allow-hosts']
  40. allow_hosts = tuple([host.strip() for host in allow_hosts.split('\n')
  41. if host.strip()!=''])
  42. self.allow_hosts = allow_hosts
  43. options['eggs-directory'] = b_options['eggs-directory']
  44. options['_e'] = options['eggs-directory'] # backward compat.
  45. options['develop-eggs-directory'] = b_options['develop-eggs-directory']
  46. options['_d'] = options['develop-eggs-directory'] # backward compat.
  47. def working_set(self, extra=()):
  48. """Separate method to just get the working set
  49. This is intended for reuse by similar recipes.
  50. """
  51. options = self.options
  52. b_options = self.buildout['buildout']
  53. # Backward compat. :(
  54. options['executable'] = sys.executable
  55. distributions = [
  56. r.strip()
  57. for r in options.get('eggs', self.name).split('\n')
  58. if r.strip()]
  59. orig_distributions = distributions[:]
  60. distributions.extend(extra)
  61. if self.buildout['buildout'].get('offline') == 'true':
  62. ws = zc.buildout.easy_install.working_set(
  63. distributions,
  64. [options['develop-eggs-directory'], options['eggs-directory']]
  65. )
  66. else:
  67. ws = zc.buildout.easy_install.install(
  68. distributions, options['eggs-directory'],
  69. links=self.links,
  70. index=self.index,
  71. path=[options['develop-eggs-directory']],
  72. newest=self.buildout['buildout'].get('newest') == 'true',
  73. allow_hosts=self.allow_hosts)
  74. return orig_distributions, ws
  75. def install(self):
  76. reqs, ws = self.working_set()
  77. return ()
  78. update = install
  79. class Scripts(Eggs):
  80. def __init__(self, buildout, name, options):
  81. super(Scripts, self).__init__(buildout, name, options)
  82. options['bin-directory'] = buildout['buildout']['bin-directory']
  83. options['_b'] = options['bin-directory'] # backward compat.
  84. self.extra_paths = [
  85. os.path.join(buildout['buildout']['directory'], p.strip())
  86. for p in options.get('extra-paths', '').split('\n')
  87. if p.strip()
  88. ]
  89. if self.extra_paths:
  90. options['extra-paths'] = '\n'.join(self.extra_paths)
  91. relative_paths = options.get(
  92. 'relative-paths',
  93. buildout['buildout'].get('relative-paths', 'false')
  94. )
  95. if relative_paths == 'true':
  96. options['buildout-directory'] = buildout['buildout']['directory']
  97. self._relative_paths = options['buildout-directory']
  98. else:
  99. self._relative_paths = ''
  100. assert relative_paths == 'false'
  101. parse_entry_point = re.compile(
  102. '([^=]+)=(\w+(?:[.]\w+)*):(\w+(?:[.]\w+)*)$'
  103. ).match
  104. def install(self):
  105. reqs, ws = self.working_set()
  106. options = self.options
  107. scripts = options.get('scripts')
  108. if scripts or scripts is None:
  109. if scripts is not None:
  110. scripts = scripts.split()
  111. scripts = dict([
  112. ('=' in s) and s.split('=', 1) or (s, s)
  113. for s in scripts
  114. ])
  115. for s in options.get('entry-points', '').split():
  116. parsed = self.parse_entry_point(s)
  117. if not parsed:
  118. logging.getLogger(self.name).error(
  119. "Cannot parse the entry point %s.", s)
  120. raise zc.buildout.UserError("Invalid entry point")
  121. reqs.append(parsed.groups())
  122. if get_bool(options, 'dependent-scripts'):
  123. # Generate scripts for all packages in the working set,
  124. # except distribute.
  125. reqs = list(reqs)
  126. for dist in ws:
  127. name = dist.project_name
  128. if name != 'distribute' and name not in reqs:
  129. reqs.append(name)
  130. return zc.buildout.easy_install.scripts(
  131. reqs, ws, sys.executable, options['bin-directory'],
  132. scripts=scripts,
  133. extra_paths=self.extra_paths,
  134. interpreter=options.get('interpreter'),
  135. initialization=options.get('initialization', ''),
  136. arguments=options.get('arguments', ''),
  137. relative_paths=self._relative_paths,
  138. )
  139. return ()
  140. update = install
  141. def get_bool(options, name, default=False):
  142. value = options.get(name)
  143. if not value:
  144. return default
  145. if value == 'true':
  146. return True
  147. elif value == 'false':
  148. return False
  149. else:
  150. raise zc.buildout.UserError(
  151. "Invalid value for %s option: %s" % (name, value))
  152. Egg = Scripts