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


Python ParseContext.temp方法代码示例

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


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

示例1: test_binary_target_injected_into_minified_dependencies

# 需要导入模块: from twitter.pants.base import ParseContext [as 别名]
# 或者: from twitter.pants.base.ParseContext import temp [as 别名]
  def test_binary_target_injected_into_minified_dependencies(self):
    with ParseContext.temp():
      foo = python_library(
        name = 'foo',
        provides = setup_py(
          name = 'foo',
          version = '0.0.0',
        ).with_binaries(
          foo_binary = pants(':foo_bin')
        )
      )

      foo_bin = python_binary(
        name = 'foo_bin',
        entry_point = 'foo.bin.foo',
        dependencies = [ pants(':foo_bin_dep') ]
      )

      foo_bin_dep = python_library(
        name = 'foo_bin_dep'
      )

    assert SetupPy.minified_dependencies(foo) == OrderedSet([foo_bin, foo_bin_dep])
    entry_points = dict(SetupPy.iter_entry_points(foo))
    assert entry_points == {'foo_binary': 'foo.bin.foo'}

    with self.run_execute(foo, recursive=False) as setup_py_command:
      setup_py_command.run_one.assert_called_with(foo)

    with self.run_execute(foo, recursive=True) as setup_py_command:
      setup_py_command.run_one.assert_called_with(foo)
开发者ID:CodeWarltz,项目名称:commons,代码行数:33,代码来源:test_setup_py.py

示例2: create_target

# 需要导入模块: from twitter.pants.base import ParseContext [as 别名]
# 或者: from twitter.pants.base.ParseContext import temp [as 别名]
  def create_target(category, target_name, target_index, targets):
    def name(name):
      return "%s-%s-%d" % (target_name, name, target_index)

    # TODO(John Sirois): JavaLibrary and ScalaLibrary can float here between src/ and tests/ - add
    # ant build support to allow the same treatment for JavaThriftLibrary and JavaProtobufLibrary
    # so that tests can house test IDL in tests/
    target_type, base = category
    with ParseContext.temp(base):
      if target_type == JavaProtobufLibrary:
        return _aggregate(JavaProtobufLibrary, name('protobuf'), targets, buildflags=buildflags)
      elif target_type == JavaThriftLibrary:
        return _aggregate(JavaThriftLibrary, name('thrift'), targets, buildflags=buildflags)
      elif target_type == AnnotationProcessor:
        return _aggregate(AnnotationProcessor, name('apt'), targets)
      elif target_type == JavaLibrary:
        return _aggregate(JavaLibrary, name('java'), targets, deployjar, buildflags)
      elif target_type == ScalaLibrary:
        return _aggregate(ScalaLibrary, name('scala'), targets, deployjar, buildflags)
      elif target_type == JavaTests:
        return _aggregate(JavaTests, name('java-tests'), targets, buildflags=buildflags)
      elif target_type == ScalaTests:
        return _aggregate(ScalaTests, name('scala-tests'), targets, buildflags=buildflags)
      else:
        raise Exception("Cannot aggregate targets of type: %s" % target_type)
开发者ID:JoeEnnever,项目名称:commons,代码行数:27,代码来源:bang.py

示例3: __init__

# 需要导入模块: from twitter.pants.base import ParseContext [as 别名]
# 或者: from twitter.pants.base.ParseContext import temp [as 别名]
  def __init__(self, name, sources=None, resources=None, exclusives=None):
    TargetWithSources.__init__(self, name, sources=sources, exclusives=exclusives)

    if resources is not None:
      def is_resources(item):
        if not isinstance(item, Target):
          return False
        concrete_targets = [t for t in item.resolve() if t.is_concrete]
        return all(isinstance(t, Resources) for t in concrete_targets)

      if is_resources(resources):
        self.resources = list(self.resolve_all(resources, Resources))
      elif isinstance(resources, Sequence) and all(map(is_resources, resources)):
        self.resources = list(self.resolve_all(resources, Resources))
      else:
        # Handle parallel resource dir globs.
        # For example, for a java_library target base of src/main/java:
        #   src/main/java/com/twitter/base/BUILD
        # We get:
        #   sibling_resources_base = src/main/resources
        #   base_relpath = com/twitter/base
        #   resources_dir = src/main/resources/com/twitter/base
        #
        # TODO(John Sirois): migrate projects to Resources and remove support for old style assumed
        # parallel resources dirs
        sibling_resources_base = os.path.join(os.path.dirname(self.target_base), 'resources')
        base_relpath = os.path.relpath(self.address.buildfile.relpath, self.target_base)
        resources_dir = os.path.join(sibling_resources_base, base_relpath)
        with ParseContext.temp(basedir=resources_dir):
          self.resources = [Resources(name, resources)]
开发者ID:alfss,项目名称:commons,代码行数:32,代码来源:resources.py

示例4: test_python_binary_with_entry_point_and_source

# 需要导入模块: from twitter.pants.base import ParseContext [as 别名]
# 或者: from twitter.pants.base.ParseContext import temp [as 别名]
 def test_python_binary_with_entry_point_and_source(self):
   with ParseContext.temp('src'):
     assert 'blork' == PythonBinary(
         name = 'binary1', entry_point = 'blork', source='blork.py').entry_point
     assert 'blork:main' == PythonBinary(
         name = 'binary2', entry_point = 'blork:main', source='blork.py').entry_point
     assert 'bin.blork:main' == PythonBinary(
         name = 'binary3', entry_point = 'bin.blork:main', source='bin/blork.py').entry_point
开发者ID:chencao0524,项目名称:commons,代码行数:10,代码来源:test_python_binary.py

示例5: test_validation

# 需要导入模块: from twitter.pants.base import ParseContext [as 别名]
# 或者: from twitter.pants.base.ParseContext import temp [as 别名]
  def test_validation(self):
    with ParseContext.temp('InternalTargetTest/test_validation'):
      InternalTarget(name="valid", dependencies=None)
      self.assertRaises(TargetDefinitionException, InternalTarget,
                        name=1, dependencies=None)

      InternalTarget(name="valid2", dependencies=Target(name='mybird'))
      self.assertRaises(TargetDefinitionException, InternalTarget,
                        name='valid3', dependencies=1)
开发者ID:CodeWarltz,项目名称:commons,代码行数:11,代码来源:test_internal.py

示例6: generate_test_targets

# 需要导入模块: from twitter.pants.base import ParseContext [as 别名]
# 或者: from twitter.pants.base.ParseContext import temp [as 别名]
 def generate_test_targets():
   if PythonTestBuilder.TESTING_TARGETS is None:
     with ParseContext.temp():
       PythonTestBuilder.TESTING_TARGETS = [
         PythonRequirement('pytest'),
         PythonRequirement('unittest2', version_filter=lambda:sys.version_info[0]==2),
         PythonRequirement('unittest2py3k', version_filter=lambda:sys.version_info[0]==3)
       ]
   return PythonTestBuilder.TESTING_TARGETS
开发者ID:JoeEnnever,项目名称:commons,代码行数:11,代码来源:test_builder.py

示例7: execute

# 需要导入模块: from twitter.pants.base import ParseContext [as 别名]
# 或者: from twitter.pants.base.ParseContext import temp [as 别名]
  def execute(self):
    if self.options.pex and self.options.ipython:
      self.error('Cannot specify both --pex and --ipython!')

    if self.options.entry_point and self.options.ipython:
      self.error('Cannot specify both --entry_point and --ipython!')

    if self.options.verbose:
      print('Build operating on target: %s %s' % (self.target,
        'Extra targets: %s' % ' '.join(map(str, self.extra_targets)) if self.extra_targets else ''))

    builder = PEXBuilder(tempfile.mkdtemp(), interpreter=self.interpreter,
        pex_info=self.target.pexinfo if isinstance(self.target, PythonBinary) else None)

    if self.options.entry_point:
      builder.set_entry_point(self.options.entry_point)

    if self.options.ipython:
      if not self.config.has_section('python-ipython'):
        self.error('No python-ipython sections defined in your pants.ini!')

      builder.info.entry_point = self.config.get('python-ipython', 'entry_point')
      if builder.info.entry_point is None:
        self.error('Must specify entry_point for IPython in the python-ipython section '
                   'of your pants.ini!')

      requirements = self.config.getlist('python-ipython', 'requirements', default=[])

      with ParseContext.temp():
        for requirement in requirements:
          self.extra_targets.append(PythonRequirement(requirement))

    executor = PythonChroot(
        self.target,
        self.root_dir,
        builder=builder,
        interpreter=self.interpreter,
        extra_targets=self.extra_targets,
        conn_timeout=self.options.conn_timeout)

    executor.dump()

    if self.options.pex:
      pex_name = os.path.join(self.root_dir, 'dist', '%s.pex' % self.target.name)
      builder.build(pex_name)
      print('Wrote %s' % pex_name)
      return 0
    else:
      builder.freeze()
      pex = PEX(builder.path(), interpreter=self.interpreter)
      po = pex.run(args=list(self.args), blocking=False)
      try:
        return po.wait()
      except KeyboardInterrupt:
        po.send_signal(signal.SIGINT)
        raise
开发者ID:alfss,项目名称:commons,代码行数:58,代码来源:py.py

示例8: create_dependencies

# 需要导入模块: from twitter.pants.base import ParseContext [as 别名]
# 或者: from twitter.pants.base.ParseContext import temp [as 别名]
def create_dependencies(depmap):
  target_map = {}
  with ParseContext.temp():
    for name, deps in depmap.items():
      target_map[name] = python_library(
        name=name,
        provides=setup_py(name=name, version='0.0.0'),
        dependencies=[pants(':%s' % dep) for dep in deps]
      )
  return target_map
开发者ID:CodeWarltz,项目名称:commons,代码行数:12,代码来源:test_setup_py.py

示例9: __init__

# 需要导入模块: from twitter.pants.base import ParseContext [as 别名]
# 或者: from twitter.pants.base.ParseContext import temp [as 别名]
 def __init__(self, name, dependencies=None, num_sources=0, exclusives=None):
   with ParseContext.temp():
     InternalTarget.__init__(self, name, dependencies, exclusives=exclusives)
     TargetWithSources.__init__(self, name, exclusives=exclusives)
   self.num_sources = num_sources
   self.declared_exclusives = defaultdict(set)
   if exclusives is not None:
     for k in exclusives:
       self.declared_exclusives[k] = set([exclusives[k]])
   self.exclusives = None
开发者ID:BabyDuncan,项目名称:commons,代码行数:12,代码来源:mock_target.py

示例10: test_python_binary_with_entry_point_and_source_mismatch

# 需要导入模块: from twitter.pants.base import ParseContext [as 别名]
# 或者: from twitter.pants.base.ParseContext import temp [as 别名]
 def test_python_binary_with_entry_point_and_source_mismatch(self):
   with ParseContext.temp('src'):
     with pytest.raises(TargetDefinitionException):
       PythonBinary(name = 'binary1', entry_point = 'blork', source='hork.py')
     with pytest.raises(TargetDefinitionException):
       PythonBinary(name = 'binary2', entry_point = 'blork:main', source='hork.py')
     with pytest.raises(TargetDefinitionException):
       PythonBinary(name = 'binary3', entry_point = 'bin.blork', source='blork.py')
     with pytest.raises(TargetDefinitionException):
       PythonBinary(name = 'binary4', entry_point = 'bin.blork', source='bin.py')
开发者ID:chencao0524,项目名称:commons,代码行数:12,代码来源:test_python_binary.py

示例11: generate_test_targets

# 需要导入模块: from twitter.pants.base import ParseContext [as 别名]
# 或者: from twitter.pants.base.ParseContext import temp [as 别名]
 def generate_test_targets(cls):
   if cls.TESTING_TARGETS is None:
     with ParseContext.temp():
       cls.TESTING_TARGETS = [
         PythonRequirement('pytest'),
         PythonRequirement('pytest-cov'),
         PythonRequirement('coverage==3.6b1'),
         PythonRequirement('unittest2', version_filter=lambda py, pl: py.startswith('2')),
         PythonRequirement('unittest2py3k', version_filter=lambda py, pl: py.startswith('3'))
       ]
   return cls.TESTING_TARGETS
开发者ID:CodeWarltz,项目名称:commons,代码行数:13,代码来源:test_builder.py

示例12: generate_test_targets

# 需要导入模块: from twitter.pants.base import ParseContext [as 别名]
# 或者: from twitter.pants.base.ParseContext import temp [as 别名]
 def generate_test_targets():
     if PythonTestBuilder.TESTING_TARGETS is None:
         with ParseContext.temp():
             PythonTestBuilder.TESTING_TARGETS = [
                 PythonRequirement("pytest"),
                 PythonRequirement("pytest-cov"),
                 PythonRequirement("coverage"),
                 PythonRequirement("unittest2", version_filter=lambda: sys.version_info[0] == 2),
                 PythonRequirement("unittest2py3k", version_filter=lambda: sys.version_info[0] == 3),
             ]
     return PythonTestBuilder.TESTING_TARGETS
开发者ID:UrbanCompass,项目名称:commons,代码行数:13,代码来源:test_builder.py

示例13: test_validation

# 需要导入模块: from twitter.pants.base import ParseContext [as 别名]
# 或者: from twitter.pants.base.ParseContext import temp [as 别名]
 def test_validation(self):
   with ParseContext.temp():
     repo = Repository(name="myRepo", url="myUrl", push_db="myPushDb")
     Artifact(org="testOrg", name="testName", repo=repo, description="Test")
     self.assertRaises(ValueError, Artifact,
                       org=1, name="testName", repo=repo, description="Test")
     self.assertRaises(ValueError, Artifact,
                       org="testOrg", name=1, repo=repo, description="Test")
     self.assertRaises(ValueError, Artifact,
                       org="testOrg", name="testName", repo=1, description="Test")
     self.assertRaises(ValueError, Artifact,
                       org="testOrg", name="testName", repo=repo, description=1)
开发者ID:CodeWarltz,项目名称:commons,代码行数:14,代码来源:test_artifact.py

示例14: _generate_requirement

# 需要导入模块: from twitter.pants.base import ParseContext [as 别名]
# 或者: from twitter.pants.base.ParseContext import temp [as 别名]
  def _generate_requirement(self, library, builder_cls):
    library_key = self._key_generator.key_for_target(library)
    builder = builder_cls(library, self._root, self._config, '-' + library_key.hash[:8])

    cache_dir = os.path.join(self._egg_cache_root, library_key.id)
    if self._build_invalidator.needs_update(library_key):
      sdist = builder.build(interpreter=self._interpreter)
      safe_mkdir(cache_dir)
      shutil.copy(sdist, os.path.join(cache_dir, os.path.basename(sdist)))
      self._build_invalidator.update(library_key)

    with ParseContext.temp():
      return PythonRequirement(builder.requirement_string(), repository=cache_dir, use_2to3=True)
开发者ID:CodeWarltz,项目名称:commons,代码行数:15,代码来源:python_chroot.py

示例15: compiled_idl

# 需要导入模块: from twitter.pants.base import ParseContext [as 别名]
# 或者: from twitter.pants.base.ParseContext import temp [as 别名]
  def compiled_idl(cls, idl_dep, generated_deps=None, compiler=None, language=None, namespace_map=None):
    """Marks a jar as containing IDL files that should be fetched and processed locally.

    idl_dep:        A dependency resolvable to a single jar library.
    generated_deps: Dependencies for the code that will be generated from "idl_dep"
    compiler:       The thrift compiler to apply to the fetched thrift IDL files.
    language:       The language to generate code for - supported by some compilers
    namespace_map:  A mapping from IDL declared namespaces to custom namespaces - supported by some
                    compilers.
    """
    deps = [t for t in idl_dep.resolve() if t.is_concrete]
    if not len(deps) == 1:
      raise TaskError('Can only arrange for compiled idl for a single dependency at a time, '
                      'given:\n\t%s' % '\n\t'.join(map(str, deps)))
    jar = deps.pop()
    if not isinstance(jar, JarDependency):
      raise TaskError('Can only arrange for compiled idl from a jar dependency, given: %s' % jar)

    request = (jar, compiler, language)
    namespace_signature = None
    if namespace_map:
      sha = hashlib.sha1()
      for ns_from, ns_to in sorted(namespace_map.items()):
        sha.update(ns_from)
        sha.update(ns_to)
      namespace_signature = sha.hexdigest()
    request += (namespace_signature,)

    if request not in cls._PLACEHOLDER_BY_REQUEST:
      if not cls._EXTRACT_BASE:
        config = Config.load()
        cls._EXTRACT_BASE = config.get('idl-extract', 'workdir')
        safe_mkdir(cls._EXTRACT_BASE)
        SourceRoot.register(cls._EXTRACT_BASE, JavaThriftLibrary)

      with ParseContext.temp(cls._EXTRACT_BASE):
        # TODO(John Sirois): abstract ivy specific configurations notion away
        jar._configurations.append('idl')
        jar.with_artifact(configuration='idl', classifier='idl')
        target_name = '-'.join(filter(None, (jar.id, compiler, language, namespace_signature)))
        placeholder = JavaThriftLibrary(target_name,
                                        sources=None,
                                        dependencies=[jar] + (generated_deps or []),
                                        compiler=compiler,
                                        language=language,
                                        namespace_map=namespace_map)
        cls._PLACEHOLDER_BY_REQUEST[request] = placeholder
        cls._PLACEHOLDERS_BY_JAR[jar].append(placeholder)
    return cls._PLACEHOLDER_BY_REQUEST[request]
开发者ID:alfss,项目名称:commons,代码行数:51,代码来源:extract.py


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