Debian Codegraph @

gavo/rscdef/group.py

raw symbols SCIP
1 """
2 VOTable-style groups for RD tables.
3 """
4
5 #c Copyright 2008-2025, the GAVO project <[email protected]>
6 #c
7 #c This program is free software, covered by the GNU GPL. See the
8 #c COPYING file in the source distribution.
9
10
11 from gavoscip-python python gavodachs 2.13 gavo/__init__: import basescip-python python gavodachs 2.13 `gavo.base`/__init__:
12 from gavo.basescip-python python gavodachs 2.13 `gavo.base`/__init__: import attrdefscip-python python gavodachs 2.13 `gavo.base.attrdef`/__init__:
13 from gavo.rscdefscip-python python gavodachs 2.13 `gavo.rscdef`/__init__: import columnscip-python python gavodachs 2.13 `gavo.rscdef.column`/__init__:
14 from gavo.rscdefscip-python python gavodachs 2.13 `gavo.rscdef`/__init__: import commonscip-python python gavodachs 2.13 `gavo.rscdef.common`/__init__:
15
16
17 class TypedReferencescip-python python gavodachs 2.13 `gavo.rscdef.group`/TypedReference#(basescip-python python gavodachs 2.13 `gavo.base`/__init__:.Structurescip-python python gavodachs 2.13 `gavo.base.structure`/Structure#):
18 """A base class for references to columns and parameters.
19 """
20 _destscip-python python gavodachs 2.13 `gavo.rscdef.group`/TypedReference#_dest. = basescip-python python gavodachs 2.13 `gavo.base`/__init__:.UnicodeAttributescip-python python gavodachs 2.13 `gavo.base.attrdef`/UnicodeAttribute#("key",
21 default=basescip-python python gavodachs 2.13 `gavo.base`/__init__:.Undefinedscip-python python gavodachs 2.13 `gavo.base.attrdef`/UnicodeAttribute#,
22 description="The key (i.e., name) of the referenced column or param.",
23 copyable="True",
24 aliases=["dest"])
25
26 _ucdscip-python python gavodachs 2.13 `gavo.rscdef.group`/TypedReference#_ucd. = basescip-python python gavodachs 2.13 `gavo.base`/__init__:.UnicodeAttributescip-python python gavodachs 2.13 `gavo.base.attrdef`/UnicodeAttribute#("ucd",
27 default=None,
28 description="The UCD of the group",
29 copyable=True)
30
31 _utypescip-python python gavodachs 2.13 `gavo.rscdef.group`/TypedReference#_utype. = basescip-python python gavodachs 2.13 `gavo.base`/__init__:.UnicodeAttributescip-python python gavodachs 2.13 `gavo.base.attrdef`/UnicodeAttribute#("utype",
32 default=None,
33 description="A utype for the group",
34 copyable=True)
35
36 def resolvescip-python python gavodachs 2.13 `gavo.rscdef.group`/TypedReference#resolve().(selfscip-python python gavodachs 2.13 `gavo.rscdef.group`/TypedReference#resolve().(self), containerscip-python python gavodachs 2.13 `gavo.rscdef.group`/TypedReference#resolve().(container)):
37 """tries to resolve the reference within container.
38
39 This must be overridden by derived classes.
40 """
41 raise NotImplementedErrorscip-python python python-stdlib 3.11 builtins/NotImplementedError#("Don't now how to resolve %s references."%
42 selfscip-python python gavodachs 2.13 `gavo.rscdef.group`/TypedReference#resolve().(self).__class__scip-python python python-stdlib 3.11 builtins/object#__class__()..__name__scip-python python python-stdlib 3.11 builtins/__name__#)
43
44
45 class ColumnReferencescip-python python gavodachs 2.13 `gavo.rscdef.group`/ColumnReference#(TypedReferencescip-python python gavodachs 2.13 `gavo.rscdef.group`/TypedReference#):
46 """A reference from a group to a column within a table.
47
48 ColumnReferences do not support qualified references, i.e., you
49 can only give simple names.
50 """
51 name_scip-python python gavodachs 2.13 `gavo.rscdef.group`/ColumnReference#name_. = "columnRef"
52
53 def resolvescip-python python gavodachs 2.13 `gavo.rscdef.group`/ColumnReference#resolve().(selfscip-python python gavodachs 2.13 `gavo.rscdef.group`/ColumnReference#resolve().(self), containerscip-python python gavodachs 2.13 `gavo.rscdef.group`/ColumnReference#resolve().(container)):
54 return containerscip-python python gavodachs 2.13 `gavo.rscdef.group`/ColumnReference#resolve().(container).getColumnByName(selfscip-python python gavodachs 2.13 `gavo.rscdef.group`/ColumnReference#resolve().(self).key)
55
56
57 class ParameterReferencescip-python python gavodachs 2.13 `gavo.rscdef.group`/ParameterReference#(TypedReferencescip-python python gavodachs 2.13 `gavo.rscdef.group`/TypedReference#):
58 """A reference from a group to a parameter within a table.
59
60 ParamReferences do not support qualified references, i.e., you
61 can only give simple names.
62
63 Also note that programmatically, you usually want to resolve
64 ParamReferences within the Table instance, not the table definition.
65 """
66 name_scip-python python gavodachs 2.13 `gavo.rscdef.group`/ParameterReference#name_. = "paramRef"
67
68 def resolvescip-python python gavodachs 2.13 `gavo.rscdef.group`/ParameterReference#resolve().(selfscip-python python gavodachs 2.13 `gavo.rscdef.group`/ParameterReference#resolve().(self), containerscip-python python gavodachs 2.13 `gavo.rscdef.group`/ParameterReference#resolve().(container)):
69 return containerscip-python python gavodachs 2.13 `gavo.rscdef.group`/ParameterReference#resolve().(container).getParamByName(selfscip-python python gavodachs 2.13 `gavo.rscdef.group`/ParameterReference#resolve().(self).key)
70
71
72 class Groupscip-python python gavodachs 2.13 `gavo.rscdef.group`/Group#(basescip-python python gavodachs 2.13 `gavo.base`/__init__:.Structurescip-python python gavodachs 2.13 `gavo.base.structure`/Structure#):
73 """A group is a collection of columns, parameters and other groups
74 with a dash of metadata.
75
76 Within a group, you can refer to columns or params of the enclosing table
77 by their names. Nothing outside of the enclosing table can be
78 part of a group.
79
80 Rather than referring to params, you can also embed them into a group;
81 they will then *not* be present in the embedding table.
82
83 Groups may contain groups.
84
85 One application for this is grouping input keys for the form renderer.
86 For such groups, you probably want to give the label property (and
87 possibly cssClass).
88 """
89 name_scip-python python gavodachs 2.13 `gavo.rscdef.group`/Group#name_. = "group"
90
91 _namescip-python python gavodachs 2.13 `gavo.rscdef.group`/Group#_name. = columnscip-python python gavodachs 2.13 `gavo.rscdef.column`/__init__:.ParamNameAttributescip-python python gavodachs 2.13 `gavo.rscdef.column`/ParamNameAttribute#("name",
92 default=None,
93 description="Name of the column (must be SQL-valid for onDisk tables)",
94 copyable=True)
95
96 _ucdscip-python python gavodachs 2.13 `gavo.rscdef.group`/Group#_ucd. = basescip-python python gavodachs 2.13 `gavo.base`/__init__:.UnicodeAttributescip-python python gavodachs 2.13 `gavo.base.attrdef`/UnicodeAttribute#("ucd",
97 default=None,
98 description="The UCD of the group",
99 copyable=True)
100
101 _descriptionscip-python python gavodachs 2.13 `gavo.rscdef.group`/Group#_description. = basescip-python python gavodachs 2.13 `gavo.base`/__init__:.NWUnicodeAttributescip-python python gavodachs 2.13 `gavo.base.attrdef`/UnicodeAttribute#("description",
102 default=None,
103 copyable=True,
104 description="A short (one-line) description of the group")
105
106 _utypescip-python python gavodachs 2.13 `gavo.rscdef.group`/Group#_utype. = basescip-python python gavodachs 2.13 `gavo.base`/__init__:.UnicodeAttributescip-python python gavodachs 2.13 `gavo.base.attrdef`/UnicodeAttribute#("utype",
107 default=None,
108 description="A utype for the group",
109 copyable=True)
110
111 _columnRefsscip-python python gavodachs 2.13 `gavo.rscdef.group`/Group#_columnRefs. = basescip-python python gavodachs 2.13 `gavo.base`/__init__:.StructListAttributescip-python python gavodachs 2.13 `gavo.base.complexattrs`/StructListAttribute#("columnRefs",
112 descriptionscip-python python gavodachs 2.13 `gavo.base.complexattrs`/StructListAttribute#__init__().(description)="References to table columns belonging to this group",
113 childFactoryscip-python python gavodachs 2.13 `gavo.base.complexattrs`/StructListAttribute#__init__().(childFactory)=ColumnReferencescip-python python gavodachs 2.13 `gavo.rscdef.group`/ColumnReference#,
114 copyable=True)
115
116 _paramRefsscip-python python gavodachs 2.13 `gavo.rscdef.group`/Group#_paramRefs. = basescip-python python gavodachs 2.13 `gavo.base`/__init__:.StructListAttributescip-python python gavodachs 2.13 `gavo.base.complexattrs`/StructListAttribute#("paramRefs",
117 descriptionscip-python python gavodachs 2.13 `gavo.base.complexattrs`/StructListAttribute#__init__().(description)="Names of table parameters belonging to this group",
118 childFactoryscip-python python gavodachs 2.13 `gavo.base.complexattrs`/StructListAttribute#__init__().(childFactory)=ParameterReferencescip-python python gavodachs 2.13 `gavo.rscdef.group`/ParameterReference#,
119 copyable=True)
120
121 _paramsscip-python python gavodachs 2.13 `gavo.rscdef.group`/Group#_params. = commonscip-python python gavodachs 2.13 `gavo.rscdef.common`/__init__:.ColumnListAttributescip-python python gavodachs 2.13 `gavo.rscdef.common`/ColumnListAttribute#("params",
122 childFactoryscip-python python gavodachs 2.13 `gavo.base.complexattrs`/StructListAttribute#__init__().(childFactory)=columnscip-python python gavodachs 2.13 `gavo.rscdef.column`/__init__:.Paramscip-python python gavodachs 2.13 `gavo.rscdef.column`/Param#,
123 descriptionscip-python python gavodachs 2.13 `gavo.base.complexattrs`/StructListAttribute#__init__().(description)="Immediate param elements for this group (use paramref"
124 " to reference params defined in the parent table)",
125 copyable=True)
126
127 _groupsscip-python python gavodachs 2.13 `gavo.rscdef.group`/Group#_groups. = basescip-python python gavodachs 2.13 `gavo.base`/__init__:.StructListAttributescip-python python gavodachs 2.13 `gavo.base.complexattrs`/StructListAttribute#("groups",
128 childFactoryscip-python python gavodachs 2.13 `gavo.base.complexattrs`/StructListAttribute#__init__().(childFactory)=attrdefscip-python python gavodachs 2.13 `gavo.base.attrdef`/__init__:.Recursivescip-python python gavodachs 2.13 `gavo.base.attrdef`/Recursive#,
129 descriptionscip-python python gavodachs 2.13 `gavo.base.complexattrs`/StructListAttribute#__init__().(description)="Sub-groups of this group (names are still referenced"
130 " from the enclosing table)",
131 copyable=True,
132 aliases=["group"])
133
134 _propsscip-python python gavodachs 2.13 `gavo.rscdef.group`/Group#_props. = basescip-python python gavodachs 2.13 `gavo.base`/__init__:.PropertyAttributescip-python python gavodachs 2.13 `gavo.base.complexattrs`/StructListAttribute#(copyable=True)
135
136 @propertyscip-python python python-stdlib 3.11 builtins/property#
137 def tablescip-python python gavodachs 2.13 `gavo.rscdef.group`/Group#table().(selfscip-python python gavodachs 2.13 `gavo.rscdef.group`/Group#table().(self)):
138 """the table definition this group lives in.
139
140 For nested groups, this still is the ancestor table.
141 """
142 try:
143 # (re) compute the table we belong to if there's no table cache
144 # or determination has failed so far.
145 if selfscip-python python gavodachs 2.13 `gavo.rscdef.group`/Group#table().(self).__tableCachescip-python python gavodachs 2.13 `gavo.rscdef.group`/Group#__tableCache. is None:
146 raise AttributeErrorscip-python python python-stdlib 3.11 builtins/AttributeError#
147 except AttributeErrorscip-python python python-stdlib 3.11 builtins/AttributeError#:
148 # find something that has columns (presumably a table def) in our
149 # ancestors. I don't want to check for a TableDef instance
150 # since I don't want to import rscdef.table here (circular import)
151 # and things with column and params would work as well.
152 anc = selfscip-python python gavodachs 2.13 `gavo.rscdef.group`/Group#table().(self).parentscip-python python gavodachs 2.13 `gavo.base.structure`/StructureBase#parent.
153 while anc:
154 if hasattr(anc, "columns"):
155 selfscip-python python gavodachs 2.13 `gavo.rscdef.group`/Group#table().(self).__tableCachescip-python python gavodachs 2.13 `gavo.rscdef.group`/Group#__tableCache. = anc
156 break
157 anc = anc.parentscip-python python gavodachs 2.13 `gavo.base.structure`/StructureBase#parent.
158 else:
159 selfscip-python python gavodachs 2.13 `gavo.rscdef.group`/Group#table().(self).__tableCachescip-python python gavodachs 2.13 `gavo.rscdef.group`/Group#__tableCache. = None
160 return selfscip-python python gavodachs 2.13 `gavo.rscdef.group`/Group#table().(self).__tableCachescip-python python gavodachs 2.13 `gavo.rscdef.group`/Group#__tableCache.
161
162 def onParentCompletescip-python python gavodachs 2.13 `gavo.rscdef.group`/Group#onParentComplete().(selfscip-python python gavodachs 2.13 `gavo.rscdef.group`/Group#onParentComplete().(self)):
163 """checks that param and column names can be found in the parent table.
164 """
165 # defer validation for sub-groups (parent group will cause validation)
166 if isinstance(selfscip-python python gavodachs 2.13 `gavo.rscdef.group`/Group#onParentComplete().(self).parentscip-python python gavodachs 2.13 `gavo.base.structure`/StructureBase#parent., Groupscip-python python gavodachs 2.13 `gavo.rscdef.group`/Group#):
167 return
168 # forgo validation if the group doesn't have a table
169 if selfscip-python python gavodachs 2.13 `gavo.rscdef.group`/Group#onParentComplete().(self).tablescip-python python gavodachs 2.13 `gavo.rscdef.group`/Group#table(). is None:
170 return
171
172 try:
173 for col in selfscip-python python gavodachs 2.13 `gavo.rscdef.group`/Group#onParentComplete().(self).iterColumnsscip-python python gavodachs 2.13 `gavo.rscdef.group`/Group#iterColumns().():
174 pass
175 for par in selfscip-python python gavodachs 2.13 `gavo.rscdef.group`/Group#onParentComplete().(self).iterParamsscip-python python gavodachs 2.13 `gavo.rscdef.group`/Group#iterParams().():
176 pass
177 except basescip-python python gavodachs 2.13 `gavo.base`/__init__:.NotFoundErrorscip-python python gavodachs 2.13 `gavo.base.structure`/Structure# as msg:
178 raise basescip-python python gavodachs 2.13 `gavo.base`/__init__:.StructureErrorscip-python python gavodachs 2.13 `gavo.base.structure`/Structure#(
179 "No param or field %s in found in table %s"%(
180 msg.whatscip-python python gavodachs 2.13 `gavo.utils.excs`/NotFoundError#what., selfscip-python python gavodachs 2.13 `gavo.rscdef.group`/Group#onParentComplete().(self).tablescip-python python gavodachs 2.13 `gavo.rscdef.group`/Group#table()..id))
181
182 for group in selfscip-python python gavodachs 2.13 `gavo.rscdef.group`/Group#onParentComplete().(self).groups:
183 group.onParentComplete()
184
185 def iterColumnsscip-python python gavodachs 2.13 `gavo.rscdef.group`/Group#iterColumns().(selfscip-python python gavodachs 2.13 `gavo.rscdef.group`/Group#iterColumns().(self)):
186 """iterates over columns within this group.
187 """
188 table = selfscip-python python gavodachs 2.13 `gavo.rscdef.group`/Group#iterColumns().(self).tablescip-python python gavodachs 2.13 `gavo.rscdef.group`/Group#table(). # (self.table is a property)
189 for ref in selfscip-python python gavodachs 2.13 `gavo.rscdef.group`/Group#iterColumns().(self).columnRefs:
190 yield ref.resolve(table)
191
192 def iterParamsscip-python python gavodachs 2.13 `gavo.rscdef.group`/Group#iterParams().(selfscip-python python gavodachs 2.13 `gavo.rscdef.group`/Group#iterParams().(self)):
193 """iterates over all params within this group.
194
195 This includes both params refereced in the parent table and immediate
196 params.
197 """
198 table = selfscip-python python gavodachs 2.13 `gavo.rscdef.group`/Group#iterParams().(self).tablescip-python python gavodachs 2.13 `gavo.rscdef.group`/Group#table(). # (self.table is a property)
199 for ref in selfscip-python python gavodachs 2.13 `gavo.rscdef.group`/Group#iterParams().(self).paramRefs:
200 yield ref.resolve(table)
201 for par in selfscip-python python gavodachs 2.13 `gavo.rscdef.group`/Group#iterParams().(self).params:
202 yield par
203