示例#1
0
def test_package_fetch_without_location():
  with temporary_dir() as td:
    dateutil_base = 'python-dateutil-1.5'
    dateutil = '%s.zip' % dateutil_base

    with contextlib.closing(ZipFile(os.path.join(td, dateutil), 'w')) as zf:
      zf.writestr(os.path.join(dateutil_base, 'file1.txt'), 'junk1')
      zf.writestr(os.path.join(dateutil_base, 'file2.txt'), 'junk2')

    dest = Archiver.unpack(zf.filename)
    assert set(os.listdir(dest)) == set(['file1.txt', 'file2.txt'])

    with temporary_dir() as td2:
      dest = Archiver.unpack(zf.filename, location=td2)
      assert set(os.listdir(os.path.join(td2, 'python-dateutil-1.5'))) == set(
          ['file1.txt', 'file2.txt'])
示例#2
0
def test_package_fetch_without_location():
  with temporary_dir() as td:
    dateutil_base = 'python-dateutil-1.5'
    dateutil = '%s.zip' % dateutil_base

    with contextlib.closing(ZipFile(os.path.join(td, dateutil), 'w')) as zf:
      zf.writestr(os.path.join(dateutil_base, 'file1.txt'), 'junk1')
      zf.writestr(os.path.join(dateutil_base, 'file2.txt'), 'junk2')

    dest = Archiver.unpack(zf.filename)
    assert set(os.listdir(dest)) == set(['file1.txt', 'file2.txt'])

    with temporary_dir() as td2:
      dest = Archiver.unpack(zf.filename, location=td2)
      assert set(os.listdir(os.path.join(td2, 'python-dateutil-1.5'))) == set(
          ['file1.txt', 'file2.txt'])
示例#3
0
  def __init__(self, url, **kw):
    super(SourcePackage, self).__init__(url, **kw)

    ext = Archiver.get_extension(self.filename)
    if ext is None:
      raise self.InvalidPackage('%s is not a recognized archive format.' % self.filename)

    fragment = self.filename[:-len(ext)]
    self._name, self._raw_version = self.split_fragment(fragment)
示例#4
0
    def translate(self, package, into=None):
        """From a SourcePackage, translate to a binary distribution."""
        if not isinstance(package, SourcePackage):
            return None
        if not package.local:
            raise ValueError(
                'SourceTranslator cannot translate remote packages.')

        installer = None
        version = self._interpreter.version
        unpack_path = Archiver.unpack(package.local_path)
        into = into or safe_mkdtemp()

        try:
            if self._use_2to3 and version >= (3, ):
                with TRACER.timed('Translating 2->3 %s' % package.name):
                    self.run_2to3(unpack_path)
            installer = self._installer_impl(unpack_path,
                                             interpreter=self._interpreter)
            with TRACER.timed('Packaging %s' % package.name):
                try:
                    dist_path = installer.bdist()
                except self._installer_impl.InstallFailure as e:
                    TRACER.log('Failed to install package at %s: %s' %
                               (unpack_path, e))
                    return None
                target_path = os.path.join(into, os.path.basename(dist_path))
                safe_copy(dist_path, target_path)
                target_package = Package.from_href(target_path)
                if not target_package:
                    TRACER.log('Target path %s does not look like a Package.' %
                               target_path)
                    return None
                if not target_package.compatible(self._supported_tags):
                    TRACER.log('Target package %s is not compatible with %s' %
                               (target_package, self._supported_tags))
                    return None
                return DistributionHelper.distribution_from_path(target_path)
        except Exception as e:
            TRACER.log('Failed to translate %s' % package)
            TRACER.log(traceback.format_exc())
        finally:
            if installer:
                installer.cleanup()
            if unpack_path:
                safe_rmtree(unpack_path)
示例#5
0
文件: pex.py 项目: windie/heron
 def installer_provider(sdist):
     return EggInstaller(Archiver.unpack(sdist),
                         strict=requirement.key != 'setuptools',
                         interpreter=interpreter)
示例#6
0
文件: pex.py 项目: Houzz/pex
 def installer_provider(sdist):
   return EggInstaller(
       Archiver.unpack(sdist),
       strict=requirement.key != 'setuptools',
       interpreter=interpreter)