from glob import glob import os from os.path import * import pkg_resources import zc.buildout import zc.recipe.egg class SetupDevelop: def __init__(self, buildout, name, options): self.buildout = buildout self.eggrecipe = zc.recipe.egg.Scripts(buildout, name, options) self.name = name self.options = options self.sources = options['sources'] def develop(self): """ Run zc.buildout.easy_install.develop command for each source This function installs each item in source using `zc.buildout.easy_install.develop`. The egg link returned by the buildout develop commaned is then filtered through `pkg_resources.find_on_path` to obtain an appropriate requirement string. The two stage install means that after a successfull run you will always end up with an egg link back into the source directory. This two stage install means it possible to reference a released version of a package, for bootstraping purposes, via find-links #egg=dev, and subsequently force the source install to take precedence when the paths are generated for your buildout scripts. The package that contains *this* recipe can be bootstraped for a source checkout using this technique. """ dest = self.buildout['buildout']['develop-eggs-directory'] here = os.path.abspath(os.getcwd()) extras = [] parenpath = self.buildout['buildout']['directory'] try: for src in self.sources.split(): link = zc.buildout.easy_install.develop( join(parenpath, src), dest) importer = pkg_resources.get_importer(link) extras.extend(pkg_resources.find_on_path( importer, link, only=False) ) return [str(dist.as_requirement()) for dist in extras] finally: os.chdir(here) def install(self): options = self.options extras = self.develop() reqs, ws = self.eggrecipe.working_set(extras) scripts = options.get('scripts') if scripts or scripts is None: if scripts is not None: scripts = scripts.split() scripts = dict([ ('=' in s) and s.split('=', 1) or (s, s) for s in scripts ]) for s in options.get('entry-points', '').split(): parsed = self.eggrecipe.parse_entry_point(s) if not parsed: logging.getLogger(self.name).error( "Cannot parse the entry point %s.", s) raise zc.buildout.UserError("Invalid entry point") reqs.append(parsed.groups()) zc.buildout.easy_install.scripts( reqs, ws, options['executable'], options['bin-directory'], scripts=scripts, extra_paths=self.eggrecipe.extra_paths, interpreter=options.get('interpreter'), initialization=options.get('initialization', ''), arguments=options.get('arguments', ''), ) return () update = install