@contextlib.contextmanager
    def bundle_package(self, cache=True):
        """Makes the pybundle archive (that :program:`pip` can take to
        install) with completely resolved dependencies.  It yields triple
        of package name, filename of the pybundle archive, and its full
        path. ::

            with build.bundle_package() as (package, filename, path):
                sftp.put(path, filename)

        :param cache: whether to cache the package file or not.
                      ``True`` by default
        :type cache: :class:`bool`

        """
        asuka_logger = self.get_logger('bundle_package')
        # Makes pip.log.logger to forward records to the standard logging
        if not getattr(type(self), 'initialized', False):
            type(self).initialized = True
            logger.consumers.extend([
                (Logger.FATAL, asuka_logger.critical),
                (Logger.ERROR, asuka_logger.error),
                (Logger.WARN, asuka_logger.warn),
                (Logger.NOTIFY, asuka_logger.info),
                (Logger.INFO, asuka_logger.info),
                (Logger.DEBUG, asuka_logger.debug),
                (Logger.VERBOSE_DEBUG, asuka_logger.debug)
            ])
            vcs.register(Git)
        main_parser = create_main_parser()
        bundle = commands['bundle'](main_parser)
        with self.archive_package() as (package_name, filename, filepath):
            bundle_filename = package_name + '.pybundle'
            if cache:
                cache_dir_path = os.path.join(
                    tempfile.gettempdir(),
                    'asuka-pybundle-cache'
                )
                if not os.path.isdir(cache_dir_path):
                    os.makedirs(cache_dir_path)
                cache_path = os.path.join(cache_dir_path, bundle_filename)
                if os.path.isfile(cache_path):
                    asuka_logger.info('cache exists: %s, skipping pybundle...',
                                      cache_path)
                    yield package_name, bundle_filename, cache_path
                    return
            tempdir = tempfile.gettempdir()
            bundle_path = os.path.join(
                os.path.dirname(filepath),
                bundle_filename
            )
            asuka_logger.info('pybundle_path = %r', bundle_path)
            options = optparse.Values()
            options.editables = []
            options.requirements = []
            options.find_links = []
            options.index_url = PYPI_INDEX_URLS[0]
            options.extra_index_urls = PYPI_INDEX_URLS[1:]
            options.no_index = False
            options.use_mirrors = False
            options.mirrors = True
            options.build_dir = os.path.join(
                tempdir,
                'asuka-dist-build-bundle'
            )
            options.target_dir = None
            options.download_dir = None
            options.download_cache = os.path.join(
                tempdir,
                'asuka-dist-download-cache'
            )
            options.src_dir = backup_dir(src_prefix, '-bundle')
            options.upgrade = False
            options.force_reinstall = False
            options.ignore_dependencies = False
            options.no_install = True
            options.no_download = False
            options.install_options = []
            options.global_options = []
            options.use_user_site = False
            options.as_egg = False
            asuka_logger.debug('start: pip bundle %s %s', bundle_path, filepath)
            retrial = 0
            while 1:
                try:
                    shutil.rmtree(options.build_dir)
                except (OSError, IOError):
                    pass
                try:
                    bundle.run(options, [bundle_path, filepath])
                except PipError as e:
                    asuka_logger.exception(e)
                    retrial += 1
                    if retrial < 3:
                        asuka_logger.error(
                            'retry pip bundle after %d second(s)... (%d)',
                            retrial, retrial ** 2
                        )
                        options.index_url = PYPI_INDEX_URLS[retrial]
                        options.extra_index_urls = PYPI_INDEX_URLS[retrial+1:]
                        time.sleep(retrial ** 2)
                        continue
                    raise
                finally:
                    if os.path.isdir(options.build_dir):
                        shutil.rmtree(options.build_dir)
                break
            asuka_logger.debug('end: pip bundle %s %s', bundle_path, filepath)
            if cache:
                asuka_logger.info('save pybundle cache %s...', cache_path)
                shutil.copyfile(bundle_path, cache_path)
            yield package_name, os.path.basename(bundle_path), bundle_path
dataset/ETHPy150Open crosspop/asuka/asuka/dist.py/Dist.bundle_package/original