def sort_objects(schema, objects): from . import inheriting g = {} for obj in sorted(objects, key=lambda o: o.get_name(schema)): g[obj.get_name(schema)] = {'item': obj, 'merge': [], 'deps': []} if isinstance(obj, inheriting.InheritingObject): obj_bases = obj.get_bases(schema) else: obj_bases = None if obj_bases: g[obj.get_name(schema)]['deps'].extend( b.get_name(schema) for b in obj_bases.objects(schema)) for base in obj_bases.objects(schema): base_name = base.get_name(schema) if base_name.module != obj.get_name(schema).module: g[base_name] = {'item': base, 'merge': [], 'deps': []} if not g: return ordered.OrderedSet() item = next(iter(g.values()))['item'] modname = item.get_name(schema).module objs = topological.sort(g) return ordered.OrderedSet( filter( lambda obj: getattr(obj.get_name(schema), 'module', None) == modname, objs))
def copy(self): result = super().copy() result.ops = ordered.OrderedSet( op.copy() for op in self.ops) result.before_ops = ordered.OrderedSet( op.copy() for op in self.before_ops) return result
def _sort(self, objects, depsfn=None): g = {} for obj in objects: this_item = g[obj.name] = {'item': obj, 'merge': [], 'deps': []} if depsfn is not None: deps = depsfn(obj) for dep in deps: this_item['deps'].append(dep.name) g[dep.name] = {'item': dep, 'merge': [], 'deps': []} if obj.bases: g[obj.name]['deps'].extend(b.name for b in obj.bases) for base in obj.bases: if base.name.module != obj.name.module: g[base.name] = {'item': base, 'merge': [], 'deps': []} if not g: return ordered.OrderedSet() item = next(iter(g.values()))['item'] modname = item.name.module objs = topological.sort(g) return ordered.OrderedSet( filter(lambda obj: obj.name.module == modname, objs))
def sort_subcommands_by_type(self): def _key(c): if isinstance(c, CreateObject): return 0 else: return 2 self.ops = ordered.OrderedSet(sorted(self.ops, key=_key))
def iter_columns(self, writable_only=False, only_self=False): cols = collections.OrderedDict() cols.update((c.name, c) for c in self._columns if not writable_only or not c.readonly) if not only_self: for c in reversed(self.bases): cols.update((name, bc) for name, bc in c.columns.items() if not writable_only or not bc.readonly) return ordered.OrderedSet(cols.values())
def __init__(self, name, table_name, unique=True, expr=None, predicate=None, inherit=False, metadata=None, columns=None): super().__init__(inherit=inherit, metadata=metadata) assert table_name[1] != 'feature' self.name = name self.table_name = table_name self._columns = ordered.OrderedSet() if columns: self.add_columns(columns) self.predicate = predicate self.unique = unique self.expr = expr if self.name_in_catalog != self.name: self.add_metadata('fullname', self.name)
def __init__(self, name, columns=None): super().__init__() self.name = name self._columns = ordered.OrderedSet() self.add_columns(columns or [])
def __init__(self, **kwargs): super().__init__(**kwargs) self.ops = ordered.OrderedSet() self.before_ops = ordered.OrderedSet()
def __init__(self, deltas): self.deltas = ordered.OrderedSet(deltas)
def __init__(self, name, *, columns=None, bases=None, constraints=None): self.constraints = ordered.OrderedSet(constraints or []) self.bases = ordered.OrderedSet(bases or []) self.data = [] super().__init__(name, columns=columns)
def __init__(self, name, columns=()): super().__init__(name) self._columns = ordered.OrderedSet(columns)