def path_order(x, y): """ Helper for as_path, below. Orders properties with the implicit ones first, and within the two sections in alphabetical order of feature name. """ if x == y: return 0 xg = get_grist(x) yg = get_grist(y) if yg and not xg: return -1 elif xg and not yg: return 1 else: if not xg: x = feature.expand_subfeatures([x]) y = feature.expand_subfeatures([y]) if x < y: return -1 elif x > y: return 1 else: return 0
def path_order(x, y): """ Helper for as_path, below. Orders properties with the implicit ones first, and within the two sections in alphabetical order of feature name. """ if x == y: return 0 xg = get_grist(x) yg = get_grist(y) if yg and not xg: return -1 elif xg and not yg: return 1 else: if not xg: x = feature.expand_subfeatures([x]) y = feature.expand_subfeatures([y]) if x < y: return -1 elif x > y: return 1 else: return 0
def expand_subfeatures_in_conditions (properties): assert is_iterable_typed(properties, Property) result = [] for p in properties: if not p.condition: result.append(p) else: expanded = [] for c in p.condition: # It common that condition includes a toolset which # was never defined, or mentiones subfeatures which # were never defined. In that case, validation will # only produce an spirious error, so don't validate. expanded.extend(feature.expand_subfeatures ([c], True)) # we need to keep LazyProperties lazy if isinstance(p, LazyProperty): value = p.value feature_name = get_grist(value) value = value.replace(feature_name, '') result.append(LazyProperty(feature_name, value, condition=expanded)) else: result.append(Property(p.feature, p.value, expanded)) return result
def expand_subfeatures_in_conditions(properties): assert is_iterable_typed(properties, Property) result = [] for p in properties: if not p.condition: result.append(p) else: expanded = [] for c in p.condition: # It common that condition includes a toolset which # was never defined, or mentiones subfeatures which # were never defined. In that case, validation will # only produce an spirious error, so don't validate. expanded.extend(feature.expand_subfeatures([c], True)) # we need to keep LazyProperties lazy if isinstance(p, LazyProperty): value = p.value feature_name = get_grist(value) value = value.replace(feature_name, '') result.append( LazyProperty(feature_name, value, condition=expanded)) else: result.append(Property(p.feature, p.value, expanded)) return result
def expand_subfeatures_in_conditions(properties): result = [] for p in properties: s = __re_separate_condition_and_property.match(p) if not s: result.append(p) else: condition = s.group(1) # Condition might include several elements condition = condition.split(",") value = s.group(2) e = [] for c in condition: # It common that condition includes a toolset which # was never defined, or mentiones subfeatures which # were never defined. In that case, validation will # only produce an spirious error, so prevent # validation by passing 'true' as second parameter. e.extend(feature.expand_subfeatures(c, dont_validate=True)) if e == condition: result.append(p) else: individual_subfeatures = set.difference(e, condition) result.append(",".join(individual_subfeatures) + ":" + value) return result
def expand_subfeatures_in_conditions (properties): result = [] for p in properties: s = __re_split_condition.match (p) if not s: result.append (p) else: condition = s.group (1) # Condition might include several elements condition = __re_comma.split (condition) value = s.group (2) e = [] for c in condition: cg = get_grist (c) if __re_toolset_feature.match (cg) or __re_os_feature.match (cg): # It common that condition includes a toolset which # was never defined, or mentiones subfeatures which # were never defined. In that case, validation will # only produce an spirious error, so don't validate. e.append (feature.expand_subfeatures (c, True)) else: e.append (feature.expand_subfeatures (c)) if e == condition: result.append (p) else: individual_subfeatures = Set.difference (e, condition) result.append (','.join (individual_subfeatures) + ':' + value) return result
def expand_subfeatures_in_conditions(properties): result = [] for p in properties: if not p.condition(): result.append(p) else: expanded = [] for c in p.condition(): if c.feature().name().startswith("toolset") or c.feature().name() == "os": # It common that condition includes a toolset which # was never defined, or mentiones subfeatures which # were never defined. In that case, validation will # only produce an spirious error, so don't validate. expanded.extend(feature.expand_subfeatures([c], True)) else: expanded.extend(feature.expand_subfeatures([c])) result.append(Property(p.feature(), p.value(), expanded)) return result
def expand_subfeatures_in_conditions (properties): result = [] for p in properties: if not p.condition(): result.append(p) else: expanded = [] for c in p.condition(): if c.feature().name().startswith("toolset") or c.feature().name() == "os": # It common that condition includes a toolset which # was never defined, or mentiones subfeatures which # were never defined. In that case, validation will # only produce an spirious error, so don't validate. expanded.extend(feature.expand_subfeatures ([c], True)) else: expanded.extend(feature.expand_subfeatures([c])) result.append(Property(p.feature(), p.value(), expanded)) return result
def expand_subfeatures(self): if not self.subfeatures_: self.subfeatures_ = create(feature.expand_subfeatures(self.all_)) return self.subfeatures_