예제 #1
0
def yield_pex_builder(zip_safe=True):
    with nested(temporary_dir(),
                make_distribution('p1', zipped=True,
                                  zip_safe=zip_safe)) as (td, p1):
        pb = PEXBuilder(path=td)
        pb.add_egg(p1.location)
        yield pb
예제 #2
0
def build_pex(args, options):
    interpreter = None
    if options.python:
        if os.path.exists(options.python):
            interpreter = PythonInterpreter.from_binary(options.python)
        else:
            interpreter = PythonInterpreter.from_env(options.python)
        if interpreter is None:
            die('Failed to find interpreter: %s' % options.python)

    pex_builder = PEXBuilder(
        path=safe_mkdtemp(),
        interpreter=interpreter,
    )

    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())

    resolveds = requirement_resolver(options.requirements,
                                     cache=options.cache_dir,
                                     fetchers=fetchers,
                                     interpreter=interpreter,
                                     platform=options.platform)

    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:
        try:
            egg_path = EggInstaller(source_dir).bdist()
        except EggInstaller.Error:
            die('Failed to run installer for %s' % source_dir, 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)

    return pex_builder
예제 #3
0
파일: pex.py 프로젝트: CodeWarltz/commons
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
def write_pex(td, exe_contents, dists=None):
    dists = dists or []

    with open(os.path.join(td, "exe.py"), "w") as fp:
        fp.write(exe_contents)

    pb = PEXBuilder(path=td)
    for dist in dists:
        pb.add_egg(dist.location)
    pb.set_executable(os.path.join(td, "exe.py"))
    pb.freeze()

    return pb
예제 #5
0
def write_pex(td, exe_contents, dists=None):
    dists = dists or []

    with open(os.path.join(td, 'exe.py'), 'w') as fp:
        fp.write(exe_contents)

    pb = PEXBuilder(path=td)
    for dist in dists:
        pb.add_egg(dist.location)
    pb.set_executable(os.path.join(td, 'exe.py'))
    pb.freeze()

    return pb
예제 #6
0
파일: pex.py 프로젝트: koonom1985/commons
def build_pex(args, options):
    interpreter = interpreter_from_options(options)

    pex_builder = PEXBuilder(path=safe_mkdtemp(), interpreter=interpreter)

    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

    resolveds = requirement_resolver(
        options.requirements, obtainer=build_obtainer(options), interpreter=interpreter, platform=options.platform
    )

    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:
        try:
            egg_path = EggInstaller(source_dir).bdist()
        except EggInstaller.Error:
            die("Failed to run installer for %s" % source_dir, 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)

    return pex_builder
예제 #7
0
def yield_pex_builder(zip_safe=True):
  with nested(temporary_dir(), make_distribution('p1', zipped=True, zip_safe=zip_safe)) as (td, p1):
    pb = PEXBuilder(path=td)
    pb.add_egg(p1.location)
    yield pb