LSST Applications g0b6bd0c080+24c31cd83f,g0bb880f53e+124095ede6,g17e5ecfddb+de2d58b880,g1d67935e3f+1c55a0d6b1,g38293774b4+ac198e9f13,g396055baef+16b4740d3c,g3b44f30a73+6611e0205b,g48ccf36440+89c08d0516,g5c4744a4d9+a302e8c7f0,g613e996a0d+63bcad581c,g6c8d09e9e7+15f56307d2,g7271f0639c+d538d856f7,g78e1f6c1a3+d538d856f7,g7a1e1b37c0+b1ac16325f,g9b27d6183c+f4e581d51a,g9d27549199+a302e8c7f0,ga1cf026fa3+ac198e9f13,ga32aa97882+7403ac30ac,ga786bb30fb+816c9dab47,gabf319e997+87b2f5fd85,gbe2ba2026d+a8cc7fdb67,gbec6a3398f+1c55a0d6b1,gc397daaa20+2200de225a,gc6308e37c7+c9c982f948,gc655b1545f+87b2f5fd85,gd01420fc67+1c55a0d6b1,gd877ba84e5+1c55a0d6b1,gdb4cecd868+8baeac41d0,ge2d134c3d5+589dd0408c,ge448b5faa6+81805f690f,gec061abbff+d538d856f7,gecc7e12556+d538d856f7,gf3ee170dca+15f56307d2,gf4ac96e456+87b2f5fd85,gf9f5ea5b4d+ac198e9f13,gff490e6085+08a7a94303,w.2022.26
LSST Data Management Base Package
Classes | Functions
lsst.pex.config.history Namespace Reference

Classes

class  Color
 

Functions

def format (config, name=None, writeSourceLine=True, prefix="", verbose=False)
 

Function Documentation

◆ format()

def lsst.pex.config.history.format (   config,
  name = None,
  writeSourceLine = True,
  prefix = "",
  verbose = False 
)
Format the history record for a configuration, or a specific
configuration field.

Parameters
----------
config : `lsst.pex.config.Config`
    A configuration instance.
name : `str`, optional
    The name of a configuration field to specifically format the history
    for. Otherwise the history of all configuration fields is printed.
writeSourceLine : `bool`, optional
    If `True`, prefix each printout line with the code filename and line
    number where the configuration event occurred. Default is `True`.
prefix : `str`, optional
    A prefix for to add to each printout line. This prefix occurs first,
    even before any source line. The default is an empty string.
verbose : `bool`, optional
    Default is `False`.

Definition at line 174 of file history.py.

174def format(config, name=None, writeSourceLine=True, prefix="", verbose=False):
175 """Format the history record for a configuration, or a specific
176 configuration field.
177
178 Parameters
179 ----------
180 config : `lsst.pex.config.Config`
181 A configuration instance.
182 name : `str`, optional
183 The name of a configuration field to specifically format the history
184 for. Otherwise the history of all configuration fields is printed.
185 writeSourceLine : `bool`, optional
186 If `True`, prefix each printout line with the code filename and line
187 number where the configuration event occurred. Default is `True`.
188 prefix : `str`, optional
189 A prefix for to add to each printout line. This prefix occurs first,
190 even before any source line. The default is an empty string.
191 verbose : `bool`, optional
192 Default is `False`.
193 """
194
195 if name is None:
196 for i, name in enumerate(config.history.keys()):
197 if i > 0:
198 print()
199 print(format(config, name))
200
201 outputs = []
202 for value, stack, label in config.history.get(name, []):
203 output = []
204 for frame in stack:
205 if frame.function in (
206 "__new__",
207 "__set__",
208 "__setattr__",
209 "execfile",
210 "wrapper",
211 ) or os.path.split(frame.filename)[1] in ("argparse.py", "argumentParser.py"):
212 if not verbose:
213 continue
214
215 line = []
216 if writeSourceLine:
217 line.append(
218 [
219 "%s" % ("%s:%d" % (frame.filename, frame.lineno)),
220 "FILE",
221 ]
222 )
223
224 line.append(
225 [
226 frame.content,
227 "TEXT",
228 ]
229 )
230 if False:
231 line.append(
232 [
233 frame.function,
234 "FUNCTION_NAME",
235 ]
236 )
237
238 output.append(line)
239
240 outputs.append([value, output])
241
242 if outputs:
243 # Find the maximum widths of the value and file:lineNo fields.
244 if writeSourceLine:
245 sourceLengths = []
246 for value, output in outputs:
247 sourceLengths.append(max([len(x[0][0]) for x in output]))
248 sourceLength = max(sourceLengths)
249
250 valueLength = len(prefix) + max([len(str(value)) for value, output in outputs])
251
252 # Generate the config history content.
253 msg = []
254 fullname = "%s.%s" % (config._name, name) if config._name is not None else name
255 msg.append(_colorize(re.sub(r"^root\.", "", fullname), "NAME"))
256 for value, output in outputs:
257 line = prefix + _colorize("%-*s" % (valueLength, value), "VALUE") + " "
258 for i, vt in enumerate(output):
259 if writeSourceLine:
260 vt[0][0] = "%-*s" % (sourceLength, vt[0][0])
261
262 output[i] = " ".join([_colorize(v, t) for v, t in vt])
263
264 line += ("\n%*s" % (valueLength + 1, "")).join(output)
265 msg.append(line)
266
267 return "\n".join(msg)
int max
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:174