LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Public Member Functions | Public Attributes | Private Member Functions | List of all members
lsst.pex.config.configurableField.ConfigurableField Class Reference
Inheritance diagram for lsst.pex.config.configurableField.ConfigurableField:

Public Member Functions

def validateTarget
 
def __init__
 
def __get__
 
def __set__
 
def rename
 
def save
 
def freeze
 
def toDict
 
def validate
 
def __deepcopy__
 

Public Attributes

 target
 
 ConfigClass
 

Private Member Functions

def __getOrMake
 
def _compare
 

Detailed Description

A variant of a ConfigField which has a known configurable target

Behaves just like a ConfigField except that it can be 'retargeted' to point
at a different configurable. Further you can 'apply' to construct a fully
configured configurable.

Definition at line 139 of file configurableField.py.

Constructor & Destructor Documentation

def lsst.pex.config.configurableField.ConfigurableField.__init__ (   self,
  doc,
  target,
  ConfigClass = None,
  default = None,
  check = None 
)
@param target is the configurable target. Must be callable, and the first
parameter will be the value of this field
@param ConfigClass is the class of Config object expected by the target.
If not provided by target.ConfigClass it must be provided explicitly in this argument

Definition at line 166 of file configurableField.py.

167  def __init__(self, doc, target, ConfigClass=None, default=None, check=None):
168  """
169  @param target is the configurable target. Must be callable, and the first
170  parameter will be the value of this field
171  @param ConfigClass is the class of Config object expected by the target.
172  If not provided by target.ConfigClass it must be provided explicitly in this argument
173  """
174  ConfigClass = self.validateTarget(target, ConfigClass)
175 
176  if default is None:
177  default=ConfigClass
178  if default != ConfigClass and type(default) != ConfigClass:
179  raise TypeError("'default' is of incorrect type %s. Expected %s"%\
180  (_typeStr(default), _typeStr(ConfigClass)))
181 
182  source = traceback.extract_stack(limit=2)[0]
183  self._setup(doc=doc, dtype=ConfigurableInstance, default=default, \
184  check=check, optional=False, source=source)
185  self.target = target
186  self.ConfigClass = ConfigClass

Member Function Documentation

def lsst.pex.config.configurableField.ConfigurableField.__deepcopy__ (   self,
  memo 
)
Customize deep-copying, because we always want a reference to the original typemap.

WARNING: this must be overridden by subclasses if they change the constructor signature!

Definition at line 259 of file configurableField.py.

260  def __deepcopy__(self, memo):
261  """Customize deep-copying, because we always want a reference to the original typemap.
262 
263  WARNING: this must be overridden by subclasses if they change the constructor signature!
264  """
265  return type(self)(doc=self.doc, target=self.target, ConfigClass=self.ConfigClass,
266  default=copy.deepcopy(self.default))
def lsst.pex.config.configurableField.ConfigurableField.__get__ (   self,
  instance,
  owner = None,
  at = None,
  label = "default" 
)

Definition at line 196 of file configurableField.py.

197  def __get__(self, instance, owner=None, at=None, label="default"):
198  if instance is None or not isinstance(instance, Config):
199  return self
200  else:
201  return self.__getOrMake(instance, at=at, label=label)
def lsst.pex.config.configurableField.ConfigurableField.__getOrMake (   self,
  instance,
  at = None,
  label = "default" 
)
private

Definition at line 187 of file configurableField.py.

188  def __getOrMake(self, instance, at=None, label="default"):
189  value = instance._storage.get(self.name, None)
190  if value is None:
191  if at is None:
192  at = traceback.extract_stack()[:-2]
193  value = ConfigurableInstance(instance, self, at=at, label=label)
194  instance._storage[self.name]=value
195  return value
def lsst.pex.config.configurableField.ConfigurableField.__set__ (   self,
  instance,
  value,
  at = None,
  label = "assignment" 
)

Definition at line 202 of file configurableField.py.

203  def __set__(self, instance, value, at=None, label="assignment"):
204  if instance._frozen:
205  raise FieldValidationError(self, instance, "Cannot modify a frozen Config")
206  if at is None:
207  at = traceback.extract_stack()[:-1]
208  oldValue = self.__getOrMake(instance, at=at)
209 
210  if isinstance(value, ConfigurableInstance):
211  oldValue.retarget(value.target, value.ConfigClass, at, label)
212  oldValue.update(__at=at, __label=label, **value._storage)
213  elif type(value)==oldValue._ConfigClass:
214  oldValue.update(__at=at, __label=label, **value._storage)
215  elif value == oldValue.ConfigClass:
216  value = oldValue.ConfigClass()
217  oldValue.update(__at=at, __label=label, **value._storage)
218  else:
219  msg = "Value %s is of incorrect type %s. Expected %s" %\
220  (value, _typeStr(value), _typeStr(oldValue.ConfigClass))
221  raise FieldValidationError(self, instance, msg)
def lsst.pex.config.configurableField.ConfigurableField._compare (   self,
  instance1,
  instance2,
  shortcut,
  rtol,
  atol,
  output 
)
private
Helper function for Config.compare; used to compare two fields for equality.

@param[in] instance1  LHS Config instance to compare.
@param[in] instance2  RHS Config instance to compare.
@param[in] shortcut   If True, return as soon as an inequality is found.
@param[in] rtol       Relative tolerance for floating point comparisons.
@param[in] atol       Absolute tolerance for floating point comparisons.
@param[in] output     If not None, a callable that takes a string, used (possibly repeatedly)
              to report inequalities.

Floating point comparisons are performed by numpy.allclose; refer to that for details.

Definition at line 267 of file configurableField.py.

268  def _compare(self, instance1, instance2, shortcut, rtol, atol, output):
269  """Helper function for Config.compare; used to compare two fields for equality.
270 
271  @param[in] instance1 LHS Config instance to compare.
272  @param[in] instance2 RHS Config instance to compare.
273  @param[in] shortcut If True, return as soon as an inequality is found.
274  @param[in] rtol Relative tolerance for floating point comparisons.
275  @param[in] atol Absolute tolerance for floating point comparisons.
276  @param[in] output If not None, a callable that takes a string, used (possibly repeatedly)
277  to report inequalities.
278 
279  Floating point comparisons are performed by numpy.allclose; refer to that for details.
280  """
281  c1 = getattr(instance1, self.name)._value
282  c2 = getattr(instance2, self.name)._value
283  name = getComparisonName(
284  _joinNamePath(instance1._name, self.name),
285  _joinNamePath(instance2._name, self.name)
286  )
287  return compareConfigs(name, c1, c2, shortcut=shortcut, rtol=rtol, atol=atol, output=output)
288 
def lsst.pex.config.configurableField.ConfigurableField.freeze (   self,
  instance 
)

Definition at line 243 of file configurableField.py.

244  def freeze(self, instance):
245  value = self.__getOrMake(instance)
246  value.freeze()
def lsst.pex.config.configurableField.ConfigurableField.rename (   self,
  instance 
)

Definition at line 222 of file configurableField.py.

223  def rename(self, instance):
224  fullname = _joinNamePath(instance._name, self.name)
225  value = self.__getOrMake(instance)
226  value._rename(fullname)
def lsst.pex.config.configurableField.ConfigurableField.save (   self,
  outfile,
  instance 
)

Definition at line 227 of file configurableField.py.

228  def save(self, outfile, instance):
229  fullname = _joinNamePath(instance._name, self.name)
230  value = self.__getOrMake(instance)
231  target= value.target
232 
233  if target != self.target:
234  #not targeting the field-default target.
235  #save target information
236  ConfigClass = value.ConfigClass
237  for module in set([target.__module__, ConfigClass.__module__]):
238  print >> outfile, "import %s" % module
239  print >> outfile, "%s.retarget(target=%s, ConfigClass=%s)"%\
240  (fullname, _typeStr(target), _typeStr(ConfigClass))
241  #save field values
242  value._save(outfile)
def lsst.pex.config.configurableField.ConfigurableField.toDict (   self,
  instance 
)

Definition at line 247 of file configurableField.py.

248  def toDict(self, instance):
249  value = self.__get__(instance)
250  return value.toDict()
def lsst.pex.config.configurableField.ConfigurableField.validate (   self,
  instance 
)

Definition at line 251 of file configurableField.py.

252  def validate(self, instance):
253  value = self.__get__(instance)
254  value.validate()
255 
256  if self.check is not None and not self.check(value):
257  msg = "%s is not a valid value"%str(value)
258  raise FieldValidationError(self, instance, msg)
def lsst.pex.config.configurableField.ConfigurableField.validateTarget (   self,
  target,
  ConfigClass 
)

Definition at line 150 of file configurableField.py.

151  def validateTarget(self, target, ConfigClass):
152  if ConfigClass is None:
153  try:
154  ConfigClass=target.ConfigClass
155  except:
156  raise AttributeError("'target' must define attribute 'ConfigClass'")
157  if not issubclass(ConfigClass, Config):
158  raise TypeError("'ConfigClass' is of incorrect type %s."\
159  "'ConfigClass' must be a subclass of Config"%_typeStr(ConfigClass))
160  if not hasattr(target, '__call__'):
161  raise ValueError ("'target' must be callable")
162  if not hasattr(target, '__module__') or not hasattr(target, '__name__'):
163  raise ValueError("'target' must be statically defined" \
164  "(must have '__module__' and '__name__' attributes)")
165  return ConfigClass

Member Data Documentation

lsst.pex.config.configurableField.ConfigurableField.ConfigClass

Definition at line 185 of file configurableField.py.

lsst.pex.config.configurableField.ConfigurableField.target

Definition at line 184 of file configurableField.py.


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