Ejemplo n.º 1
0
def make_distribution(name='my_project', zipped=False, zip_safe=True):
  interp = {'project_name': name}
  if zip_safe:
    interp['content'] = dedent('''
    def do_something():
      print('hello world!')
    ''')
  else:
    interp['content'] = dedent('''
    if __file__ == 'derp.py':
      print('i am an idiot')
    ''')
  with temporary_content(PROJECT_CONTENT, interp=interp) as td:
    installer = Installer(td)
    distribution = installer.distribution()
    distiller = Distiller(distribution, debug=True)
    dist_location = distiller.distill(into=safe_mkdtemp())
    if zipped:
      yield DistributionHelper.distribution_from_path(dist_location)
    else:
      with temporary_dir() as td:
        extract_path = os.path.join(td, os.path.basename(dist_location))
        with contextlib.closing(zipfile.ZipFile(dist_location)) as zf:
          zf.extractall(extract_path)
        yield DistributionHelper.distribution_from_path(extract_path)
Ejemplo n.º 2
0
def make_distribution(name='my_project', zipped=False, zip_safe=True):
    interp = {'project_name': name}
    if zip_safe:
        interp['content'] = dedent('''
    def do_something():
      print('hello world!')
    ''')
    else:
        interp['content'] = dedent('''
    if __file__ == 'derp.py':
      print('i am an idiot')
    ''')
    with temporary_content(PROJECT_CONTENT, interp=interp) as td:
        installer = Installer(td)
        distribution = installer.distribution()
        distiller = Distiller(distribution, debug=True)
        dist_location = distiller.distill(into=safe_mkdtemp())
        if zipped:
            yield DistributionHelper.distribution_from_path(dist_location)
        else:
            with temporary_dir() as td:
                extract_path = os.path.join(td,
                                            os.path.basename(dist_location))
                with contextlib.closing(zipfile.ZipFile(dist_location)) as zf:
                    zf.extractall(extract_path)
                yield DistributionHelper.distribution_from_path(extract_path)
Ejemplo n.º 3
0
 def setup_distribute(self, interpreter, dest):
   obtainer = Obtainer(self._crawler, self._fetchers, [])
   obtainer_iterator = obtainer.iter(self._setuptools_requirement)
   links = [link for link in obtainer_iterator if isinstance(link, SourceLink)]
   for link in links:
     self._logger('Fetching %s' % link)
     sdist = link.fetch()
     self._logger('Installing %s' % sdist)
     installer = Installer(sdist, strict=False, interpreter=interpreter)
     dist = installer.distribution()
     self._logger('Distilling %s' % dist)
     egg = Distiller(dist).distill(into=dest)
     safe_link(egg, os.path.join(dest, 'distribute'))
     break
Ejemplo n.º 4
0
 def setup_distribute(self, interpreter, dest):
     obtainer = Obtainer(self._crawler, self._fetchers, [])
     obtainer_iterator = obtainer.iter(self._setuptools_requirement)
     links = [
         link for link in obtainer_iterator if isinstance(link, SourceLink)
     ]
     for link in links:
         self._logger('Fetching %s' % link)
         sdist = link.fetch()
         self._logger('Installing %s' % sdist)
         installer = Installer(sdist, strict=False, interpreter=interpreter)
         dist = installer.distribution()
         self._logger('Distilling %s' % dist)
         egg = Distiller(dist).distill(into=dest)
         safe_link(egg, os.path.join(dest, 'distribute'))
         break
Ejemplo n.º 5
0
 def obtain(self, req, *ignore_args, **ignore_kwargs):
   if not all(subcache.activated for subcache in self._subcaches):
     # Only fetch once all subcaches have been exhausted.
     return None
   with self.timed('Fetching %s' % req):
     fetched_req = self.fetcher.fetch(req)
   if not fetched_req:
     print('Failed to fetch %s' % req)
     return None
   installer = Installer(fetched_req)
   with self.timed('Building %s' % req):
     try:
       dist = installer.distribution()
     except Installer.InstallFailure as e:
       print('Failed to install %s' % req, file=sys.stderr)
       return None
   if self._install_cache:
     with self.timed('Distilling %s' % req):
       distilled = Distiller(dist).distill(into=self._install_cache)
     with self.timed('Constructing distribution %s' % req):
       metadata = EggMetadata(EggZipImporter(distilled))
       dist = Distribution.from_filename(distilled, metadata)
   self.add(dist)
   return dist