Debian Codegraph @

gavo/rscdef/procdef.py

raw symbols SCIP
1 """
2 Basic handling for embedded procedures.
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 import functoolsscip-python python python-stdlib 3.11 functools/__init__:
12
13 from gavoscip-python python gavodachs 2.13 gavo/__init__: import basescip-python python gavodachs 2.13 `gavo.base`/__init__:
14 from gavoscip-python python gavodachs 2.13 gavo/__init__: import utilsscip-python python gavodachs 2.13 `gavo.utils`/__init__:
15 from gavo.rscdefscip-python python gavodachs 2.13 `gavo.rscdef`/__init__: import commonscip-python python gavodachs 2.13 `gavo.rscdef.common`/__init__:
16 from gavo.rscdefscip-python python gavodachs 2.13 `gavo.rscdef`/__init__: import rmkfuncsscip-python python gavodachs 2.13 `gavo.rscdef.rmkfuncs`/__init__:
17
18
19
20 # Move this one to utils?
21 def unionByKeyscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/unionByKey().(*sequencesscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/unionByKey().(sequences)):
22 """returns all items in sequences uniqued by the items' key attributes.
23
24 The order of the sequence items is not maintained, but items in
25 later sequences override those in earlier ones.
26 """
27 allItems = {}
28 for seq in sequencesscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/unionByKey().(sequences):
29 for item in seq:
30 allItems[item.key] = item
31 return listscip-python python python-stdlib 3.11 builtins/list#(allItems.valuesscip-python python python-stdlib 3.11 builtins/dict#values().())
32
33
34 class RDParameterscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/RDParameter#(basescip-python python gavodachs 2.13 `gavo.base`/__init__:.Structurescip-python python gavodachs 2.13 `gavo.base.structure`/Structure#):
35 """A base class for parameters.
36 """
37 _namescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/RDParameter#_name. = basescip-python python gavodachs 2.13 `gavo.base`/__init__:.UnicodeAttributescip-python python gavodachs 2.13 `gavo.base.attrdef`/UnicodeAttribute#("key", default=basescip-python python gavodachs 2.13 `gavo.base`/__init__:.Undefinedscip-python python gavodachs 2.13 `gavo.base.attrdef`/UnicodeAttribute#,
38 description="The name of the parameter", copyable=True, strip=True,
39 aliases=["name"])
40 _descrscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/RDParameter#_descr. = basescip-python python gavodachs 2.13 `gavo.base`/__init__:.NWUnicodeAttributescip-python python gavodachs 2.13 `gavo.base.attrdef`/UnicodeAttribute#("description", default=None,
41 description="Some human-readable description of what the"
42 " parameter is about", copyable=True, strip=True)
43 _exprscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/RDParameter#_expr. = basescip-python python gavodachs 2.13 `gavo.base`/__init__:.DataContentscip-python python gavodachs 2.13 `gavo.base.structure`/DataContent#(descriptionscip-python python gavodachs 2.13 `gavo.base.structure`/DataContent#__init__().(description)="The default for the parameter."
44 " The special value __NULL__ indicates a NULL (python None) as usual."
45 " An empty content means a non-preset parameter, which must be filled"
46 " in applications. Use the magic value __EMPTY__ to presetting an"
47 " empty string.",
48 copyable=True, strip=True, defaultscip-python python gavodachs 2.13 `gavo.base.structure`/DataContent#__init__().(default)=basescip-python python gavodachs 2.13 `gavo.base`/__init__:.NotGivenscip-python python gavodachs 2.13 `gavo.base.attrdef`/UnicodeAttribute#)
49
50 def isDefaultedscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/RDParameter#isDefaulted().(selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/RDParameter#isDefaulted().(self)):
51 return selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/RDParameter#isDefaulted().(self).content_scip-python python gavodachs 2.13 `gavo.rscdef.procdef`/RDParameter#content_. is not basescip-python python gavodachs 2.13 `gavo.base`/__init__:.NotGivenscip-python python gavodachs 2.13 `gavo.base.attrdef`/UnicodeAttribute#
52
53 def validatescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/RDParameter#validate().(selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/RDParameter#validate().(self)):
54 superscip-python python python-stdlib 3.11 builtins/super#().validatescip-python python gavodachs 2.13 `gavo.base.common`/StructCallbacks#validate().()
55 if not utilsscip-python python gavodachs 2.13 `gavo.utils`/__init__:.identifierPatternscip-python python gavodachs 2.13 `gavo.utils.texttricks`/identifierPattern..matchscip-python python python-stdlib 3.11 re/Pattern#match().(selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/RDParameter#validate().(self).key):
56 raise basescip-python python gavodachs 2.13 `gavo.base`/__init__:.LiteralParseErrorscip-python python gavodachs 2.13 `gavo.base.attrdef`/UnicodeAttribute#("name", selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/RDParameter#validate().(self).key, hintscip-python python gavodachs 2.13 `gavo.utils.excs`/LiteralParseError#__init__().(hint)=
57 "The name you supplied was not defined by any procedure definition.")
58
59 def completeElementscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/RDParameter#completeElement().(selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/RDParameter#completeElement().(self), ctxscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/RDParameter#completeElement().(ctx)):
60 if selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/RDParameter#completeElement().(self).content_scip-python python gavodachs 2.13 `gavo.rscdef.procdef`/RDParameter#content_.=="__EMPTY__":
61 selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/RDParameter#completeElement().(self).content_scip-python python gavodachs 2.13 `gavo.rscdef.procdef`/RDParameter#content_. = ""
62
63 superscip-python python python-stdlib 3.11 builtins/super#().completeElementscip-python python gavodachs 2.13 `gavo.base.common`/StructCallbacks#completeElement().(ctxscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/RDParameter#completeElement().(ctx))
64
65
66 class AliasableRDParameterscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/AliasableRDParameter#(RDParameterscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/RDParameter#):
67 """A base class for RD parameter definitions that support aliases.
68 """
69 _aliasscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/AliasableRDParameter#_alias. = basescip-python python gavodachs 2.13 `gavo.base`/__init__:.UnicodeAttributescip-python python gavodachs 2.13 `gavo.base.attrdef`/UnicodeAttribute#("alias", default=None,
70 description="A deprecated name for the parameter",
71 copyable=True, strip=True)
72
73
74 class ProcParscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcPar#(AliasableRDParameterscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/AliasableRDParameter#):
75 """A parameter of a procedure definition.
76
77 Bodies of ProcPars are interpreted as python expressions, in
78 which macros are expanded in the context of the procedure application's
79 parent. If a body is empty, the parameter has no default and has
80 to be filled by the procedure application.
81 """
82 name_scip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcPar#name_. = "par"
83
84 _latescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcPar#_late. = basescip-python python gavodachs 2.13 `gavo.base`/__init__:.BooleanAttributescip-python python gavodachs 2.13 `gavo.base.attrdef`/UnicodeAttribute#("late", defaultscip-python python gavodachs 2.13 `gavo.base.attrdef`/AttributeDef#__init__().(default)=False,
85 descriptionscip-python python gavodachs 2.13 `gavo.base.attrdef`/AttributeDef#__init__().(description)="Bind the name not at setup time but at applying"
86 " time. In rowmaker procedures, for example, this allows you to"
87 " refer to variables like vars or rowIter in the bindings.")
88
89 def validatescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcPar#validate().(selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcPar#validate().(self)):
90 superscip-python python python-stdlib 3.11 builtins/super#().validatescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/RDParameter#validate().()
91
92 # Allow non-python syntax when things look like macro calls,
93 # but assume @ expressions will be expanded (which is not
94 # always true, admittedly)
95 if (selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcPar#validate().(self).content_scip-python python gavodachs 2.13 `gavo.rscdef.procdef`/RDParameter#content_.
96 and not "\\" in selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcPar#validate().(self).content_scip-python python gavodachs 2.13 `gavo.rscdef.procdef`/RDParameter#content_.):
97 utilsscip-python python gavodachs 2.13 `gavo.utils`/__init__:.ensureExpressionscip-python python gavodachs 2.13 `gavo.utils.codetricks`/ensureExpression().(
98 commonscip-python python gavodachs 2.13 `gavo.rscdef.common`/__init__:.replaceProcDefAtscip-python python gavodachs 2.13 `gavo.rscdef.common`/replaceProcDefAt().(selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcPar#validate().(self).content_scip-python python gavodachs 2.13 `gavo.rscdef.procdef`/RDParameter#content_.),
99 selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcPar#validate().(self).key)
100
101
102 class Bindingscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/Binding#(ProcParscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcPar#):
103 """A binding of a procedure definition parameter to a concrete value.
104
105 The value to set is contained in the binding body in the form of
106 a python expression. The body must not be empty.
107 """
108 name_scip-python python gavodachs 2.13 `gavo.rscdef.procdef`/Binding#name_. = "bind"
109
110 def validatescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/Binding#validate().(selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/Binding#validate().(self)):
111 superscip-python python python-stdlib 3.11 builtins/super#().validatescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcPar#validate().()
112 if not selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/Binding#validate().(self).content_scip-python python gavodachs 2.13 `gavo.rscdef.procdef`/RDParameter#content_. or not selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/Binding#validate().(self).content_scip-python python gavodachs 2.13 `gavo.rscdef.procdef`/RDParameter#content_..stripscip-python python python-stdlib 3.11 builtins/str#strip().():
113 raise basescip-python python gavodachs 2.13 `gavo.base`/__init__:.StructureErrorscip-python python gavodachs 2.13 `gavo.base.structure`/Structure#("Binding bodies must not be empty.")
114
115
116 class ProcSetupscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcSetup#(basescip-python python gavodachs 2.13 `gavo.base`/__init__:.Structurescip-python python gavodachs 2.13 `gavo.base.structure`/Structure#):
117 """Prescriptions for setting up a namespace for a procedure application.
118
119 You can add names to this namespace you using par(ameter)s.
120 If a parameter has no default and an procedure application does
121 not provide them, an error is raised.
122
123 You can also add names by providing a code attribute containing
124 a python function body in code. Within, the parameters are
125 available. The procedure application's parent can be accessed
126 as parent. All names you define in the code are available as
127 globals to the procedure body.
128
129 Caution: Macros are expanded within the code; this means you
130 need double backslashes if you want a single backslash in python
131 code.
132 """
133 name_scip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcSetup#name_. = "setup"
134
135 _codescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcSetup#_code. = basescip-python python gavodachs 2.13 `gavo.base`/__init__:.ListOfAtomsAttributescip-python python gavodachs 2.13 `gavo.base.complexattrs`/StructListAttribute#("codeFrags",
136 description="Python function bodies setting globals for the function"
137 " application. Macros are expanded in the context"
138 " of the procedure's parent.",
139 itemAttDscip-python python gavodachs 2.13 `gavo.base.complexattrs`/CollOfAtomsAttribute#__init__().(itemAttD)=basescip-python python gavodachs 2.13 `gavo.base`/__init__:.UnicodeAttributescip-python python gavodachs 2.13 `gavo.base.attrdef`/UnicodeAttribute#("code", description="Python function"
140 " bodies setting globals for the function application. Macros"
141 " are expanded in the context of the procedure's parent.",
142 copyable=True),
143 copyable=True)
144 _parsscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcSetup#_pars. = basescip-python python gavodachs 2.13 `gavo.base`/__init__:.StructListAttributescip-python python gavodachs 2.13 `gavo.base.complexattrs`/StructListAttribute#("pars", ProcParscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcPar#,
145 descriptionscip-python python gavodachs 2.13 `gavo.base.complexattrs`/StructListAttribute#__init__().(description)="Names to add to the procedure's global namespace.",
146 copyable=True)
147 _importsscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcSetup#_imports. = basescip-python python gavodachs 2.13 `gavo.base`/__init__:.UnicodeAttributescip-python python gavodachs 2.13 `gavo.base.attrdef`/UnicodeAttribute#("imports",
148 description="A list of comma-separated imports to put into the"
149 " code's namespace. Dottesd specs like a.b.c are converted to"
150 " ``from a.b import c``",
151 default=basescip-python python gavodachs 2.13 `gavo.base`/__init__:.NotGivenscip-python python gavodachs 2.13 `gavo.base.attrdef`/UnicodeAttribute#,
152 copyable=True)
153 _originalscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcSetup#_original. = basescip-python python gavodachs 2.13 `gavo.base`/__init__:.OriginalAttributescip-python python gavodachs 2.13 `gavo.base.parsecontext`/OriginalAttribute#()
154
155 def _getParSettingCodescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcSetup#_getParSettingCode().(selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcSetup#_getParSettingCode().(self), useLatescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcSetup#_getParSettingCode().(useLate), indentscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcSetup#_getParSettingCode().(indent), bindingsscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcSetup#_getParSettingCode().(bindings)):
156 """returns code that sets our parameters.
157
158 If useLate is true, generate for late bindings. Indent the
159 code by indent. Bindings is a dictionary overriding
160 the defaults or setting parameter values.
161 """
162 parCode = []
163 for p in selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcSetup#_getParSettingCode().(self).pars:
164 if p.late==useLatescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcSetup#_getParSettingCode().(useLate):
165 val = bindingsscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcSetup#_getParSettingCode().(bindings).get(p.key, basescip-python python gavodachs 2.13 `gavo.base`/__init__:.NotGivenscip-python python gavodachs 2.13 `gavo.base.attrdef`/UnicodeAttribute#)
166 if val is basescip-python python gavodachs 2.13 `gavo.base`/__init__:.NotGivenscip-python python gavodachs 2.13 `gavo.base.attrdef`/UnicodeAttribute#:
167 val = p.content_
168 if val is basescip-python python gavodachs 2.13 `gavo.base`/__init__:.NotGivenscip-python python gavodachs 2.13 `gavo.base.attrdef`/UnicodeAttribute#:
169 # val must be bound somewhere else (since _ensureParsBound
170 # succeeded); don't emit any code for this par in this setup
171 # and hope for the best.
172 continue
173
174 if not useLatescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcSetup#_getParSettingCode().(useLate) and val.strip().startswith("@"):
175 # Heuristic: We forbid @-expressions in val. This is doene
176 # explicitly here because this error is hard to spot and
177 # we probably won't have much in the way of false positives.
178 raise basescip-python python gavodachs 2.13 `gavo.base`/__init__:.StructureErrorscip-python python gavodachs 2.13 `gavo.base.structure`/Structure#("You cannot use @-references in"
179 f" non-late parameter bindings. But '{val}' (bound to {p.key})"
180 " looks like an @-reference, so I give up.",
181 posscip-python python gavodachs 2.13 `gavo.utils.excs`/StructureError#__init__().(pos)=selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcSetup#_getParSettingCode().(self).getSourcePositionscip-python python gavodachs 2.13 `gavo.base.structure`/StructureBase#getSourcePosition().())
182 parCode.appendscip-python python python-stdlib 3.11 builtins/list#append().("%s%s = %s"%(indentscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcSetup#_getParSettingCode().(indent), p.key, val))
183
184 return "\n".joinscip-python python python-stdlib 3.11 builtins/str#join().(parCode)
185
186 def getParCodescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcSetup#getParCode().(selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcSetup#getParCode().(self), bindingsscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcSetup#getParCode().(bindings)):
187 """returns code doing setup bindings un-indented.
188 """
189 return selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcSetup#getParCode().(self)._getParSettingCodescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcSetup#_getParSettingCode().(False, "", bindingsscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcSetup#getParCode().(bindings))
190
191 def getLateCodescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcSetup#getLateCode().(selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcSetup#getLateCode().(self), bindingsscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcSetup#getLateCode().(bindings)):
192 """returns code doing late (in-function) bindings indented with two
193 spaces.
194 """
195 return selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcSetup#getLateCode().(self)._getParSettingCodescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcSetup#_getParSettingCode().(True, " ", bindingsscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcSetup#getLateCode().(bindings))
196
197 def getImportsCodescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcSetup#getImportsCode().(selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcSetup#getImportsCode().(self)):
198 if not selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcSetup#getImportsCode().(self).imports:
199 return
200 for spec in selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcSetup#getImportsCode().(self).imports.strip().split(","):
201 parts = spec.strip().split(".")
202 if len(parts)>1:
203 yield "from %s import %s"%(".".joinscip-python python python-stdlib 3.11 builtins/str#join().(parts[:-1]), parts[-1])
204 else:
205 yield "import "+parts[0]
206
207 def getBodyCodescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcSetup#getBodyCode().(selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcSetup#getBodyCode().(self)):
208 """returns the body code un-indented.
209 """
210 collectedCode = listscip-python python python-stdlib 3.11 builtins/list#(selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcSetup#getBodyCode().(self).getImportsCodescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcSetup#getImportsCode().())
211 for frag in selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcSetup#getBodyCode().(self).codeFrags:
212 try:
213 collectedCode.appendscip-python python python-stdlib 3.11 builtins/list#append().(
214 utilsscip-python python gavodachs 2.13 `gavo.utils`/__init__:.fixIndentationscip-python python gavodachs 2.13 `gavo.utils.texttricks`/fixIndentation().(frag, "", governingLinescip-python python gavodachs 2.13 `gavo.utils.texttricks`/fixIndentation().(governingLine)=1))
215 except basescip-python python gavodachs 2.13 `gavo.base`/__init__:.LiteralParseErrorscip-python python gavodachs 2.13 `gavo.base.attrdef`/UnicodeAttribute# as ex:
216 ex.posscip-python python gavodachs 2.13 `gavo.utils.excs`/StructureError#pos. = selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcSetup#getBodyCode().(self).getSourcePositionscip-python python gavodachs 2.13 `gavo.base.structure`/StructureBase#getSourcePosition().()
217 raise
218
219 return "\n".joinscip-python python python-stdlib 3.11 builtins/str#join().(collectedCode)
220
221
222 class ProcDefscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcDef#(basescip-python python gavodachs 2.13 `gavo.base`/__init__:.Structurescip-python python gavodachs 2.13 `gavo.base.structure`/Structure#, basescip-python python gavodachs 2.13 `gavo.base`/__init__:.RestrictionMixinscip-python python gavodachs 2.13 `gavo.base.structure`/RestrictionMixin#):
223 """An embedded procedure.
224
225 Embedded procedures are python code fragments with some interface defined
226 by their type. They can occur at various places (which is called procedure
227 application generically), e.g., as row generators in grammars, as apply-s in
228 rowmakers, or as SQL phrase makers in condDescs.
229
230 They consist of the actual actual code and, optionally, definitions like
231 the namespace setup, configuration parameters, or a documentation.
232
233 The procedure applications compile into python functions with special
234 global namespaces. The signatures of the functions are determined by
235 the type attribute.
236
237 ProcDefs are referred to by procedure applications using their id.
238 """
239 name_scip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcDef#name_. = "procDef"
240
241 _codescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcDef#_code. = basescip-python python gavodachs 2.13 `gavo.base`/__init__:.UnicodeAttributescip-python python gavodachs 2.13 `gavo.base.attrdef`/UnicodeAttribute#("code", default=basescip-python python gavodachs 2.13 `gavo.base`/__init__:.NotGivenscip-python python gavodachs 2.13 `gavo.base.attrdef`/UnicodeAttribute#,
242 copyable=True, description="A python function body.")
243 _setupscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcDef#_setup. = basescip-python python gavodachs 2.13 `gavo.base`/__init__:.StructListAttributescip-python python gavodachs 2.13 `gavo.base.complexattrs`/StructListAttribute#("setups", ProcSetupscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcSetup#,
244 descriptionscip-python python gavodachs 2.13 `gavo.base.complexattrs`/StructListAttribute#__init__().(description)="Setup of the namespace the function will run in",
245 copyable=True)
246 _docscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcDef#_doc. = basescip-python python gavodachs 2.13 `gavo.base`/__init__:.UnicodeAttributescip-python python gavodachs 2.13 `gavo.base.attrdef`/UnicodeAttribute#("doc", default="", description=
247 "Human-readable docs for this proc (may be interpreted as restructured"
248 " text).", copyable=True)
249 _typescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcDef#_type. = basescip-python python gavodachs 2.13 `gavo.base`/__init__:.EnumeratedUnicodeAttributescip-python python gavodachs 2.13 `gavo.base.attrdef`/UnicodeAttribute#("type", defaultscip-python python gavodachs 2.13 `gavo.base.attrdef`/EnumeratedUnicodeAttribute#__init__().(default)=None, description=
250 "The type of the procedure definition. The procedure applications"
251 " will in general require certain types of definitions.",
252 validValuesscip-python python gavodachs 2.13 `gavo.base.attrdef`/EnumeratedUnicodeAttribute#__init__().(validValues)=["t_t", "apply", "rowfilter", "sourceFields", "mixinProc",
253 "phraseMaker", "descriptorGenerator", "dataFunction", "dataFormatter",
254 "metaMaker", "regTest", "iterator", "pargetter"],
255 copyable=True,
256 strip=True)
257 _deprecatedscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcDef#_deprecated. = basescip-python python gavodachs 2.13 `gavo.base`/__init__:.UnicodeAttributescip-python python gavodachs 2.13 `gavo.base.attrdef`/UnicodeAttribute#("deprecated", default=None,
258 copyable=True, description="A deprecation message. This will"
259 " be shown if this procDef is being compiled.")
260 _originalscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcDef#_original. = basescip-python python gavodachs 2.13 `gavo.base`/__init__:.OriginalAttributescip-python python gavodachs 2.13 `gavo.base.parsecontext`/OriginalAttribute#()
261
262 def getCodescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcDef#getCode().(selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcDef#getCode().(self)):
263 """returns the body code indented with two spaces.
264 """
265 if selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcDef#getCode().(self).code is basescip-python python gavodachs 2.13 `gavo.base`/__init__:.NotGivenscip-python python gavodachs 2.13 `gavo.base.attrdef`/UnicodeAttribute#:
266 return ""
267 else:
268 try:
269 return utilsscip-python python gavodachs 2.13 `gavo.utils`/__init__:.fixIndentationscip-python python gavodachs 2.13 `gavo.utils.texttricks`/fixIndentation().(selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcDef#getCode().(self).code, " ", governingLinescip-python python gavodachs 2.13 `gavo.utils.texttricks`/fixIndentation().(governingLine)=1)
270 except basescip-python python gavodachs 2.13 `gavo.base`/__init__:.LiteralParseErrorscip-python python gavodachs 2.13 `gavo.base.attrdef`/UnicodeAttribute# as ex:
271 ex.posscip-python python gavodachs 2.13 `gavo.utils.excs`/StructureError#pos. = selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcDef#getCode().(self).getSourcePositionscip-python python gavodachs 2.13 `gavo.base.structure`/StructureBase#getSourcePosition().()
272 raise
273
274 @functoolsscip-python python python-stdlib 3.11 functools/__init__:.lru_cachescip-python python python-stdlib 3.11 functools/lru_cache().(1)
275 def getSetupParsscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcDef#getSetupPars().(selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcDef#getSetupPars().(self)):
276 """returns all parameters used by setup items, where lexically
277 later items override earlier items of the same name.
278 """
279 return unionByKeyscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/unionByKey().(*[s.pars for s in selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcDef#getSetupPars().(self).setups])
280
281 def getLateSetupCodescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcDef#getLateSetupCode().(selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcDef#getLateSetupCode().(self), boundNamesscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcDef#getLateSetupCode().(boundNames)):
282 return "\n".joinscip-python python python-stdlib 3.11 builtins/str#join().(s.getLateCode(boundNamesscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcDef#getLateSetupCode().(boundNames)) for s in selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcDef#getLateSetupCode().(self).setups)
283
284 def getParSetupCodescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcDef#getParSetupCode().(selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcDef#getParSetupCode().(self), boundNamesscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcDef#getParSetupCode().(boundNames)):
285 return "\n".joinscip-python python python-stdlib 3.11 builtins/str#join().(s.getParCode(boundNamesscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcDef#getParSetupCode().(boundNames)) for s in selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcDef#getParSetupCode().(self).setups)
286
287 def getBodySetupCodescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcDef#getBodySetupCode().(selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcDef#getBodySetupCode().(self), boundNamesscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcDef#getBodySetupCode().(boundNames)):
288 return "\n".joinscip-python python python-stdlib 3.11 builtins/str#join().(s.getBodyCode() for s in selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcDef#getBodySetupCode().(self).setups)
289
290
291 class ProcAppscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#(ProcDefscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcDef#):
292 """An abstract base for procedure applications.
293
294 Deriving classes need to provide:
295
296 - a requiredType attribute specifying what ProcDefs can be applied.
297 - a formalArgs attribute containing a (python) formal argument list
298 - of course, a name_ for XML purposes.
299
300 They can, in addition, give a class attribute additionalNamesForProcs,
301 which is a dictionary that is joined into the global namespace during
302 procedure compilation.
303 """
304 _procDefscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#_procDef. = basescip-python python gavodachs 2.13 `gavo.base`/__init__:.ReferenceAttributescip-python python gavodachs 2.13 `gavo.base.parsecontext`/ReferenceAttribute#("procDef", forceTypescip-python python gavodachs 2.13 `gavo.base.parsecontext`/ReferenceAttribute#__init__().(forceType)=ProcDefscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcDef#,
305 defaultscip-python python gavodachs 2.13 `gavo.base.parsecontext`/ReferenceAttribute#__init__().(default)=basescip-python python gavodachs 2.13 `gavo.base`/__init__:.NotGivenscip-python python gavodachs 2.13 `gavo.base.attrdef`/UnicodeAttribute#, descriptionscip-python python gavodachs 2.13 `gavo.base.parsecontext`/ReferenceAttribute#__init__().(description)="Reference to the procedure"
306 " definition to apply", copyable=True)
307 _bindingsscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#_bindings. = basescip-python python gavodachs 2.13 `gavo.base`/__init__:.StructListAttributescip-python python gavodachs 2.13 `gavo.base.complexattrs`/StructListAttribute#("bindings", descriptionscip-python python gavodachs 2.13 `gavo.base.complexattrs`/StructListAttribute#__init__().(description)=
308 "Values for parameters of the procedure definition",
309 childFactoryscip-python python gavodachs 2.13 `gavo.base.complexattrs`/StructListAttribute#__init__().(childFactory)=Bindingscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/Binding#, copyable=True)
310 _namescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#_name. = basescip-python python gavodachs 2.13 `gavo.base`/__init__:.UnicodeAttributescip-python python gavodachs 2.13 `gavo.base.attrdef`/UnicodeAttribute#("name", default=basescip-python python gavodachs 2.13 `gavo.base`/__init__:.NotGivenscip-python python gavodachs 2.13 `gavo.base.attrdef`/UnicodeAttribute#,
311 description="A name of the proc. ProcApps compute their (python)"
312 " names to be somewhat random strings. Set a name manually to"
313 " receive more easily decipherable error messages. If you do that,"
314 " you have to care about name clashes yourself, though.", strip=True)
315
316 requiredTypescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#requiredType. = None
317
318 additionalNamesForProcsscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#additionalNamesForProcs. = {}
319
320 def validatescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#validate().(selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#validate().(self)):
321 if selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#validate().(self).procDef and selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#validate().(self).procDef.type and selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#validate().(self).requiredTypescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#requiredType.:
322 if selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#validate().(self).procDef.type!=selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#validate().(self).requiredTypescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#requiredType.:
323 raise basescip-python python gavodachs 2.13 `gavo.base`/__init__:.StructureErrorscip-python python gavodachs 2.13 `gavo.base.structure`/Structure#("The procDef %s has type %s, but"
324 " here %s procDefs are required."%(selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#validate().(self).procDef.id,
325 selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#validate().(self).procDef.type, selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#validate().(self).requiredTypescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#requiredType.))
326
327 if selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#validate().(self).procDef:
328 if selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#validate().(self).procDef.deprecated:
329 if selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#validate().(self).getSourcePositionscip-python python gavodachs 2.13 `gavo.base.structure`/StructureBase#getSourcePosition().()!="<internally built>":
330 # for now, don't warn about these; they typically
331 # originate when copying/adapting cores and will just
332 # confuse operators
333 procId = "unnamed procApp"
334 if selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#validate().(self).namescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#name.:
335 procId = "procApp %s"%selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#validate().(self).namescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#name.
336
337 basescip-python python gavodachs 2.13 `gavo.base`/__init__:.uiscip-python python gavodachs 2.13 `gavo.base`/ui..notifyWarningscip-python python gavodachs 2.13 `gavo.base.events`/EventDispatcher#notifyWarning().("%s, %s: %s"%(
338 selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#validate().(self).getSourcePositionscip-python python gavodachs 2.13 `gavo.base.structure`/StructureBase#getSourcePosition().(),
339 procId,
340 utilsscip-python python gavodachs 2.13 `gavo.utils`/__init__:.fixIndentationscip-python python gavodachs 2.13 `gavo.utils.texttricks`/fixIndentation().(selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#validate().(self).procDef.deprecated, "")))
341
342 superscip-python python python-stdlib 3.11 builtins/super#().validatescip-python python gavodachs 2.13 `gavo.base.common`/StructCallbacks#validate().()
343 selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#validate().(self)._ensureParsBoundscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#_ensureParsBound().()
344
345 def completeElementscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#completeElement().(selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#completeElement().(self), ctxscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#completeElement().(ctx)):
346 superscip-python python python-stdlib 3.11 builtins/super#().completeElementscip-python python gavodachs 2.13 `gavo.base.structure`/RestrictionMixin#completeElement().(ctxscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#completeElement().(ctx))
347 if selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#completeElement().(self).namescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#name. is basescip-python python gavodachs 2.13 `gavo.base`/__init__:.NotGivenscip-python python gavodachs 2.13 `gavo.base.attrdef`/UnicodeAttribute#: # make up a name from self's id
348 selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#completeElement().(self).namescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#name. = ("proc%x"%id(selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#completeElement().(self))).replacescip-python python python-stdlib 3.11 builtins/str#replace().("-", "")
349
350 @functoolsscip-python python python-stdlib 3.11 functools/__init__:.lru_cachescip-python python python-stdlib 3.11 functools/lru_cache().(1)
351 def getSetupParsscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#getSetupPars().(selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#getSetupPars().(self)):
352 """returns the setup parameters for the proc app, where procDef
353 parameters may be overridden by self's parameters.
354 """
355 allSetups = []
356 if selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#getSetupPars().(self).procDef is not basescip-python python gavodachs 2.13 `gavo.base`/__init__:.NotGivenscip-python python gavodachs 2.13 `gavo.base.attrdef`/UnicodeAttribute#:
357 allSetups.extendscip-python python python-stdlib 3.11 builtins/list#extend().(selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#getSetupPars().(self).procDef.setups)
358 allSetups.extendscip-python python python-stdlib 3.11 builtins/list#extend().(selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#getSetupPars().(self).setups)
359 return unionByKeyscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/unionByKey().(*[s.pars for s in allSetups])
360
361 def _ensureParsBoundscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#_ensureParsBound().(selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#_ensureParsBound().(self)):
362 """raises an error if non-defaulted pars of procDef are not filled
363 by the bindings.
364 """
365 bindNames = dictscip-python python python-stdlib 3.11 builtins/dict#((b.key, b) for b in selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#_ensureParsBound().(self).bindings)
366 for p in selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#_ensureParsBound().(self).getSetupParsscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#getSetupPars().():
367
368 if p.alias and p.alias in bindNames:
369 binding = bindNames.popscip-python python python-stdlib 3.11 builtins/dict#pop().(p.alias)
370 binding.key = p.key
371 if p.key in bindNames:
372 raise basescip-python python gavodachs 2.13 `gavo.base`/__init__:.StructureErrorscip-python python gavodachs 2.13 `gavo.base.structure`/Structure#("Both canonical name and alias bound:"
373 " %s, %s"%(p.key, p.alias))
374 else:
375 bindNames[p.key] = binding
376
377 if not p.isDefaulted():
378 if not p.key in bindNames:
379 raise basescip-python python gavodachs 2.13 `gavo.base`/__init__:.StructureErrorscip-python python gavodachs 2.13 `gavo.base.structure`/Structure#("Parameter %s is not defaulted in"
380 " %s and thus must be bound."%(p.key, selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#_ensureParsBound().(self).namescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#name.))
381 if p.key in bindNames:
382 bindNames.popscip-python python python-stdlib 3.11 builtins/dict#pop().(p.key)
383
384 if bindNames:
385 raise basescip-python python gavodachs 2.13 `gavo.base`/__init__:.StructureErrorscip-python python gavodachs 2.13 `gavo.base.structure`/Structure#("May not bind non-existing parameter(s)"
386 " %s."%(", ".joinscip-python python python-stdlib 3.11 builtins/str#join().(bindNames)))
387
388 def onElementCompletescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#onElementComplete().(selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#onElementComplete().(self)):
389 superscip-python python python-stdlib 3.11 builtins/super#().onElementCompletescip-python python gavodachs 2.13 `gavo.base.common`/StructCallbacks#onElementComplete().()
390 selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#onElementComplete().(self)._boundNamesscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#_boundNames. = dictscip-python python python-stdlib 3.11 builtins/dict#((b.key, b.content_) for b in selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#onElementComplete().(self).bindings)
391
392 def _combineWithProcDefscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#_combineWithProcDef().(selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#_combineWithProcDef().(self), methodNamescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#_combineWithProcDef().(methodName), boundNamesscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#_combineWithProcDef().(boundNames)):
393 # A slightly tricky helper method for the implementation of get*SetupCode:
394 # this combines the results of calling methodName on a procDef
395 # (where applicable) with calling it on ProcDef for self.
396 parts = []
397 if selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#_combineWithProcDef().(self).procDef is not basescip-python python gavodachs 2.13 `gavo.base`/__init__:.NotGivenscip-python python gavodachs 2.13 `gavo.base.attrdef`/UnicodeAttribute#:
398 parts.appendscip-python python python-stdlib 3.11 builtins/list#append().(getattrscip-python python python-stdlib 3.11 builtins/getattr().(selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#_combineWithProcDef().(self).procDef, methodNamescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#_combineWithProcDef().(methodName))(boundNamesscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#_combineWithProcDef().(boundNames)))
399
400 parts.appendscip-python python python-stdlib 3.11 builtins/list#append().(getattrscip-python python python-stdlib 3.11 builtins/getattr().(ProcDefscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcDef#, methodNamescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#_combineWithProcDef().(methodName))(selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#_combineWithProcDef().(self), boundNamesscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#_combineWithProcDef().(boundNames)))
401 return "\n".joinscip-python python python-stdlib 3.11 builtins/str#join().(parts)
402
403 def getLateSetupCodescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#getLateSetupCode().(selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#getLateSetupCode().(self), boundNamesscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#getLateSetupCode().(boundNames)):
404 return selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#getLateSetupCode().(self)._combineWithProcDefscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#_combineWithProcDef().("getLateSetupCode", boundNamesscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#getLateSetupCode().(boundNames))
405
406 def getParSetupCodescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#getParSetupCode().(selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#getParSetupCode().(self), boundNamesscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#getParSetupCode().(boundNames)):
407 return selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#getParSetupCode().(self)._combineWithProcDefscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#_combineWithProcDef().("getParSetupCode", boundNamesscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#getParSetupCode().(boundNames))
408
409 def getBodySetupCodescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#getBodySetupCode().(selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#getBodySetupCode().(self), boundNamesscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#getBodySetupCode().(boundNames)):
410 return selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#getBodySetupCode().(self)._combineWithProcDefscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#_combineWithProcDef().("getBodySetupCode", boundNamesscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#getBodySetupCode().(boundNames))
411
412 def getSetupCodescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#getSetupCode().(selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#getSetupCode().(self)):
413 code = "\n".joinscip-python python python-stdlib 3.11 builtins/str#join().((
414 selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#getSetupCode().(self).getParSetupCodescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#getParSetupCode().(selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#getSetupCode().(self)._boundNamesscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#_boundNames.),
415 selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#getSetupCode().(self).getBodySetupCodescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#getBodySetupCode().(selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#getSetupCode().(self)._boundNamesscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#_boundNames.)))
416 if "\\" in code:
417 code = selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#getSetupCode().(self).parentscip-python python gavodachs 2.13 `gavo.base.structure`/StructureBase#parent..expand(code)
418 return code
419
420 def _getFunctionDefinitionscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#_getFunctionDefinition().(selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#_getFunctionDefinition().(self), mainSourcescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#_getFunctionDefinition().(mainSource)):
421 """returns mainSource in a function definition with proper
422 signature including setup of late code.
423 """
424 parts = [selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#_getFunctionDefinition().(self).getLateSetupCodescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#getLateSetupCode().(selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#_getFunctionDefinition().(self)._boundNamesscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#_boundNames.)]
425 parts.appendscip-python python python-stdlib 3.11 builtins/list#append().(mainSourcescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#_getFunctionDefinition().(mainSource))
426 body = "\n".joinscip-python python python-stdlib 3.11 builtins/str#join().(parts)
427 if not body.stripscip-python python python-stdlib 3.11 builtins/str#strip().():
428 body = " pass"
429 return "def %s(%s):\n%s"%(selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#_getFunctionDefinition().(self).namescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#name., selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#_getFunctionDefinition().(self).formalArgs,
430 body)
431
432 def getFuncCodescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#getFuncCode().(selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#getFuncCode().(self)):
433 """returns a function definition for this proc application.
434
435 This includes bindings of late parameters.
436
437 Locally defined code overrides code defined in a procDef.
438 """
439 mainCode = ""
440 if selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#getFuncCode().(self).code is basescip-python python gavodachs 2.13 `gavo.base`/__init__:.NotGivenscip-python python gavodachs 2.13 `gavo.base.attrdef`/UnicodeAttribute#:
441 if selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#getFuncCode().(self).procDef is not basescip-python python gavodachs 2.13 `gavo.base`/__init__:.NotGivenscip-python python gavodachs 2.13 `gavo.base.attrdef`/UnicodeAttribute#:
442 mainCode = selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#getFuncCode().(self).procDef.getCode()
443 else:
444 mainCode = selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#getFuncCode().(self).getCodescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcDef#getCode().()
445 code = selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#getFuncCode().(self)._getFunctionDefinitionscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#_getFunctionDefinition().(mainCode)
446 if "\\" in code:
447 code = selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#getFuncCode().(self).parentscip-python python gavodachs 2.13 `gavo.base.structure`/StructureBase#parent..expand(code)
448 return code
449
450 def _compileForParentscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#_compileForParent().(selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#_compileForParent().(self), parentscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#_compileForParent().(parent)):
451 """helps compile.
452 """
453 # go get the RD for parent; it's always handy in this kind
454 # of code
455 curEl = parentscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#_compileForParent().(parent)
456 while not hasattr(curEl, "rd"):
457 if curEl.parent:
458 curEl = curEl.parent
459 else:
460 break
461 try:
462 rd = curEl.rd
463 except AttributeErrorscip-python python python-stdlib 3.11 builtins/AttributeError#:
464 # maybe an unrooted element
465 rd = None
466
467 return rmkfuncsscip-python python gavodachs 2.13 `gavo.rscdef.rmkfuncs`/__init__:.makeProcscip-python python gavodachs 2.13 `gavo.rscdef.rmkfuncs`/makeProc().(
468 selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#_compileForParent().(self).namescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#name., selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#_compileForParent().(self).getFuncCodescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#getFuncCode().(),
469 selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#_compileForParent().(self).getSetupCodescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#getSetupCode().(), parentscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#_compileForParent().(parent),
470 selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#_compileForParent().(self).getSourcePositionscip-python python gavodachs 2.13 `gavo.base.structure`/StructureBase#getSourcePosition().(),
471 rd=rd,
472 procDef=selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#_compileForParent().(self),
473 **selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#_compileForParent().(self).additionalNamesForProcsscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#additionalNamesForProcs.)
474
475 def breakCirclesscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#breakCircles().(selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#breakCircles().(self)):
476 # overridden to undo additional memoization
477 ProcDefscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcDef#.breakCirclesscip-python python gavodachs 2.13 `gavo.base.structure`/StructureBase#breakCircles().(selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#breakCircles().(self))
478 utilsscip-python python gavodachs 2.13 `gavo.utils`/__init__:.forgetMemoizedscip-python python gavodachs 2.13 `gavo.utils.codetricks`/forgetMemoized().(selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#breakCircles().(self))
479
480 def compilescip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#compile().(selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#compile().(self), parentscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#compile().(parent)=None):
481 """returns a callable for this procedure application.
482
483 You can pass a different parent; it will then be used to
484 expand macros. If you do not give it, the embedding structure will
485 be used.
486 """
487 if parentscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#compile().(parent) is None:
488 parentscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#compile().(parent) = selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#compile().(self).parentscip-python python gavodachs 2.13 `gavo.base.structure`/StructureBase#parent.
489 return utilsscip-python python gavodachs 2.13 `gavo.utils`/__init__:.memoizeOnscip-python python gavodachs 2.13 `gavo.utils.codetricks`/memoizeOn().(parentscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#compile().(parent), selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#compile().(self), selfscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#compile().(self)._compileForParentscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#_compileForParent()., parentscip-python python gavodachs 2.13 `gavo.rscdef.procdef`/ProcApp#compile().(parent))