本文整理汇总了Python中b2.util.sequence.unique函数的典型用法代码示例。如果您正苦于以下问题:Python unique函数的具体用法?Python unique怎么用?Python unique使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了unique函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: register
def register (g):
""" Registers new generator instance 'g'.
"""
id = g.id ()
__generators [id] = g
# A generator can produce several targets of the
# same type. We want unique occurence of that generator
# in .generators.$(t) in that case, otherwise, it will
# be tried twice and we'll get false ambiguity.
for t in sequence.unique(g.target_types()):
__type_to_generators.setdefault(t, []).append(g)
# Update the set of generators for toolset
# TODO: should we check that generator with this id
# is not already registered. For example, the fop.jam
# module intentionally declared two generators with the
# same id, so such check will break it.
# Some generators have multiple periods in their name, so the
# normal $(id:S=) won't generate the right toolset name.
# e.g. if id = gcc.compile.c++, then
# .generators-for-toolset.$(id:S=) will append to
# .generators-for-toolset.gcc.compile, which is a separate
# value from .generators-for-toolset.gcc. Correcting this
# makes generator inheritance work properly.
# See also inherit-generators in module toolset
base = id.split ('.', 100) [0]
__generators_for_toolset.setdefault(base, []).append(g)
示例2: __handle_flag_value
def __handle_flag_value (manager, value, ps):
assert isinstance(value, basestring)
assert isinstance(ps, property_set.PropertySet)
result = []
if get_grist (value):
f = feature.get(value)
values = ps.get(f)
for value in values:
if f.dependency:
# the value of a dependency feature is a target
# and must be actualized
result.append(value.actualize())
elif f.path or f.free:
# Treat features with && in the value
# specially -- each &&-separated element is considered
# separate value. This is needed to handle searched
# libraries, which must be in specific order.
if not __re_two_ampersands.search(value):
result.append(value)
else:
result.extend(value.split ('&&'))
else:
result.append (value)
else:
result.append (value)
return sequence.unique(result, stable=True)
示例3: __init__
def __init__ (self, main_target, prop_set, sources, build_properties, sources_usage_requirements, created_targets):
"""
main_target: The instance of MainTarget class
prop_set: Properties requested for this target
sources:
build_properties: Actually used properties
sources_usage_requirements: Properties propagated from sources
created_targets: Top-level created targets
"""
self.main_target_ = main_target
self.properties_ = prop_set
self.sources_ = sources
self.build_properties_ = build_properties
self.sources_usage_requirements_ = sources_usage_requirements
self.created_targets_ = created_targets
self.usage_requirements_ = None
# Pre-compose the list of other dependency graphs, on which this one
# depends
deps = build_properties.get('<implicit-dependency>')
self.other_dg_ = []
for d in deps:
self.other_dg_.append(d.creating_subvariant ())
self.other_dg_ = unique (self.other_dg_)
self.implicit_includes_cache_ = {}
self.target_directories_ = None
示例4: refine
def refine(properties, requirements):
""" Refines 'properties' by overriding any non-free properties
for which a different value is specified in 'requirements'.
Conditional requirements are just added without modification.
Returns the resulting list of properties.
"""
# The result has no duplicates, so we store it in a set
result = set()
# Records all requirements.
required = {}
# All the elements of requirements should be present in the result
# Record them so that we can handle 'properties'.
for r in requirements:
# Don't consider conditional requirements.
if not r.condition():
required[r.feature()] = r
for p in properties:
# Skip conditional properties
if p.condition():
result.add(p)
# No processing for free properties
elif p.feature().free():
result.add(p)
else:
if required.has_key(p.feature()):
result.add(required[p.feature()])
else:
result.add(p)
return sequence.unique(list(result) + requirements)
示例5: convert_multiple_sources_to_consumable_types
def convert_multiple_sources_to_consumable_types (self, project, prop_set, sources):
""" Converts several files to consumable types.
"""
if __debug__:
from .targets import ProjectTarget
assert isinstance(project, ProjectTarget)
assert isinstance(prop_set, property_set.PropertySet)
assert is_iterable_typed(sources, virtual_target.VirtualTarget)
if not self.source_types_:
return list(sources)
acceptable_types = set()
for t in self.source_types_:
acceptable_types.update(type.all_derived(t))
result = []
for source in sources:
if source.type() not in acceptable_types:
transformed = construct_types(
project, None,self.source_types_, prop_set, [source])
# construct_types returns [prop_set, [targets]]
for t in transformed[1]:
if t.type() in self.source_types_:
result.append(t)
if not transformed:
project.manager().logger().log(__name__, " failed to convert ", source)
else:
result.append(source)
result = sequence.unique(result, stable=True)
return result
示例6: all_referenced_targets
def all_referenced_targets(self, result):
"""Returns all targets referenced by this subvariant,
either directly or indirectly, and either as sources,
or as dependency properties. Targets referred with
dependency property are returned a properties, not targets."""
# Find directly referenced targets.
deps = self.build_properties().dependency()
all_targets = self.sources_ + deps
# Find other subvariants.
r = []
for e in all_targets:
if not e in result:
result.add(e)
if isinstance(e, property.Property):
t = e.value()
else:
t = e
# FIXME: how can this be?
cs = t.creating_subvariant()
if cs:
r.append(cs)
r = unique(r)
for s in r:
if s != self:
s.all_referenced_targets(result)
示例7: viable_source_types_for_generator_real
def viable_source_types_for_generator_real (generator):
""" Returns the list of source types, which, when passed to 'run'
method of 'generator', has some change of being eventually used
(probably after conversion by other generators)
"""
source_types = generator.source_types ()
if not source_types:
# If generator does not specify any source types,
# it might be special generator like builtin.lib-generator
# which just relays to other generators. Return '*' to
# indicate that any source type is possibly OK, since we don't
# know for sure.
return ['*']
else:
result = []
for s in source_types:
viable_sources = viable_source_types(s)
if viable_sources == "*":
result = ["*"]
break
else:
result.extend(type.all_derived(s) + viable_sources)
return unique(result)
示例8: convert_to_consumable_types
def convert_to_consumable_types (self, project, name, prop_set, sources, only_one=False):
""" Attempts to convert 'source' to the types that this generator can
handle. The intention is to produce the set of targets can should be
used when generator is run.
only_one: convert 'source' to only one of source types
if there's more that one possibility, report an
error.
Returns a pair:
consumed: all targets that can be consumed.
"""
if __debug__:
from .targets import ProjectTarget
assert isinstance(name, basestring) or name is None
assert isinstance(project, ProjectTarget)
assert isinstance(prop_set, property_set.PropertySet)
assert is_iterable_typed(sources, virtual_target.VirtualTarget)
assert isinstance(only_one, bool)
consumed = []
missing_types = []
if len (sources) > 1:
# Don't know how to handle several sources yet. Just try
# to pass the request to other generator
missing_types = self.source_types_
else:
(c, m) = self.consume_directly (sources [0])
consumed += c
missing_types += m
# No need to search for transformation if
# some source type has consumed source and
# no more source types are needed.
if only_one and consumed:
missing_types = []
#TODO: we should check that only one source type
#if create of 'only_one' is true.
# TODO: consider if consuned/bypassed separation should
# be done by 'construct_types'.
if missing_types:
transformed = construct_types (project, name, missing_types, prop_set, sources)
# Add targets of right type to 'consumed'. Add others to
# 'bypassed'. The 'generators.construct' rule has done
# its best to convert everything to the required type.
# There's no need to rerun it on targets of different types.
# NOTE: ignoring usage requirements
for t in transformed[1]:
if t.type() in missing_types:
consumed.append(t)
consumed = unique(consumed)
return consumed
示例9: collect_targets
def collect_targets(self, targets):
s = [t.creating_subvariant() for t in targets]
s = unique(s)
result = set(targets)
for i in s:
i.all_referenced_targets(result)
result2 = []
for r in result:
if isinstance(r, property.Property):
if r.feature().name() != "use":
result2.append(r.value())
else:
result2.append(r)
result2 = unique(result2)
return result2
示例10: compute_target_directories
def compute_target_directories(self, target_type=None):
result = []
for t in self.created_targets():
if not target_type or b2.build.type.is_derived(t.type(), target_type):
result.append(t.path())
for d in self.other_dg_:
result.extend(d.all_target_directories(target_type))
result = unique(result)
return result
示例11: build_multiple
def build_multiple(self, property_sets):
usage_requirements = property_set.empty()
result = []
for p in property_sets:
r = AliasTarget.generate(self, p)
if r:
usage_requirements = usage_requirements.add(r.usage_requirements())
result.extend(r.targets())
return targets.GenerateResult(usage_requirements, unique(result))
示例12: create
def create (raw_properties = []):
""" Creates a new 'PropertySet' instance for the given raw properties,
or returns an already existing one.
"""
raw_properties.sort ()
raw_properties = unique (raw_properties)
key = '-'.join (raw_properties)
if not __cache.has_key (key):
__cache [key] = PropertySet (raw_properties)
return __cache [key]
示例13: register
def register (g):
""" Registers new generator instance 'g'.
"""
assert isinstance(g, Generator)
id = g.id()
__generators [id] = g
# A generator can produce several targets of the
# same type. We want unique occurence of that generator
# in .generators.$(t) in that case, otherwise, it will
# be tried twice and we'll get false ambiguity.
for t in sequence.unique(g.target_types()):
__type_to_generators.setdefault(t, []).append(g)
# Update the set of generators for toolset
# TODO: should we check that generator with this id
# is not already registered. For example, the fop.jam
# module intentionally declared two generators with the
# same id, so such check will break it.
# Some generators have multiple periods in their name, so the
# normal $(id:S=) won't generate the right toolset name.
# e.g. if id = gcc.compile.c++, then
# .generators-for-toolset.$(id:S=) will append to
# .generators-for-toolset.gcc.compile, which is a separate
# value from .generators-for-toolset.gcc. Correcting this
# makes generator inheritance work properly.
# See also inherit-generators in module toolset
base = id.split ('.', 100) [0]
__generators_for_toolset.setdefault(base, []).append(g)
# After adding a new generator that can construct new target types, we need
# to clear the related cached viable source target type information for
# constructing a specific target type or using a specific generator. Cached
# viable source target type lists affected by this are those containing any
# of the target types constructed by the new generator or any of their base
# target types.
#
# A more advanced alternative to clearing that cached viable source target
# type information would be to expand it with additional source types or
# even better - mark it as needing to be expanded on next use.
#
# For now we just clear all the cached viable source target type information
# that does not simply state 'all types' and may implement a more detailed
# algorithm later on if it becomes needed.
invalidate_extendable_viable_source_target_type_cache()
示例14: run_path_setup
def run_path_setup(target, sources, ps):
# For testing, we need to make sure that all dynamic libraries needed by the
# test are found. So, we collect all paths from dependency libraries (via
# xdll-path property) and add whatever explicit dll-path user has specified.
# The resulting paths are added to the environment on each test invocation.
dll_paths = ps.get('dll-path')
dll_paths.extend(ps.get('xdll-path'))
dll_paths.extend(bjam.call("get-target-variable", sources, "RUN_PATH"))
dll_paths = unique(dll_paths)
if dll_paths:
bjam.call("set-target-variable", target, "PATH_SETUP",
common.prepend_path_variable_command(
common.shared_library_path_variable(), dll_paths))
示例15: set_library_order
def set_library_order (manager, sources, prop_set, result):
used_libraries = []
deps = prop_set.dependency ()
sources.extend(d.value() for d in deps)
sources = sequence.unique(sources)
for l in sources:
if l.type () and type.is_derived (l.type (), 'LIB'):
used_libraries.append (l)
created_libraries = []
for l in result:
if l.type () and type.is_derived (l.type (), 'LIB'):
created_libraries.append (l)
created_libraries = set.difference (created_libraries, used_libraries)
set_library_order_aux (created_libraries, used_libraries)