示例#1
0
文件: graph.py 项目: dfabulich/pants
    def resolve_item(item, addr=None):
      if Serializable.is_serializable(item):
        hydrated_args = {'address': addr} if addr else {}

        # Recurse on the Serializable's values and hydrates any addressables found.  This unwinds
        # from the leaves thus hydrating item's closure in the inline case.
        for key, value in item._asdict().items():
          is_addressable = AddressableDescriptor.is_addressable(item, key)

          def maybe_addr(x):
            return parse_addr(x) if is_addressable and isinstance(x, six.string_types) else x

          if isinstance(value, collections.MutableMapping):
            container_type = type(value)
            container = container_type()
            container.update((k, resolve_item(maybe_addr(v))) for k, v in value.items())
            hydrated_args[key] = container
          elif isinstance(value, collections.MutableSequence):
            container_type = type(value)
            hydrated_args[key] = container_type(resolve_item(maybe_addr(v)) for v in value)
          else:
            hydrated_args[key] = resolve_item(maybe_addr(value))

        # Re-build the thin Serializable with either fully hydrated objects or Resolvables
        # substituted for all Address values; ie: Only ever expose fully resolved or resolvable
        # closures for requested addresses.
        return self._hydrate(type(item), **hydrated_args)
      elif isinstance(item, Address):
        if self._inline:
          return self._resolve_recursively(item, resolve_path)
        else:
          # TODO(John Sirois): Implement lazy cycle checks across Resolver chains.
          return Resolver(self, address=item)
      else:
        return item
示例#2
0
    def resolve_item(item, addr=None):
      if Serializable.is_serializable(item):
        hydrated_args = {'address': addr} if addr else {}

        # Recurse on the Serializable's values and hydrates any addressables found.  This unwinds
        # from the leaves thus hydrating item's closure in the inline case.
        for key, value in item._asdict().items():
          is_addressable = AddressableDescriptor.is_addressable(item, key)

          def maybe_addr(x):
            return parse_addr(x) if is_addressable and isinstance(x, six.string_types) else x

          if isinstance(value, collections.MutableMapping):
            container_type = type(value)
            container = container_type()
            container.update((k, resolve_item(maybe_addr(v))) for k, v in value.items())
            hydrated_args[key] = container
          elif isinstance(value, collections.MutableSequence):
            container_type = type(value)
            hydrated_args[key] = container_type(resolve_item(maybe_addr(v)) for v in value)
          else:
            hydrated_args[key] = resolve_item(maybe_addr(value))

        # Re-build the thin Serializable with either fully hydrated objects or Resolvables
        # substituted for all Address values; ie: Only ever expose fully resolved or resolvable
        # closures for requested addresses.
        return self._hydrate(type(item), **hydrated_args)
      elif isinstance(item, Address):
        if self._inline:
          return self._resolve_recursively(item, resolve_path)
        else:
          # TODO(John Sirois): Implement lazy cycle checks across Resolver chains.
          return Resolver(self, address=item)
      else:
        return item
示例#3
0
 def collect_dependencies(item):
   for key, value in sorted(item._asdict().items(), key=_key_func):
     if not AddressableDescriptor.is_addressable(item, key):
       continue
     if isinstance(value, collections.MutableMapping):
       for _, v in sorted(value.items(), key=_key_func):
         maybe_append(key, v)
     elif isinstance(value, collections.MutableSequence):
       for v in value:
         maybe_append(key, v)
     else:
       maybe_append(key, value)
示例#4
0
 def collect_dependencies(item):
     for key, value in sorted(item._asdict().items(), key=_key_func):
         if not AddressableDescriptor.is_addressable(item, key):
             continue
         if isinstance(value, collections.MutableMapping):
             for _, v in sorted(value.items(), key=_key_func):
                 maybe_append(key, v)
         elif isinstance(value, collections.MutableSequence):
             for v in value:
                 maybe_append(key, v)
         else:
             maybe_append(key, value)
示例#5
0
  def consume_dependencies(item, args=None):
    hydrated_args = args or {}
    for key, value in sorted(item._asdict().items(), key=_key_func):
      if not AddressableDescriptor.is_addressable(item, key):
        hydrated_args[key] = value
        continue

      if isinstance(value, collections.MutableMapping):
        container_type = type(value)
        hydrated_args[key] = container_type((k, maybe_consume(key, v))
                                            for k, v in sorted(value.items(), key=_key_func))
      elif isinstance(value, collections.MutableSequence):
        container_type = type(value)
        hydrated_args[key] = container_type(maybe_consume(key, v) for v in value)
      else:
        hydrated_args[key] = maybe_consume(key, value)
    return _hydrate(type(item), address.spec_path, **hydrated_args)
示例#6
0
    def consume_dependencies(item, args=None):
        hydrated_args = args or {}
        for key, value in sorted(item._asdict().items(), key=_key_func):
            if not AddressableDescriptor.is_addressable(item, key):
                hydrated_args[key] = value
                continue

            if isinstance(value, collections.MutableMapping):
                container_type = type(value)
                hydrated_args[key] = container_type(
                    (k, maybe_consume(key, v))
                    for k, v in sorted(value.items(), key=_key_func))
            elif isinstance(value, collections.MutableSequence):
                container_type = type(value)
                hydrated_args[key] = container_type(
                    maybe_consume(key, v) for v in value)
            else:
                hydrated_args[key] = maybe_consume(key, value)
        return _hydrate(type(item), address.spec_path, **hydrated_args)