LSSTApplications  17.0+11,17.0+34,17.0+56,17.0+57,17.0+59,17.0+7,17.0-1-g377950a+33,17.0.1-1-g114240f+2,17.0.1-1-g4d4fbc4+28,17.0.1-1-g55520dc+49,17.0.1-1-g5f4ed7e+52,17.0.1-1-g6dd7d69+17,17.0.1-1-g8de6c91+11,17.0.1-1-gb9095d2+7,17.0.1-1-ge9fec5e+5,17.0.1-1-gf4e0155+55,17.0.1-1-gfc65f5f+50,17.0.1-1-gfc6fb1f+20,17.0.1-10-g87f9f3f+1,17.0.1-11-ge9de802+16,17.0.1-16-ga14f7d5c+4,17.0.1-17-gc79d625+1,17.0.1-17-gdae4c4a+8,17.0.1-2-g26618f5+29,17.0.1-2-g54f2ebc+9,17.0.1-2-gf403422+1,17.0.1-20-g2ca2f74+6,17.0.1-23-gf3eadeb7+1,17.0.1-3-g7e86b59+39,17.0.1-3-gb5ca14a,17.0.1-3-gd08d533+40,17.0.1-30-g596af8797,17.0.1-4-g59d126d+4,17.0.1-4-gc69c472+5,17.0.1-6-g5afd9b9+4,17.0.1-7-g35889ee+1,17.0.1-7-gc7c8782+18,17.0.1-9-gc4bbfb2+3,w.2019.22
LSSTDataManagementBasePackage
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
lsst.pex.config.listField.ListField Class Reference
Inheritance diagram for lsst.pex.config.listField.ListField:
lsst.pex.config.config.Field

Public Member Functions

def __init__ (self, doc, dtype, default=None, optional=False, listCheck=None, itemCheck=None, length=None, minLength=None, maxLength=None)
 
def validate (self, instance)
 
def __set__ (self, instance, value, at=None, label="assignment")
 
def toDict (self, instance)
 
def rename (self, instance)
 
def freeze (self, instance)
 
def save (self, outfile, instance)
 
def __get__ (self, instance, owner=None, at=None, label="default")
 
def __delete__ (self, instance, at=None, label='deletion')
 

Public Attributes

 listCheck
 
 itemCheck
 
 itemtype
 
 length
 
 minLength
 
 maxLength
 
 dtype
 
 doc
 
 default
 
 check
 
 optional
 
 source
 

Static Public Attributes

 supportedTypes = set((str, bool, float, int, complex))
 

Detailed Description

A configuration field (`~lsst.pex.config.Field` subclass) that contains
a list of values of a specific type.

Parameters
----------
doc : `str`
    A description of the field.
dtype : class
    The data type of items in the list.
default : sequence, optional
    The default items for the field.
optional : `bool`, optional
    Set whether the field is *optional*. When `False`,
    `lsst.pex.config.Config.validate` will fail if the field's value is
    `None`.
listCheck : callable, optional
    A callable that validates the list as a whole.
itemCheck : callable, optional
    A callable that validates individual items in the list.
length : `int`, optional
    If set, this field must contain exactly ``length`` number of items.
minLength : `int`, optional
    If set, this field must contain *at least* ``minLength`` number of
    items.
maxLength : `int`, optional
    If set, this field must contain *no more than* ``maxLength`` number of
    items.

See also
--------
ChoiceField
ConfigChoiceField
ConfigDictField
ConfigField
ConfigurableField
DictField
Field
RangeField
RegistryField

Definition at line 211 of file listField.py.

Constructor & Destructor Documentation

◆ __init__()

def lsst.pex.config.listField.ListField.__init__ (   self,
  doc,
  dtype,
  default = None,
  optional = False,
  listCheck = None,
  itemCheck = None,
  length = None,
  minLength = None,
  maxLength = None 
)

Definition at line 254 of file listField.py.

254  length=None, minLength=None, maxLength=None):
255  if dtype not in Field.supportedTypes:
256  raise ValueError("Unsupported dtype %s" % _typeStr(dtype))
257  if length is not None:
258  if length <= 0:
259  raise ValueError("'length' (%d) must be positive" % length)
260  minLength = None
261  maxLength = None
262  else:
263  if maxLength is not None and maxLength <= 0:
264  raise ValueError("'maxLength' (%d) must be positive" % maxLength)
265  if minLength is not None and maxLength is not None \
266  and minLength > maxLength:
267  raise ValueError("'maxLength' (%d) must be at least"
268  " as large as 'minLength' (%d)" % (maxLength, minLength))
269 
270  if listCheck is not None and not hasattr(listCheck, "__call__"):
271  raise ValueError("'listCheck' must be callable")
272  if itemCheck is not None and not hasattr(itemCheck, "__call__"):
273  raise ValueError("'itemCheck' must be callable")
274 
275  source = getStackFrame()
276  self._setup(doc=doc, dtype=List, default=default, check=None, optional=optional, source=source)
277 
278  self.listCheck = listCheck
279  """Callable used to check the list as a whole.
280  """
281 
282  self.itemCheck = itemCheck
283  """Callable used to validate individual items as they are inserted
284  into the list.
285  """
286 
287  self.itemtype = dtype
288  """Data type of list items.
289  """
290 
291  self.length = length
292  """Number of items that must be present in the list (or `None` to
293  disable checking the list's length).
294  """
295 
296  self.minLength = minLength
297  """Minimum number of items that must be present in the list (or `None`
298  to disable checking the list's minimum length).
299  """
300 
301  self.maxLength = maxLength
302  """Maximum number of items that must be present in the list (or `None`
303  to disable checking the list's maximum length).
304  """
305 
def getStackFrame(relative=0)
Definition: callStack.py:52

Member Function Documentation

◆ __delete__()

def lsst.pex.config.config.Field.__delete__ (   self,
  instance,
  at = None,
  label = 'deletion' 
)
inherited
Delete an attribute from a `lsst.pex.config.Config` instance.

Parameters
----------
instance : `lsst.pex.config.Config`
    The config instance that contains this field.
at : `list` of `lsst.pex.config.callStack.StackFrame`
    The call stack (created by
    `lsst.pex.config.callStack.getCallStack`).
label : `str`, optional
    Event label for the history.

Notes
-----
This is invoked by the owning `~lsst.pex.config.Config` object and
should not be called directly.

Definition at line 551 of file config.py.

551  def __delete__(self, instance, at=None, label='deletion'):
552  """Delete an attribute from a `lsst.pex.config.Config` instance.
553 
554  Parameters
555  ----------
556  instance : `lsst.pex.config.Config`
557  The config instance that contains this field.
558  at : `list` of `lsst.pex.config.callStack.StackFrame`
559  The call stack (created by
560  `lsst.pex.config.callStack.getCallStack`).
561  label : `str`, optional
562  Event label for the history.
563 
564  Notes
565  -----
566  This is invoked by the owning `~lsst.pex.config.Config` object and
567  should not be called directly.
568  """
569  if at is None:
570  at = getCallStack()
571  self.__set__(instance, None, at=at, label=label)
572 
def getCallStack(skip=0)
Definition: callStack.py:169

◆ __get__()

def lsst.pex.config.config.Field.__get__ (   self,
  instance,
  owner = None,
  at = None,
  label = "default" 
)
inherited
Define how attribute access should occur on the Config instance
This is invoked by the owning config object and should not be called
directly

When the field attribute is accessed on a Config class object, it
returns the field object itself in order to allow inspection of
Config classes.

When the field attribute is access on a config instance, the actual
value described by the field (and held by the Config instance) is
returned.

Definition at line 476 of file config.py.

476  def __get__(self, instance, owner=None, at=None, label="default"):
477  """Define how attribute access should occur on the Config instance
478  This is invoked by the owning config object and should not be called
479  directly
480 
481  When the field attribute is accessed on a Config class object, it
482  returns the field object itself in order to allow inspection of
483  Config classes.
484 
485  When the field attribute is access on a config instance, the actual
486  value described by the field (and held by the Config instance) is
487  returned.
488  """
489  if instance is None or not isinstance(instance, Config):
490  return self
491  else:
492  return instance._storage[self.name]
493 

◆ __set__()

def lsst.pex.config.listField.ListField.__set__ (   self,
  instance,
  value,
  at = None,
  label = "assignment" 
)

Definition at line 346 of file listField.py.

346  def __set__(self, instance, value, at=None, label="assignment"):
347  if instance._frozen:
348  raise FieldValidationError(self, instance, "Cannot modify a frozen Config")
349 
350  if at is None:
351  at = getCallStack()
352 
353  if value is not None:
354  value = List(instance, self, value, at, label)
355  else:
356  history = instance._history.setdefault(self.name, [])
357  history.append((value, at, label))
358 
359  instance._storage[self.name] = value
360 
def getCallStack(skip=0)
Definition: callStack.py:169

◆ freeze()

def lsst.pex.config.config.Field.freeze (   self,
  instance 
)
inherited
Make this field read-only (for internal use only).

Parameters
----------
instance : `lsst.pex.config.Config`
    The config instance that contains this field.

Notes
-----
Freezing is only relevant for fields that hold subconfigs. Fields which
hold subconfigs should freeze each subconfig.

**Subclasses should implement this method.**

Definition at line 359 of file config.py.

359  def freeze(self, instance):
360  """Make this field read-only (for internal use only).
361 
362  Parameters
363  ----------
364  instance : `lsst.pex.config.Config`
365  The config instance that contains this field.
366 
367  Notes
368  -----
369  Freezing is only relevant for fields that hold subconfigs. Fields which
370  hold subconfigs should freeze each subconfig.
371 
372  **Subclasses should implement this method.**
373  """
374  pass
375 

◆ rename()

def lsst.pex.config.config.Field.rename (   self,
  instance 
)
inherited
Rename the field in a `~lsst.pex.config.Config` (for internal use
only).

Parameters
----------
instance : `lsst.pex.config.Config`
    The config instance that contains this field.

Notes
-----
This method is invoked by the `lsst.pex.config.Config` object that
contains this field and should not be called directly.

Renaming is only relevant for `~lsst.pex.config.Field` instances that
hold subconfigs. `~lsst.pex.config.Fields` that hold subconfigs should
rename each subconfig with the full field name as generated by
`lsst.pex.config.config._joinNamePath`.

Definition at line 309 of file config.py.

309  def rename(self, instance):
310  """Rename the field in a `~lsst.pex.config.Config` (for internal use
311  only).
312 
313  Parameters
314  ----------
315  instance : `lsst.pex.config.Config`
316  The config instance that contains this field.
317 
318  Notes
319  -----
320  This method is invoked by the `lsst.pex.config.Config` object that
321  contains this field and should not be called directly.
322 
323  Renaming is only relevant for `~lsst.pex.config.Field` instances that
324  hold subconfigs. `~lsst.pex.config.Fields` that hold subconfigs should
325  rename each subconfig with the full field name as generated by
326  `lsst.pex.config.config._joinNamePath`.
327  """
328  pass
329 

◆ save()

def lsst.pex.config.config.Field.save (   self,
  outfile,
  instance 
)
inherited
Save this field to a file (for internal use only).

Parameters
----------
outfile : file-like object
    A writeable field handle.
instance : `Config`
    The `Config` instance that contains this field.

Notes
-----
This method is invoked by the `~lsst.pex.config.Config` object that
contains this field and should not be called directly.

The output consists of the documentation string
(`lsst.pex.config.Field.doc`) formatted as a Python comment. The second
line is formatted as an assignment: ``{fullname}={value}``.

This output can be executed with Python.

Definition at line 417 of file config.py.

417  def save(self, outfile, instance):
418  """Save this field to a file (for internal use only).
419 
420  Parameters
421  ----------
422  outfile : file-like object
423  A writeable field handle.
424  instance : `Config`
425  The `Config` instance that contains this field.
426 
427  Notes
428  -----
429  This method is invoked by the `~lsst.pex.config.Config` object that
430  contains this field and should not be called directly.
431 
432  The output consists of the documentation string
433  (`lsst.pex.config.Field.doc`) formatted as a Python comment. The second
434  line is formatted as an assignment: ``{fullname}={value}``.
435 
436  This output can be executed with Python.
437  """
438  value = self.__get__(instance)
439  fullname = _joinNamePath(instance._name, self.name)
440 
441  # write full documentation string as comment lines (i.e. first character is #)
442  doc = "# " + str(self.doc).replace("\n", "\n# ")
443  if isinstance(value, float) and (math.isinf(value) or math.isnan(value)):
444  # non-finite numbers need special care
445  outfile.write(u"{}\n{}=float('{!r}')\n\n".format(doc, fullname, value))
446  else:
447  outfile.write(u"{}\n{}={!r}\n\n".format(doc, fullname, value))
448 
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:168

◆ toDict()

def lsst.pex.config.listField.ListField.toDict (   self,
  instance 
)
Convert the value of this field to a plain `list`.

`lsst.pex.config.Config.toDict` is the primary user of this method.

Parameters
----------
instance : `lsst.pex.config.Config`
    The config instance that contains this field.

Returns
-------
`list`
    Plain `list` of items, or `None` if the field is not set.

Definition at line 361 of file listField.py.

361  def toDict(self, instance):
362  """Convert the value of this field to a plain `list`.
363 
364  `lsst.pex.config.Config.toDict` is the primary user of this method.
365 
366  Parameters
367  ----------
368  instance : `lsst.pex.config.Config`
369  The config instance that contains this field.
370 
371  Returns
372  -------
373  `list`
374  Plain `list` of items, or `None` if the field is not set.
375  """
376  value = self.__get__(instance)
377  return list(value) if value is not None else None
378 
daf::base::PropertyList * list
Definition: fits.cc:885

◆ validate()

def lsst.pex.config.listField.ListField.validate (   self,
  instance 
)
Validate the field.

Parameters
----------
instance : `lsst.pex.config.Config`
    The config instance that contains this field.

Raises
------
lsst.pex.config.FieldValidationError
    Raised if:

    - The field is not optional, but the value is `None`.
    - The list itself does not meet the requirements of the `length`,
      `minLength`, or `maxLength` attributes.
    - The `listCheck` callable returns `False`.

Notes
-----
Individual item checks (`itemCheck`) are applied when each item is
set and are not re-checked by this method.

Definition at line 306 of file listField.py.

306  def validate(self, instance):
307  """Validate the field.
308 
309  Parameters
310  ----------
311  instance : `lsst.pex.config.Config`
312  The config instance that contains this field.
313 
314  Raises
315  ------
316  lsst.pex.config.FieldValidationError
317  Raised if:
318 
319  - The field is not optional, but the value is `None`.
320  - The list itself does not meet the requirements of the `length`,
321  `minLength`, or `maxLength` attributes.
322  - The `listCheck` callable returns `False`.
323 
324  Notes
325  -----
326  Individual item checks (`itemCheck`) are applied when each item is
327  set and are not re-checked by this method.
328  """
329  Field.validate(self, instance)
330  value = self.__get__(instance)
331  if value is not None:
332  lenValue = len(value)
333  if self.length is not None and not lenValue == self.length:
334  msg = "Required list length=%d, got length=%d" % (self.length, lenValue)
335  raise FieldValidationError(self, instance, msg)
336  elif self.minLength is not None and lenValue < self.minLength:
337  msg = "Minimum allowed list length=%d, got length=%d" % (self.minLength, lenValue)
338  raise FieldValidationError(self, instance, msg)
339  elif self.maxLength is not None and lenValue > self.maxLength:
340  msg = "Maximum allowed list length=%d, got length=%d" % (self.maxLength, lenValue)
341  raise FieldValidationError(self, instance, msg)
342  elif self.listCheck is not None and not self.listCheck(value):
343  msg = "%s is not a valid value" % str(value)
344  raise FieldValidationError(self, instance, msg)
345 

Member Data Documentation

◆ check

lsst.pex.config.config.Field.check
inherited

Definition at line 293 of file config.py.

◆ default

lsst.pex.config.config.Field.default
inherited

Definition at line 289 of file config.py.

◆ doc

lsst.pex.config.config.Field.doc
inherited

Definition at line 280 of file config.py.

◆ dtype

lsst.pex.config.config.Field.dtype
inherited

Definition at line 276 of file config.py.

◆ itemCheck

lsst.pex.config.listField.ListField.itemCheck

Definition at line 282 of file listField.py.

◆ itemtype

lsst.pex.config.listField.ListField.itemtype

Definition at line 287 of file listField.py.

◆ length

lsst.pex.config.listField.ListField.length

Definition at line 291 of file listField.py.

◆ listCheck

lsst.pex.config.listField.ListField.listCheck

Definition at line 278 of file listField.py.

◆ maxLength

lsst.pex.config.listField.ListField.maxLength

Definition at line 301 of file listField.py.

◆ minLength

lsst.pex.config.listField.ListField.minLength

Definition at line 296 of file listField.py.

◆ optional

lsst.pex.config.config.Field.optional
inherited

Definition at line 297 of file config.py.

◆ source

lsst.pex.config.config.Field.source
inherited

Definition at line 304 of file config.py.

◆ supportedTypes

lsst.pex.config.config.Field.supportedTypes = set((str, bool, float, int, complex))
staticinherited

Definition at line 262 of file config.py.


The documentation for this class was generated from the following file: