Make .load_from_config explicit and optional (don't call it from __init__).
authorW. Trevor King <wking@drexel.edu>
Sun, 18 Mar 2012 16:12:46 +0000 (12:12 -0400)
committerW. Trevor King <wking@drexel.edu>
Sun, 18 Mar 2012 16:12:46 +0000 (12:12 -0400)
pyafm/afm.py
pyafm/digital_port.py
pyafm/stepper.py
pyafm/storage.py
pyafm/temperature.py

index dd6d2396a2e2bc95a110949e39a4c8e651654f70..61a036f48ec67197bfbce1782771afb9ea553234 100644 (file)
@@ -81,7 +81,8 @@ class AFM (object):
     >>> config['temperature'] = pyafm.config.TemperatureConfig()
     >>> config['temperature']['name'] = 'test temperature'
 
-    >>> afm = AFM(config=config, devices=devices)
+    >>> afm = AFM(config=config)
+    >>> afm.load_from_config(devices=devices)
     >>> afm.setup_config()
 
     >>> afm.get_temperature()  # doctest: +SKIP
@@ -260,7 +261,8 @@ class AFM (object):
           test temperature
         <HDF5 dataset "units": shape (), type "|S7">
           Celsius
-    >>> afm2 = pyafm.storage.load_afm(filename=filename, devices=devices)
+    >>> afm2 = pyafm.storage.load_afm(filename=filename)
+    >>> afm2.load_from_config(devices=devices)
 
     >>> afm2.get_temperature()  # doctest: +SKIP
     297.37
@@ -274,22 +276,23 @@ class AFM (object):
 
     >>> os.remove(filename)
     """
-    def __init__(self, config, piezo=None, stepper=None, temperature=None,
-                 devices=None):
+    def __init__(self, config, piezo=None, stepper=None, temperature=None):
         self.config = config
         self.piezo = piezo
         self.stepper = stepper
         self.temperature = temperature
-        self.load_from_config(devices=devices)
 
     def load_from_config(self, devices):
         c = self.config  # reduce verbosity
         if self.piezo is None and c['piezo']:
-            self.piezo = _AFMPiezo(config=c['piezo'], devices=devices)
+            self.piezo = _AFMPiezo(config=c['piezo'])
+            self.piezo.load_from_config(devices=devices)
         if self.stepper is None and c['stepper']:
-            self.stepper = _Stepper(config=c['stepper'], devices=devices)
+            self.stepper = _Stepper(config=c['stepper'])
+            self.stepper.load_from_config(devices=devices)
         if self.temperature is None and c['temperature']:
             self.temperature = _Temperature(config=c['temperature'])
+            self.temperature.load_from_config()
 
     def setup_config(self):
         if self.piezo:
index 4c8a401b55656072cba88880dcf8a036a37483ce..508b4e8bb3df7a70b7676bed578517036411bede 100644 (file)
@@ -15,7 +15,8 @@ class DigitalPort (object):
     >>> config['channels'] = [1, 2, 3, 4]
     >>> config['name'] = 'test port'
 
-    >>> port = DigitalPort(config=config, devices=devices)
+    >>> port = DigitalPort(config=config)
+    >>> port.load_from_config(devices=devices)
     >>> port.write_bitfield(13)
     >>> port.write([1, 0, 1, 0])
     >>> port.write_bitfield(0)
@@ -23,10 +24,9 @@ class DigitalPort (object):
     >>> for device in devices:
     ...     device.close()
     """
-    def __init__(self, config, devices=None):
+    def __init__(self, config):
         self.config = config
         self.subdevice = None
-        self.load_from_config(devices=devices)
 
     def load_from_config(self, devices):
         c = self.config  # reduce verbosity
index d82accea0ddadb363c62ad7097612c9410e51668..3c04556c41e116c01cd6879158f955dd4d82370a 100644 (file)
@@ -23,7 +23,8 @@ class Stepper(_stepper.Stepper):
     >>> config['port']['name'] = 'stepper port'
     >>> config['name'] = 'test stepper'
 
-    >>> s = Stepper(config=config, devices=devices)
+    >>> s = Stepper(config=config)
+    >>> s.load_from_config(devices=devices)
     >>> s.position
     0
     >>> s.single_step(1)
@@ -33,10 +34,9 @@ class Stepper(_stepper.Stepper):
     >>> for device in devices:
     ...     device.close()
     """
-    def __init__(self, config, devices=None):
+    def __init__(self, config):
         self.config = config
         self.port = None
-        self.load_from_config(devices=devices)
         c = self.config  # reduce verbosity
         super(Stepper, self).__init__(
             write=self.port.write_bitfield, full_step=c['full-step'],
@@ -46,7 +46,8 @@ class Stepper(_stepper.Stepper):
     def load_from_config(self, devices):
         c = self.config  # reduce verbosity
         if self.port is None:
-            self.port = _DigitalPort(config=c['port'], devices=devices)
+            self.port = _DigitalPort(config=c['port'])
+            self.port.load_from_config(devices=devices)
             self._write = self.port.write_bitfield
         self.full_step = c['full-step']
         self.logic = c['logic']
index b764730cc8ec6de4311c64e218752cb12e4a9f0f..2bce2bbd5b98d93a6775b300455ab22b84dec4c7 100644 (file)
@@ -24,7 +24,7 @@ def save_afm(afm, filename=None, group=None):
     storage = _HDF5_Storage(filename=filename, group=group)
     storage.save(config=afm.config)
 
-def load_afm(filename=None, group=None, devices=None):
+def load_afm(filename=None, group=None):
     if filename is None:
         filename = DEFAULT_FILENAME
     if group is None:
@@ -35,4 +35,4 @@ def load_afm(filename=None, group=None, devices=None):
     config.load()
     _LOG.debug(
         'constructing AFM from configuration:\n{}'.format(config.dump()))
-    return AFM(config=config, devices=devices)
+    return = AFM(config=config)
index 5798a4e8ca1bb623073546a7fb9043ae45e15b7f..a50b448b34d46395480d4915690e290e593fc184 100644 (file)
@@ -30,6 +30,7 @@ class Temperature (object):
 
     >>> config = TemperatureConfig()
     >>> t = Temperature(config=config)
+    >>> t.load_from_config()
     >>> t.get_temperature()  # doctest: +SKIP
     297.37
     >>> t.cleanup()
@@ -38,7 +39,6 @@ class Temperature (object):
         _LOG.debug('setup temperature monitor')
         self.config = config
         self.backend = backend
-        self.load_from_config()
 
     def load_from_config(self):
         c = self.config  # reduce verbosity