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


Python OrderedSet.add方法代码示例

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


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

示例1: _register

# 需要导入模块: from twitter.common.collections import OrderedSet [as 别名]
# 或者: from twitter.common.collections.OrderedSet import add [as 别名]
  def _register(cls, source_root_dir, *allowed_target_types):
    """Registers a source root.

    :source_root_dir The source root directory against which we resolve source paths,
                     relative to the build root.
    :allowed_target_types Optional list of target types. If specified, we enforce that
                          only targets of those types appear under this source root.
    """
    # Verify that source_root_dir doesn't reach outside buildroot.
    buildroot = os.path.normpath(get_buildroot())
    if source_root_dir.startswith(buildroot):
      abspath = os.path.normpath(source_root_dir)
    else:
      abspath = os.path.normpath(os.path.join(buildroot, source_root_dir))
    if not abspath.startswith(buildroot):
      raise ValueError('Source root %s is not under the build root %s' % (abspath, buildroot))
    source_root_dir = os.path.relpath(abspath, buildroot)

    types = cls._TYPES_BY_ROOT.get(source_root_dir)
    if types is None:
      types = OrderedSet()
      cls._TYPES_BY_ROOT[source_root_dir] = types

    for allowed_target_type in allowed_target_types:
      types.add(allowed_target_type)
      roots = cls._ROOTS_BY_TYPE.get(allowed_target_type)
      if roots is None:
        roots = OrderedSet()
        cls._ROOTS_BY_TYPE[allowed_target_type] = roots
      roots.add(source_root_dir)
开发者ID:ejconlon,项目名称:pants,代码行数:32,代码来源:source_root.py

示例2: _create_doc_target

# 需要导入模块: from twitter.common.collections import OrderedSet [as 别名]
# 或者: from twitter.common.collections.OrderedSet import add [as 别名]
  def _create_doc_target(self):
    all_sources = []
    all_deps = OrderedSet()
    for target in self.targets:
      if not self.only_provides or is_exported(target):
        for source in target.sources:
          source_path = os.path.join(self.java_src_prefix, source)
          if os.path.exists(source_path):
            all_sources.append(source_path)
          else:
            print "skipping %s" % source_path

          for jar_dep in target.jar_dependencies:
            if jar_dep.rev:
              all_deps.add(copy(jar_dep).intransitive())

    def create_meta_target():
      return JavaLibrary('pants.doc.deps',
                         all_sources,
                         provides = None,
                         dependencies = all_deps,
                         excludes = None,
                         resources = None,
                         binary_resources = None,
                         deployjar = False,
                         buildflags = None,
                         is_meta = True)

    # TODO(John Sirois): Find a better way to do_in_context when we don't care about the context
    return list(self.targets)[0].do_in_context(create_meta_target)
开发者ID:DikangGu,项目名称:commons,代码行数:32,代码来源:doc.py

示例3: _compute_sources

# 需要导入模块: from twitter.common.collections import OrderedSet [as 别名]
# 或者: from twitter.common.collections.OrderedSet import add [as 别名]
  def _compute_sources(self, target):
    relative_sources = OrderedSet()
    source_roots = OrderedSet()

    def capture_and_relativize_to_source_root(source):
      source_root = self.context.source_roots.find_by_path(source)
      if not source_root:
        source_root = self.context.source_roots.find(target)
      source_roots.add(source_root.path)
      return fast_relpath(source, source_root.path)

    if target.payload.get_field_value('ordered_sources'):
      # Re-match the filespecs against the sources in order to apply them in the literal order
      # they were specified in.
      filespec = target.globs_relative_to_buildroot()
      excludes = filespec.get('excludes', [])
      for filespec in filespec.get('globs', []):
        sources = [s for s in target.sources_relative_to_buildroot()
                   if globs_matches([s], [filespec], excludes)]
        if len(sources) != 1:
          raise TargetDefinitionException(
              target,
              'With `ordered_sources=True`, expected one match for each file literal, '
              'but got: {} for literal `{}`.'.format(sources, filespec)
            )
        relative_sources.add(capture_and_relativize_to_source_root(sources[0]))
    else:
      # Otherwise, use the default (unspecified) snapshot ordering.
      for source in target.sources_relative_to_buildroot():
        relative_sources.add(capture_and_relativize_to_source_root(source))
    return relative_sources, source_roots
开发者ID:cosmicexplorer,项目名称:pants,代码行数:33,代码来源:wire_gen.py

示例4: get_resolved_jars_for_jar_library

# 需要导入模块: from twitter.common.collections import OrderedSet [as 别名]
# 或者: from twitter.common.collections.OrderedSet import add [as 别名]
  def get_resolved_jars_for_jar_library(self, jar_library, memo=None):
    """Collects jars for the passed jar_library.

    Because artifacts are only fetched for the "winning" version of a module, the artifacts
    will not always represent the version originally declared by the library.

    This method is transitive within the library's jar_dependencies, but will NOT
    walk into its non-jar dependencies.

    :param jar_library A JarLibrary to collect the transitive artifacts for.
    :param memo see `traverse_dependency_graph`
    :returns: all the artifacts for all of the jars in this library, including transitive deps
    :rtype: list of str
    """
    def to_resolved_jar(jar_module_ref, artifact_path):
      return ResolvedJar(coordinate=M2Coordinate(org=jar_module_ref.org, name=jar_module_ref.name,
                                                 rev=jar_module_ref.rev,
                                                 classifier=jar_module_ref.classifier),
                         cache_path=artifact_path
      )
    resolved_jars = OrderedSet()
    def create_collection(dep):
      return OrderedSet([dep])
    for jar in jar_library.jar_dependencies:
      for classifier in jar.artifact_classifiers:
        jar_module_ref = IvyModuleRef(jar.org, jar.name, jar.rev, classifier)
        for module_ref in self.traverse_dependency_graph(jar_module_ref, create_collection, memo):
          for artifact_path in self._artifacts_by_ref[module_ref.unversioned]:
            resolved_jars.add(to_resolved_jar(jar_module_ref, artifact_path))
    return resolved_jars
开发者ID:Gabriel439,项目名称:pants,代码行数:32,代码来源:ivy_utils.py

示例5: bundle

# 需要导入模块: from twitter.common.collections import OrderedSet [as 别名]
# 或者: from twitter.common.collections.OrderedSet import add [as 别名]
  def bundle(self, app):
    """Create a self-contained application bundle.

    The bundle will contain the target classes, dependencies and resources.
    """
    assert(isinstance(app, BundleCreate.App))

    def verbose_symlink(src, dst):
      try:
        os.symlink(src, dst)
      except OSError as e:
        self.context.log.error("Unable to create symlink: {0} -> {1}".format(src, dst))
        raise e

    bundle_dir = os.path.join(self._outdir, '%s-bundle' % app.basename)
    self.context.log.info('creating %s' % os.path.relpath(bundle_dir, get_buildroot()))

    safe_mkdir(bundle_dir, clean=True)

    classpath = OrderedSet()
    # If creating a deployjar, we add the external dependencies to the bundle as
    # loose classes, and have no classpath. Otherwise we add the external dependencies
    # to the bundle as jars in a libs directory.
    if not self._create_deployjar:
      lib_dir = os.path.join(bundle_dir, 'libs')
      os.mkdir(lib_dir)

      jarmap = self.context.products.get('jars')

      def add_jars(target):
        generated = jarmap.get(target)
        if generated:
          for base_dir, internal_jars in generated.items():
            for internal_jar in internal_jars:
              verbose_symlink(os.path.join(base_dir, internal_jar), os.path.join(lib_dir, internal_jar))
              classpath.add(internal_jar)

      app.binary.walk(add_jars, lambda t: t != app.binary)

      # Add external dependencies to the bundle.
      for basedir, external_jar in self.list_external_jar_dependencies(app.binary):
        path = os.path.join(basedir, external_jar)
        verbose_symlink(path, os.path.join(lib_dir, external_jar))
        classpath.add(external_jar)

    bundle_jar = os.path.join(bundle_dir, '%s.jar' % app.binary.basename)

    with self.monolithic_jar(app.binary, bundle_jar,
                             with_external_deps=self._create_deployjar) as jar:
      self.add_main_manifest_entry(jar, app.binary)
      if classpath:
        jar.classpath([os.path.join('libs', jar) for jar in classpath])

    for bundle in app.bundles:
      for path, relpath in bundle.filemap.items():
        bundle_path = os.path.join(bundle_dir, relpath)
        safe_mkdir(os.path.dirname(bundle_path))
        verbose_symlink(path, bundle_path)

    return bundle_dir
开发者ID:digideskio,项目名称:pants,代码行数:62,代码来源:bundle_create.py

示例6: parse_args

# 需要导入模块: from twitter.common.collections import OrderedSet [as 别名]
# 或者: from twitter.common.collections.OrderedSet import add [as 别名]
  def parse_args(args):
    goals = OrderedSet()
    specs = OrderedSet()
    help = False
    explicit_multi = False

    def is_spec(spec):
      return os.sep in spec or ':' in spec

    for i, arg in enumerate(args):
      help = help or 'help' == arg
      if not arg.startswith('-'):
        specs.add(arg) if is_spec(arg) else goals.add(arg)
      elif '--' == arg:
        if specs:
          raise GoalError('Cannot intermix targets with goals when using --. Targets should '
                          'appear on the right')
        explicit_multi = True
        del args[i]
        break

    if explicit_multi:
      spec_offset = len(goals) + 1 if help else len(goals)
      specs.update(arg for arg in args[spec_offset:] if not arg.startswith('-'))

    return goals, specs
开发者ID:soheilhy,项目名称:commons,代码行数:28,代码来源:goal.py

示例7: _format_args_for_target

# 需要导入模块: from twitter.common.collections import OrderedSet [as 别名]
# 或者: from twitter.common.collections.OrderedSet import add [as 别名]
  def _format_args_for_target(self, target, target_workdir):
    """Calculate the arguments to pass to the command line for a single target."""

    relative_proto_files = OrderedSet()
    if target.payload.proto_files:
      relative_proto_files.update(target.payload.proto_files)
    else:
      sources = OrderedSet(target.sources_relative_to_buildroot())
      if not self.validate_sources_present(sources, [target]):
        return None
      # Compute the source path relative to the 'source root' which is the path used at the
      # root of imports
      for source in sources:
        source_root = self.context.source_roots.find_by_path(source).path
        relative_proto_files.add(os.path.relpath(source, source_root))

    args = ['--generated-source-directory', target_workdir]

    for root in target.payload.roots:
      args.extend(['--root', root])

    for path in self._calculate_proto_paths(target):
      # NB(gmalmquist): This isn't a typo. The --source argument is actually a proto path.
      args.extend(['--source', path])

    for source in relative_proto_files:
      args.extend(['--proto', source])

    return args
开发者ID:ericzundel,项目名称:mvn2pants,代码行数:31,代码来源:sake_wire_codegen.py

示例8: RootedProducts

# 需要导入模块: from twitter.common.collections import OrderedSet [as 别名]
# 或者: from twitter.common.collections.OrderedSet import add [as 别名]
class RootedProducts(object):
  """File products of a build that have a concept of a 'root' directory.

  E.g., classfiles, under a root package directory."""
  def __init__(self, root):
    self._root = root
    self._rel_paths = OrderedSet()

  def add_abs_paths(self, abs_paths):
    for abs_path in abs_paths:
      if not abs_path.startswith(self._root):
        raise Exception('{} is not under {}'.format(abs_path, self._root))
      self._rel_paths.add(os.path.relpath(abs_path, self._root))

  def add_rel_paths(self, rel_paths):
    self._rel_paths.update(rel_paths)

  def root(self):
    return self._root

  def rel_paths(self):
    return self._rel_paths

  def abs_paths(self):
    for relpath in self._rel_paths:
      yield os.path.join(self._root, relpath)

  def __bool__(self):
    return self._rel_paths

  __nonzero__ = __bool__
开发者ID:MathewJennings,项目名称:pants,代码行数:33,代码来源:products.py

示例9: transitive_subgraph_of_addresses_bfs

# 需要导入模块: from twitter.common.collections import OrderedSet [as 别名]
# 或者: from twitter.common.collections.OrderedSet import add [as 别名]
    def transitive_subgraph_of_addresses_bfs(self, addresses, predicate=None, leveled_predicate=None):
        """Returns the transitive dependency closure of `addresses` using BFS.

    :API: public

    :param list<Address> addresses: The closure of `addresses` will be walked.
    :param function predicate: If this parameter is not given, no Targets will be filtered
      out of the closure.  If it is given, any Target which fails the predicate will not be
      walked, nor will its dependencies.  Thus predicate effectively trims out any subgraph
      that would only be reachable through Targets that fail the predicate.
    :param function leveled_predicate: Behaves identically to predicate, but takes the depth of the
      target in the search tree as a second parameter, and it is checked just before a dependency is
      expanded.
    """
        ordered_closure = OrderedSet()
        # Use the DepthAgnosticWalk if we can, because DepthAwareWalk does a bit of extra work that can
        # slow things down by few millis.
        walker = self.DepthAwareWalk if leveled_predicate else self.DepthAgnosticWalk
        walk = walker()
        to_walk = deque((0, addr) for addr in addresses)
        while len(to_walk) > 0:
            level, address = to_walk.popleft()
            target = self._target_by_address[address]
            if not walk.expand_once(target, level):
                continue
            if predicate and not predicate(target):
                continue
            if walk.do_work_once(target):
                ordered_closure.add(target)
            for addr in self._target_dependencies_by_address[address]:
                if not leveled_predicate or leveled_predicate(self._target_by_address[addr], level):
                    to_walk.append((level + 1, addr))
        return ordered_closure
开发者ID:ttim,项目名称:pants,代码行数:35,代码来源:build_graph.py

示例10: parse_addresses

# 需要导入模块: from twitter.common.collections import OrderedSet [as 别名]
# 或者: from twitter.common.collections.OrderedSet import add [as 别名]
  def parse_addresses(self, specs, fail_fast=False):
    """Process a list of command line specs and perform expansion.  This method can expand a list
    of command line specs.
    :param list specs: either a single spec string or a list of spec strings.
    :return: a generator of specs parsed into addresses.
    :raises: CmdLineSpecParser.BadSpecError if any of the address selectors could not be parsed.
    """
    specs = maybe_list(specs)

    addresses = OrderedSet()
    for spec in specs:
      for address in self._parse_spec(spec, fail_fast):
        addresses.add(address)

    results = filter(self._not_excluded_address, addresses)

    # Print debug information about the excluded targets
    if logger.getEffectiveLevel() <= logging.DEBUG and self._exclude_patterns:
      logger.debug('excludes:\n  {excludes}'
                   .format(excludes='\n  '.join(self._exclude_target_regexps)))
      targets = ', '.join(self._excluded_target_map[CmdLineSpecParser._UNMATCHED_KEY])
      logger.debug('Targets after excludes: {targets}'.format(targets=targets))
      excluded_count = 0
      for pattern, targets in six.iteritems(self._excluded_target_map):
        if pattern != CmdLineSpecParser._UNMATCHED_KEY:
          logger.debug('Targets excluded by pattern {pattern}\n  {targets}'
                       .format(pattern=pattern,
                               targets='\n  '.join(targets)))
          excluded_count += len(targets)
      logger.debug('Excluded {count} target{plural}.'
                   .format(count=excluded_count,
                           plural=('s' if excluded_count != 1 else '')))
    return results
开发者ID:dturner-tw,项目名称:pants,代码行数:35,代码来源:cmd_line_spec_parser.py

示例11: get_resolved_jars_for_coordinates

# 需要导入模块: from twitter.common.collections import OrderedSet [as 别名]
# 或者: from twitter.common.collections.OrderedSet import add [as 别名]
  def get_resolved_jars_for_coordinates(self, coordinates, memo=None):
    """Collects jars for the passed coordinates.

    Because artifacts are only fetched for the "winning" version of a module, the artifacts
    will not always represent the version originally declared by the library.

    This method is transitive within the passed coordinates dependencies.

    :param coordinates collections.Iterable: Collection of coordinates to collect transitive
                                             resolved jars for.
    :param memo: See `traverse_dependency_graph`.
    :returns: All the artifacts for all of the jars for the provided coordinates,
              including transitive dependencies.
    :rtype: list of :class:`pants.backend.jvm.jar_dependency_utils.ResolvedJar`
    """
    def to_resolved_jar(jar_ref, jar_path):
      return ResolvedJar(coordinate=M2Coordinate(org=jar_ref.org,
                                                 name=jar_ref.name,
                                                 rev=jar_ref.rev,
                                                 classifier=jar_ref.classifier,
                                                 ext=jar_ref.ext),
                         cache_path=jar_path)
    resolved_jars = OrderedSet()
    def create_collection(dep):
      return OrderedSet([dep])
    for jar in coordinates:
      classifier = jar.classifier if self._conf == 'default' else self._conf
      jar_module_ref = IvyModuleRef(jar.org, jar.name, jar.rev, classifier)
      for module_ref in self.traverse_dependency_graph(jar_module_ref, create_collection, memo):
        for artifact_path in self._artifacts_by_ref[module_ref.unversioned]:
          resolved_jars.add(to_resolved_jar(module_ref, artifact_path))
    return resolved_jars
开发者ID:ahamilton55,项目名称:pants,代码行数:34,代码来源:ivy_utils.py

示例12: dump_requirements

# 需要导入模块: from twitter.common.collections import OrderedSet [as 别名]
# 或者: from twitter.common.collections.OrderedSet import add [as 别名]
def dump_requirements(builder, interpreter, reqs, log, platforms=None):
  """Multi-platform dependency resolution for PEX files.

  :param builder: Dump the requirements into this builder.
  :param interpreter: The :class:`PythonInterpreter` to resolve requirements for.
  :param reqs: A list of :class:`PythonRequirement` to resolve.
  :param log: Use this logger.
  :param platforms: A list of :class:`Platform`s to resolve requirements for.
                    Defaults to the platforms specified by PythonSetup.
  """
  deduped_reqs = OrderedSet(reqs)
  find_links = OrderedSet()
  blacklist = PythonSetup.global_instance().resolver_blacklist
  for req in deduped_reqs:
    log.debug('  Dumping requirement: {}'.format(req))
    if not (req.key in blacklist and interpreter.identity.matches(blacklist[req.key])):
      builder.add_requirement(req.requirement)
    if req.repository:
      find_links.add(req.repository)

  # Resolve the requirements into distributions.
  distributions = _resolve_multi(interpreter, deduped_reqs, platforms, find_links)
  locations = set()
  for platform, dists in distributions.items():
    for dist in dists:
      if dist.location not in locations:
        log.debug('  Dumping distribution: .../{}'.format(os.path.basename(dist.location)))
        builder.add_distribution(dist)
      locations.add(dist.location)
开发者ID:traviscrawford,项目名称:pants,代码行数:31,代码来源:pex_build_util.py

示例13: _resolve_overrides

# 需要导入模块: from twitter.common.collections import OrderedSet [as 别名]
# 或者: from twitter.common.collections.OrderedSet import add [as 别名]
  def _resolve_overrides(self):
    """
    Resolves override targets, and then excludes and re-includes each of them
    to create and return a new dependency set.
    """
    if not self.override_targets:
      return self._pre_override_dependencies

    result = OrderedSet()

    # resolve overrides and fetch all of their "artifact-providing" dependencies
    excludes = set()
    for override_target in self.override_targets:
      # add pre_override deps of the target as exclusions
      for resolved in override_target.resolve():
        excludes.update(self._excludes(resolved))
      # prepend the target as a new target
      result.add(override_target)

    # add excludes for each artifact
    for direct_dep in self._pre_override_dependencies:
      # add relevant excludes to jar dependencies
      for jar_dep in self._jar_dependencies(direct_dep):
        for exclude in excludes:
          jar_dep.exclude(exclude.org, exclude.name)
      result.add(direct_dep)

    return result
开发者ID:FernandoG26,项目名称:commons,代码行数:30,代码来源:jar_library.py

示例14: targets

# 需要导入模块: from twitter.common.collections import OrderedSet [as 别名]
# 或者: from twitter.common.collections.OrderedSet import add [as 别名]
  def targets(self, predicate=None, postorder=False):
    """Selects targets in-play in this run from the target roots and their transitive dependencies.

    Also includes any new synthetic targets created from the target roots or their transitive
    dependencies during the course of the run.

    :API: public

    :param predicate: If specified, the predicate will be used to narrow the scope of targets
                      returned.
    :param bool postorder: `True` to gather transitive dependencies with a postorder traversal;
                          `False` or preorder by default.
    :returns: A list of matching targets.
    """
    target_set = self._collect_targets(self.target_roots, postorder=postorder)

    synthetics = OrderedSet()
    for synthetic_address in self.build_graph.synthetic_addresses:
      if self.build_graph.get_concrete_derived_from(synthetic_address) in target_set:
        synthetics.add(self.build_graph.get_target(synthetic_address))

    synthetic_set = self._collect_targets(synthetics, postorder=postorder)

    target_set.update(synthetic_set)

    return filter(predicate, target_set)
开发者ID:lost-a-tooth,项目名称:pants,代码行数:28,代码来源:context.py

示例15: _create_java_target

# 需要导入模块: from twitter.common.collections import OrderedSet [as 别名]
# 或者: from twitter.common.collections.OrderedSet import add [as 别名]
 def _create_java_target(self, target, dependees):
   genfiles = []
   for source in target.sources_relative_to_source_root():
     path = os.path.join(target.target_base, source)
     genfiles.extend(self.calculate_genfiles(path, source).get('java', []))
   spec_path = os.path.relpath(self.java_out, get_buildroot())
   address = SyntheticAddress(spec_path, target.id)
   deps = OrderedSet(self.javadeps)
   import_jars = target.imported_jars
   jars_tgt = self.context.add_new_target(SyntheticAddress(spec_path, target.id+str('-rjars')),
                                          JarLibrary,
                                          jars=import_jars,
                                          derived_from=target)
   # Add in the 'spec-rjars' target, which contains all the JarDependency targets passed in via the
   # imports parameter. Each of these jars is expected to contain .proto files bundled together
   # with their .class files.
   deps.add(jars_tgt)
   tgt = self.context.add_new_target(address,
                                     JavaLibrary,
                                     derived_from=target,
                                     sources=genfiles,
                                     provides=target.provides,
                                     dependencies=deps,
                                     excludes=target.payload.get_field_value('excludes'))
   for dependee in dependees:
     dependee.inject_dependency(tgt.address)
   return tgt
开发者ID:MathewJennings,项目名称:pants,代码行数:29,代码来源:protobuf_gen.py


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