Esempio n. 1
0
  def main(cls):
    from itertools import chain
    from twitter.common.python.distiller import Distiller
    from twitter.common.python.fetcher import Fetcher, PyPIFetcher
    from twitter.common.python.http import Crawler
    from twitter.common.python.installer import Installer
    from twitter.common.python.obtainer import Obtainer
    from twitter.common.python.resolver import Resolver
    from twitter.common.python.translator import Translator

    parser = cls.configure_clp()
    options, args = parser.parse_args()
    cls.process_logging_options(options)
    cls.exit_on_erroneous_inputs(options, parser)

    pex_builder = PEXBuilder()

    fetchers = [Fetcher(options.repos)]
    if options.use_pypi:
      fetchers.append(PyPIFetcher())
    resolver = Resolver(cache=options.cache_dir, fetchers=fetchers, install_cache=options.cache_dir)
    reqs = cls.get_all_valid_reqs(options.requirements, options.requirements_txt)
    cls.logger.info("Requirements specified: " + str(reqs))
    resolveds = resolver.resolve(reqs)
    cls.logger.info("Resolved requirements: " + str(resolveds))
    for pkg in resolveds:
      cls.logger.info("Adding to PEX: Distribution: {0}".format(pkg))
      pex_builder.add_distribution(pkg)
      pex_builder.add_requirement(pkg.as_requirement())
    for source_dir in options.source_dirs:
      dist = Installer(source_dir).distribution()
      egg_path = Distiller(dist).distill()
      cls.logger.info("Adding source dir to PEX: {0} distilled into egg {1}".format(
        source_dir, egg_path)
      )
      pex_builder.add_egg(egg_path)
    if options.entry_point is not None:
      if options.entry_point.endswith(".py"):
        cls.logger.info("Adding entry point to PEX: File: {0}".format(options.entry_point))
        pex_builder.set_executable(options.entry_point)
      elif ":" in options.entry_point:
        cls.logger.info("Adding entry point to PEX: Function: {0}".format(options.entry_point))
        pex_builder.info().entry_point = options.entry_point
      else:
        cls.logger.warn("Invalid entry point: {0}".format(options.entry_point))
    if options.pex_name is not None:
      cls.logger.info("Saving PEX file at {0}.pex".format(options.pex_name))
      pex_builder.build(options.pex_name + '.pex')
    else:
      pex_builder.freeze()
      cls.logger.info("Running PEX file at {0} with args {1}".format(pex_builder.path(), args))
      from .pex import PEX
      pex = PEX(pex_builder.path())
      return pex.run(args=list(args))

    logging.shutdown()
Esempio n. 2
0
def build_pex(args, options):
  pex_builder = PEXBuilder(path=safe_mkdtemp())

  pex_info = pex_builder.info

  pex_info.zip_safe = options.zip_safe
  pex_info.always_write_cache = options.always_write_cache
  pex_info.ignore_errors = options.ignore_errors
  pex_info.inherit_path = options.inherit_path

  fetchers = [Fetcher(options.repos)]

  if options.pypi:
    fetchers.append(PyPIFetcher())

  resolver = Resolver(cache=options.cache_dir, fetchers=fetchers, install_cache=options.cache_dir)

  resolveds = resolver.resolve(options.requirements)

  if resolveds:
    log('Resolved distributions:', v=options.verbosity)
  for pkg in resolveds:
    log('  %s' % pkg, v=options.verbosity)
    pex_builder.add_distribution(pkg)
    pex_builder.add_requirement(pkg.as_requirement())

  for source_dir in options.source_dirs:
    dist = Installer(source_dir).distribution()
    if not dist:
      die('Failed to run installer for %s' % source_dir, CANNOT_DISTILL)
    egg_path = Distiller(dist).distill()
    if not egg_path:
      die('Failed to distill %s into egg' % dist, CANNOT_DISTILL)
    pex_builder.add_egg(egg_path)

  if options.entry_point is not None:
    log('Setting entry point to %s' % options.entry_point, v=options.verbosity)
    pex_builder.info.entry_point = options.entry_point
  else:
    log('Creating environment PEX.', v=options.verbosity)

  if options.pex_name is not None:
    log('Saving PEX file to %s' % options.pex_name, v=options.verbosity)
    tmp_name = options.pex_name + '~'
    safe_delete(tmp_name)
    pex_builder.build(tmp_name)
    os.rename(tmp_name, options.pex_name)
  else:
    pex_builder.freeze()
    log('Running PEX file at %s with args %s' % (pex_builder.path(), args), v=options.verbosity)
    pex = PEX(pex_builder.path())
    return pex.run(args=list(args))

  return 0
Esempio n. 3
0
    def from_target(cls, config, target, conn_timeout=None):
        from twitter.common.python.fetcher import PyPIFetcher, Fetcher
        from twitter.common.python.resolver import Resolver
        from twitter.common.python.http import Crawler
        from twitter.common.quantity import Amount, Time

        conn_timeout_amount = Amount(
            conn_timeout, Time.SECONDS) if conn_timeout is not None else None

        crawler = Crawler(cache=config.get('python-setup', 'download_cache'),
                          conn_timeout=conn_timeout_amount)

        fetchers = []
        fetchers.extend(
            Fetcher([url])
            for url in config.getlist('python-repos', 'repos', []))
        fetchers.extend(
            PyPIFetcher(url)
            for url in config.getlist('python-repos', 'indices', []))

        platforms = config.getlist('python-setup', 'platforms', ['current'])
        if isinstance(target, PythonBinary) and target.platforms:
            platforms = target.platforms

        return cls(platforms=get_platforms(platforms),
                   resolver=Resolver(cache=config.get('python-setup',
                                                      'install_cache'),
                                     crawler=crawler,
                                     fetchers=fetchers,
                                     install_cache=config.get(
                                         'python-setup', 'install_cache'),
                                     conn_timeout=conn_timeout_amount))
Esempio n. 4
0
    def main(cls):
        from itertools import chain
        from twitter.common.python.distiller import Distiller
        from twitter.common.python.fetcher import Fetcher, PyPIFetcher
        from twitter.common.python.http import Crawler
        from twitter.common.python.installer import Installer
        from twitter.common.python.obtainer import Obtainer
        from twitter.common.python.resolver import Resolver
        from twitter.common.python.translator import Translator

        parser = cls.configure_clp()
        options, args = parser.parse_args()
        cls.process_logging_options(options)
        cls.exit_on_erroneous_inputs(options, parser)

        pex_builder = PEXBuilder()

        fetchers = [Fetcher(options.repos)]
        if options.use_pypi:
            fetchers.append(PyPIFetcher())
        resolver = Resolver(cache=options.cache_dir,
                            fetchers=fetchers,
                            install_cache=options.cache_dir)
        reqs = cls.get_all_valid_reqs(options.requirements,
                                      options.requirements_txt)
        cls.logger.info("Requirements specified: " + str(reqs))
        resolveds = resolver.resolve(reqs)
        cls.logger.info("Resolved requirements: " + str(resolveds))
        for pkg in resolveds:
            cls.logger.info("Adding to PEX: Distribution: {0}".format(pkg))
            pex_builder.add_distribution(pkg)
            pex_builder.add_requirement(pkg.as_requirement())
        for source_dir in options.source_dirs:
            dist = Installer(source_dir).distribution()
            egg_path = Distiller(dist).distill()
            cls.logger.info(
                "Adding source dir to PEX: {0} distilled into egg {1}".format(
                    source_dir, egg_path))
            pex_builder.add_egg(egg_path)
        if options.entry_point is not None:
            if options.entry_point.endswith(".py"):
                cls.logger.info("Adding entry point to PEX: File: {0}".format(
                    options.entry_point))
                pex_builder.set_executable(options.entry_point)
            elif ":" in options.entry_point:
                cls.logger.info(
                    "Adding entry point to PEX: Function: {0}".format(
                        options.entry_point))
                pex_builder.info().entry_point = options.entry_point
            else:
                cls.logger.warn("Invalid entry point: {0}".format(
                    options.entry_point))
        if options.pex_name is not None:
            cls.logger.info("Saving PEX file at {0}.pex".format(
                options.pex_name))
            pex_builder.build(options.pex_name + '.pex')
        else:
            pex_builder.freeze()
            cls.logger.info("Running PEX file at {0} with args {1}".format(
                pex_builder.path(), args))
            from .pex import PEX
            pex = PEX(pex_builder.path())
            return pex.run(args=list(args))

        logging.shutdown()