Commits

Gael Pasgrimaud committed 83abba9

better versions handling

Comments (0)

Files changed (1)

gp/recipe/pip/__init__.py

         self.buildout, self.name, self.options = buildout, name, options
 
     def pip_install(self, part_dir, src_dir, extra_args):
-        """Installer"""
+
+        # pop command line arguments
         args = ['install',
                 '-i', self.buildout['buildout'].get('index', pypi_url),
                 '-E', part_dir,
                 '-b', join(part_dir, 'build'),
                 '--src', src_dir,
                ]
+
         if 'find-links' in self.buildout['buildout']:
             for l in to_list(self.buildout['buildout']['find-links']):
                 args.extend(['-f', l])
             cmd = [executable, '-c']
         else:
             cmd = [sys.executable, '-c']
+
+        # command line
         cmd.append('"from pip import main; main(%r)"' % (args+extra_args,))
 
+        # subprocess environ
         env = os.environ.copy()
         env.update({
              'PYTHONPATH': ':'.join(sys.path),
              'LDFLAGS': '-I%s' % include_dir,
              })
 
+        # pip cache
         if 'download-cache' in self.buildout['buildout']:
              env['PIP_DOWNLOAD_CACHE'] = self.buildout['buildout'].get('download-cache')
 
+        # darwin environ (adapted from lxml)
         if sys.platform in ('darwin',):
             # We compile Universal if we are on a machine > 10.3
             major_version = int(os.uname()[2].split('.')[0])
                     'MACOSX_DEPLOYMENT_TARGET' : "10.5" in isysroot and "10.5" or "10.4"
                     })
 
+        # call pip
         code = call(' '.join(cmd), shell=True, env=env)
         if code != 0:
             raise RuntimeError('An error occur during pip installation. See %s-log.txt' % self.name)
         src_dir = self.options.get('sources-directory',
                                    join(self.buildout['buildout']['directory'], 'src'))
 
+        # get buildout versions
+        versions_option = self.buildout['buildout'].get('versions')
+        if versions_option:
+            buildout_versions = dict(self.buildout[versions_option])
+        else:
+            buildout_versions = {}
+
+        # pip installs
+
+        # VSC
         editables = [('-e', e) for e in to_list(self.options.get('editables', ''))]
         for e in editables:
             self.pip_install(part_dir, src_dir, e)
+
+        # packages / bundles. add version if needed
         for i in to_list(self.options.get('install', '')):
+            for k in buildout_versions:
+                if i.endswith(k):
+                    i = '%s==%s' % (i, buildout_versions.get(k))
             self.pip_install(part_dir, src_dir, [i])
 
+
+        # prepare options for zc.recipe.egg
+
+        # retrieve venv's site-packages and executable
         site_packages = glob.glob(join(part_dir, 'lib', '*', 'site-packages'))[0]
         executable = get_executable(part_dir)
 
+        # retrieve versions from egg-info
         egg_infos = glob.glob(join(site_packages, '*.egg-info'))
         eggs = [os.path.basename(p) for p in glob.glob(join(src_dir, '*'))]
         versions = []
             name, ver, r = info.split('-', 2)
             eggs.append(name)
             versions.append((name, ver))
+        versions = dict(versions)
 
+        # update with buildout versions
+        versions.update(buildout_versions)
+
+        zc.buildout.easy_install.default_versions(versions)
+
+        # set eggs directory and executable
         _options = self.buildout['buildout'].copy()
         self.buildout['buildout']['develop-eggs-directory'] = site_packages
         self.buildout['buildout']['executable'] = executable
-        zc.buildout.easy_install.default_versions(dict(versions))
 
+        # clean copy of options
         options = {}
         for k in self.options:
             options[k] = self.options[k]
 
+        # add eggs found in venv to eggs option
         options['eggs'] = '\n'.join(eggs) + '\n' + self.options.get('eggs')
 
+        # add VCS path as extra_paths
         extra_paths = glob.glob(join(src_dir, '*'))
 
+        # get eggs already in sys path and add them to extra_paths
         eggs_dir = self.buildout['buildout']['eggs-directory']
         extra_paths.extend('\n'.join([p for p in sys.path if p.startswith(eggs_dir)]))
         options['extra-paths'] = '\n'.join([p for p in sys.path if p.startswith(eggs_dir)])
 
+        # run the recipe
         egg = Scripts(self.buildout, self.name, options)
         egg.install()
 
+        # restore options
         for k in _options:
             self.buildout['buildout'][k] = _options[k]
         versions = self.buildout['buildout'].get('versions')