当前位置: 首页>>代码示例>>Python>>正文


Python PythonInterpreter.get方法代码示例

本文整理汇总了Python中twitter.common.python.interpreter.PythonInterpreter.get方法的典型用法代码示例。如果您正苦于以下问题:Python PythonInterpreter.get方法的具体用法?Python PythonInterpreter.get怎么用?Python PythonInterpreter.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twitter.common.python.interpreter.PythonInterpreter的用法示例。


在下文中一共展示了PythonInterpreter.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from twitter.common.python.interpreter import PythonInterpreter [as 别名]
# 或者: from twitter.common.python.interpreter.PythonInterpreter import get [as 别名]
  def __init__(self, target, root_dir, run_tracker, interpreter=None, conn_timeout=None):
    self.target = target
    self.interpreter = interpreter or PythonInterpreter.get()
    if not isinstance(target, PythonBinary):
      raise PythonBinaryBuilder.NotABinaryTargetException(
          "Target %s is not a PythonBinary!" % target)

    config = Config.load()
    self.distdir = config.getdefault('pants_distdir')
    distpath = tempfile.mktemp(dir=self.distdir, prefix=target.name)

    run_info = run_tracker.run_info
    build_properties = {}
    build_properties.update(run_info.add_basic_info(run_id=None, timestamp=time.time()))
    build_properties.update(run_info.add_scm_info())

    pexinfo = target.pexinfo.copy()
    pexinfo.build_properties = build_properties
    builder = PEXBuilder(distpath, pex_info=pexinfo, interpreter=self.interpreter)

    self.chroot = PythonChroot(
        target,
        root_dir,
        builder=builder,
        interpreter=self.interpreter,
        conn_timeout=conn_timeout)
开发者ID:FernandoG26,项目名称:commons,代码行数:28,代码来源:binary_builder.py

示例2: __init__

# 需要导入模块: from twitter.common.python.interpreter import PythonInterpreter [as 别名]
# 或者: from twitter.common.python.interpreter.PythonInterpreter import get [as 别名]
  def __init__(self,
               target,
               root_dir,
               extra_targets=None,
               extra_requirements=None,
               builder=None,
               platforms=None,
               interpreter=None,
               conn_timeout=None):
    self._config = Config.load()
    self._target = target
    self._root = root_dir
    self._platforms = platforms
    self._interpreter = interpreter or PythonInterpreter.get()
    self._extra_targets = list(extra_targets) if extra_targets is not None else []
    self._extra_requirements = list(extra_requirements) if extra_requirements is not None else []
    self._builder = builder or PEXBuilder(tempfile.mkdtemp(), interpreter=self._interpreter)

    # Note: unrelated to the general pants artifact cache.
    self._egg_cache_root = os.path.join(
        PythonSetup(self._config).scratch_dir('artifact_cache', default_name='artifacts'),
        str(self._interpreter.identity))

    self._key_generator = CacheKeyGenerator()
    self._build_invalidator = BuildInvalidator( self._egg_cache_root)
开发者ID:ejconlon,项目名称:pants,代码行数:27,代码来源:python_chroot.py

示例3: build

# 需要导入模块: from twitter.common.python.interpreter import PythonInterpreter [as 别名]
# 或者: from twitter.common.python.interpreter.PythonInterpreter import get [as 别名]
  def build(self, targets, args, interpreter=None, conn_timeout=None):
    test_targets = []
    binary_targets = []
    interpreter = interpreter or PythonInterpreter.get()

    for target in targets:
      assert target.is_python, "PythonBuilder can only build PythonTargets, given %s" % str(target)

    # PythonBuilder supports PythonTests and PythonBinaries
    for target in targets:
      if isinstance(target, PythonTests) or isinstance(target, PythonTestSuite):
        test_targets.append(target)
      elif isinstance(target, PythonBinary):
        binary_targets.append(target)

    rv = PythonTestBuilder(
        test_targets,
        args,
        self._root_dir,
        interpreter=interpreter,
        conn_timeout=conn_timeout).run()
    if rv != 0:
      return rv

    for binary_target in binary_targets:
      rv = PythonBinaryBuilder(
          binary_target,
          self._root_dir,
          self._run_tracker,
          interpreter=interpreter,
          conn_timeout=conn_timeout).run()
      if rv != 0:
        return rv

    return 0
开发者ID:ejconlon,项目名称:pants,代码行数:37,代码来源:python_builder.py

示例4: select_interpreter

# 需要导入模块: from twitter.common.python.interpreter import PythonInterpreter [as 别名]
# 或者: from twitter.common.python.interpreter.PythonInterpreter import get [as 别名]
 def select_interpreter(self, compatibilities, allow_multiple=False):
   if allow_multiple:
     return compatibilities
   me = PythonInterpreter.get()
   if me in compatibilities:
     return [me]
   return [min(compatibilities)] if compatibilities else []
开发者ID:jfarrell,项目名称:commons,代码行数:9,代码来源:interpreter_cache.py

示例5: __init__

# 需要导入模块: from twitter.common.python.interpreter import PythonInterpreter [as 别名]
# 或者: from twitter.common.python.interpreter.PythonInterpreter import get [as 别名]
 def __init__(self, targets, args, root_dir, interpreter=None, conn_timeout=None):
   self.targets = targets
   self.args = args
   self.root_dir = root_dir
   self.interpreter = interpreter or PythonInterpreter.get()
   self.successes = {}
   self._conn_timeout = conn_timeout
开发者ID:ejconlon,项目名称:pants,代码行数:9,代码来源:test_builder.py

示例6: test_iter_ordering

# 需要导入模块: from twitter.common.python.interpreter import PythonInterpreter [as 别名]
# 或者: from twitter.common.python.interpreter.PythonInterpreter import get [as 别名]
def test_iter_ordering():
  pi = PythonInterpreter.get()
  tgz = SourcePackage('psutil-0.6.1.tar.gz')
  egg = EggPackage('psutil-0.6.1-py%s-%s.egg' % (pi.python, get_build_platform()))
  req = Requirement.parse('psutil')

  assert list(FakeObtainer([tgz, egg]).iter(req)) == [egg, tgz]
  assert list(FakeObtainer([egg, tgz]).iter(req)) == [egg, tgz]
开发者ID:dturner-tw,项目名称:commons,代码行数:10,代码来源:test_obtainer.py

示例7: from_file

# 需要导入模块: from twitter.common.python.interpreter import PythonInterpreter [as 别名]
# 或者: from twitter.common.python.interpreter.PythonInterpreter import get [as 别名]
 def from_file(filename, interpreter=PythonInterpreter.get()):
     if filename.lower().endswith(".egg"):
         return PythonDependency.from_eggs(filename, interpreter=interpreter)
     else:
         for suffix in VALID_SOURCE_EXTENSIONS:
             if filename.lower().endswith(suffix):
                 return PythonDependency.from_source(filename, interpreter=interpreter)
     raise PythonDependency.RequirementError("Unrecognized Python dependency file format: %s!" % filename)
开发者ID:satifanie,项目名称:commons,代码行数:10,代码来源:dependency.py

示例8: install_requirement

# 需要导入模块: from twitter.common.python.interpreter import PythonInterpreter [as 别名]
# 或者: from twitter.common.python.interpreter.PythonInterpreter import get [as 别名]
  def install_requirement(req,
                          path=None,
                          extra_site_dirs=[],
                          index='http://pypi.python.org/simple',
                          repositories=['http://pypi.python.org/simple'],
                          interpreter=PythonInterpreter.get()):
    """
      Install the requirement "req" to path "path" with extra_site_dirs put
      onto the PYTHONPATH.  Returns the set of newly added Distributions
      (of type pkg_resource.Distribution.)

      "req" can either be a pkg_resources.Requirement object (e.g. created by
        pkg_resources.Requirement.parse("MySQL-python==1.2.2")) or an installable
        package (e.g. a tar.gz source distribution, a source or binary .egg)

      "path" is the into which we install the requirements.  if path is None,
      we'll create one for you.
    """

    # TODO(wickman)  Consider importing the easy_install Command class directly and
    # manipulating it with initialize/finalize options + run.

    if not isinstance(req, pkg_resources.Requirement):
      if not os.path.exists(req):
        try:
          req = pkg_resources.Requirement.parse(req)
        except:
          raise TypeError(
            "req should either be an installable file, a pkg_resources.Requirement "
            "or a valid requirement string.  got %s" % req)

    if path is None:
      path = tempfile.mkdtemp()

    if not os.path.exists(path):
      safe_mkdir(path)

    easy_install_args = [
      '--install-dir=%s' % path,
      '--site-dirs=%s' % ','.join([path] + extra_site_dirs),
      '--always-copy',
      '--multi-version',
      '--exclude-scripts',
      '-i', index]
    for repo in reversed(repositories):
      easy_install_args.extend(['-f', repo])
    easy_install_args.append(str(req))

    distributions_backup = set(pkg_resources.find_distributions(path))

    rc = ReqBuilder.run_easy_install([path] + extra_site_dirs + sys.path,
      easy_install_args, interpreter)

    distributions = set(pkg_resources.find_distributions(path))
    new_distributions = distributions - distributions_backup
    return new_distributions if rc else set()
开发者ID:adamsxu,项目名称:commons,代码行数:58,代码来源:reqbuilder.py

示例9: __init__

# 需要导入模块: from twitter.common.python.interpreter import PythonInterpreter [as 别名]
# 或者: from twitter.common.python.interpreter.PythonInterpreter import get [as 别名]
  def __init__(self, targets, args, interpreter=None, conn_timeout=None, fast=False):
    self.targets = targets
    self.args = args
    self.interpreter = interpreter or PythonInterpreter.get()
    self._conn_timeout = conn_timeout

    # If fast is true, we run all the tests in a single chroot. This is MUCH faster than
    # creating a chroot for each test target. However running each test separately is more
    # correct, as the isolation verifies that its dependencies are correctly declared.
    self._fast = fast
开发者ID:igmor,项目名称:pants,代码行数:12,代码来源:test_builder.py

示例10: test_iter_ordering

# 需要导入模块: from twitter.common.python.interpreter import PythonInterpreter [as 别名]
# 或者: from twitter.common.python.interpreter.PythonInterpreter import get [as 别名]
def test_iter_ordering():
  pi = PythonInterpreter.get()
  tgz = SourcePackage('psutil-0.6.1.tar.gz')
  egg = EggPackage('psutil-0.6.1-py%s-%s.egg' % (pi.python, get_build_platform()))
  whl = WheelPackage('psutil-0.6.1-cp%s-none-%s.whl' % (
      pi.python.replace('.', ''),
      get_build_platform().replace('-', '_').replace('.', '_').lower()))
  req = Requirement.parse('psutil')

  assert list(FakeObtainer([tgz, egg, whl]).iter(req)) == [whl, egg, tgz]
  assert list(FakeObtainer([egg, tgz, whl]).iter(req)) == [whl, egg, tgz]
开发者ID:FernandoG26,项目名称:commons,代码行数:13,代码来源:test_obtainer.py

示例11: interpreter_from_options

# 需要导入模块: from twitter.common.python.interpreter import PythonInterpreter [as 别名]
# 或者: from twitter.common.python.interpreter.PythonInterpreter import get [as 别名]
def interpreter_from_options(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)
  else:
    interpreter = PythonInterpreter.get()
  return interpreter
开发者ID:EricCen,项目名称:commons,代码行数:14,代码来源:pex.py

示例12: resolve_multi

# 需要导入模块: from twitter.common.python.interpreter import PythonInterpreter [as 别名]
# 或者: from twitter.common.python.interpreter.PythonInterpreter import get [as 别名]
def resolve_multi(config,
                  requirements,
                  interpreter=None,
                  platforms=None,
                  conn_timeout=None,
                  ttl=3600):
  """Multi-platform dependency resolution for PEX files.

     Given a pants configuration and a set of requirements, return a list of distributions
     that must be included in order to satisfy them.  That may involve distributions for
     multiple platforms.

     :param config: Pants :class:`Config` object.
     :param requirements: A list of :class:`PythonRequirement` objects to resolve.
     :param interpreter: :class:`PythonInterpreter` for which requirements should be resolved.
                         If None specified, defaults to current interpreter.
     :param platforms: Optional list of platforms against requirements will be resolved. If
                         None specified, the defaults from `config` will be used.
     :param conn_timeout: Optional connection timeout for any remote fetching.
     :param ttl: Time in seconds before we consider re-resolving an open-ended requirement, e.g.
                 "flask>=0.2" if a matching distribution is available on disk.  Defaults
                 to 3600.
  """
  distributions = dict()
  interpreter = interpreter or PythonInterpreter.get()
  if not isinstance(interpreter, PythonInterpreter):
    raise TypeError('Expected interpreter to be a PythonInterpreter, got %s' % type(interpreter))

  install_cache = PythonSetup(config).scratch_dir('install_cache', default_name='eggs')
  platforms = get_platforms(platforms or config.getlist('python-setup', 'platforms', ['current']))

  for platform in platforms:
    translator = Translator.default(
        install_cache=install_cache,
        interpreter=interpreter,
        platform=platform,
        conn_timeout=conn_timeout)

    obtainer = PantsObtainer(
        install_cache=install_cache,
        crawler=crawler_from_config(config, conn_timeout=conn_timeout),
        fetchers=fetchers_from_config(config) or [PyPIFetcher()],
        translators=translator)

    distributions[platform] = resolve(requirements=requirements,
                                      obtainer=obtainer,
                                      interpreter=interpreter,
                                      platform=platform)

  return distributions
开发者ID:aoen,项目名称:pants,代码行数:52,代码来源:resolver.py

示例13: __init__

# 需要导入模块: from twitter.common.python.interpreter import PythonInterpreter [as 别名]
# 或者: from twitter.common.python.interpreter.PythonInterpreter import get [as 别名]
  def __init__(self, target, root_dir, extra_targets=None, builder=None, interpreter=None,
      conn_timeout=None):
    self._config = Config.load()
    self._target = target
    self._root = root_dir
    self._interpreter = interpreter or PythonInterpreter.get()
    self._extra_targets = list(extra_targets) if extra_targets is not None else []
    self._resolver = MultiResolver(self._config, target, conn_timeout=conn_timeout)
    self._builder = builder or PEXBuilder(tempfile.mkdtemp(), interpreter=self._interpreter)

    # Note: unrelated to the general pants artifact cache.
    self._egg_cache_root = os.path.join(self._config.get('python-setup', 'artifact_cache'),
                                        str(self._interpreter.identity))

    self._key_generator = CacheKeyGenerator()
    self._build_invalidator = BuildInvalidator( self._egg_cache_root)
开发者ID:CodeWarltz,项目名称:commons,代码行数:18,代码来源:python_chroot.py

示例14: build

# 需要导入模块: from twitter.common.python.interpreter import PythonInterpreter [as 别名]
# 或者: from twitter.common.python.interpreter.PythonInterpreter import get [as 别名]
  def build(self, targets, args, interpreter=None, conn_timeout=None):
    test_targets = []
    binary_targets = []
    interpreter = interpreter or PythonInterpreter.get()

    for target in targets:
      assert target.is_python, "PythonBuilder can only build PythonTargets, given %s" % str(target)

    if 'pylint' in args:
      real_args = list(args)
      real_args.remove('pylint')
      for target in targets:
        try:
          PythonLintBuilder([target], real_args, self._root_dir, conn_timeout=conn_timeout).run()
        except Exception as e:
          print('Failed to run lint for %s: %s' % (target, e))
      return 0

    # PythonBuilder supports PythonTests and PythonBinaries
    for target in targets:
      if isinstance(target, PythonTests) or isinstance(target, PythonTestSuite):
        test_targets.append(target)
      elif isinstance(target, PythonBinary):
        binary_targets.append(target)

    rv = PythonTestBuilder(
        test_targets,
        args,
        self._root_dir,
        interpreter=interpreter,
        conn_timeout=conn_timeout).run()
    if rv != 0:
      return rv

    for binary_target in binary_targets:
      rv = PythonBinaryBuilder(
          binary_target,
          self._root_dir,
          self._run_tracker,
          interpreter=interpreter,
          conn_timeout=conn_timeout).run()
      if rv != 0:
        return rv

    return 0
开发者ID:CodeWarltz,项目名称:commons,代码行数:47,代码来源:python_builder.py

示例15: resolve_multi

# 需要导入模块: from twitter.common.python.interpreter import PythonInterpreter [as 别名]
# 或者: from twitter.common.python.interpreter.PythonInterpreter import get [as 别名]
def resolve_multi(config,
                  requirements,
                  interpreter=None,
                  platforms=None,
                  conn_timeout=None,
                  ttl=3600):
  """Multi-platform dependency resolution for PEX files.

     Given a pants configuration and a set of requirements, return a list of distributions
     that must be included in order to satisfy them.  That may involve distributions for
     multiple platforms.

     :param config: Pants :class:`Config` object.
     :param requirements: A list of :class:`PythonRequirement` objects to resolve.
     :param interpreter: :class:`PythonInterpreter` for which requirements should be resolved.
                         If None specified, defaults to current interpreter.
     :param platforms: Optional list of platforms against requirements will be resolved. If
                         None specified, the defaults from `config` will be used.
     :param conn_timeout: Optional connection timeout for any remote fetching.
     :param ttl: Time in seconds before we consider re-resolving an open-ended requirement, e.g.
                 "flask>=0.2" if a matching distribution is available on disk.  Defaults
                 to 3600.
  """
  now = time.time()
  distributions = {}

  interpreter = interpreter or PythonInterpreter.get()
  if not isinstance(interpreter, PythonInterpreter):
    raise TypeError('Expected interpreter to be a PythonInterpreter, got %s' % type(interpreter))

  install_cache = PythonSetup(config).scratch_dir('install_cache', default_name='eggs')
  platforms = get_platforms(platforms or config.getlist('python-setup', 'platforms', ['current']))
  crawler = crawler_from_config(config, conn_timeout=conn_timeout)
  fetchers = fetchers_from_config(config)

  for platform in platforms:
    env = PantsEnvironment(interpreter, platform=platform)
    working_set = WorkingSet(entries=[])

    shared_options = dict(install_cache=install_cache, platform=platform)
    egg_translator = EggTranslator(interpreter=interpreter, **shared_options)
    egg_obtainer = Obtainer(crawler, [Fetcher([install_cache])], egg_translator)

    def installer(req):
      # Attempt to obtain the egg from the local cache.  If it's an exact match, we can use it.
      # If it's not an exact match, then if it's been resolved sufficiently recently, we still
      # use it.
      dist = egg_obtainer.obtain(req)
      if dist and (requirement_is_exact(req) or now - os.path.getmtime(dist.location) < ttl):
        return dist

      # Failed, so follow through to "remote" resolution
      source_translator = SourceTranslator(
           interpreter=interpreter,
           use_2to3=getattr(req, 'use_2to3', False),
           **shared_options)
      translator = ChainedTranslator(egg_translator, source_translator)
      obtainer = Obtainer(
          crawler,
          [Fetcher([req.repository])] if getattr(req, 'repository', None) else fetchers,
          translator)
      dist = obtainer.obtain(req)
      if dist:
        try:
          touch(dist.location)
        except OSError:
          pass
      return dist

    distributions[platform] = working_set.resolve(requirements, env=env, installer=installer)

  return distributions
开发者ID:intchar90,项目名称:commons,代码行数:74,代码来源:resolver.py


注:本文中的twitter.common.python.interpreter.PythonInterpreter.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。