[pytango] 110/122: Remove metaclasses in the docs

Sandor Bodo-Merle sbodomerle-guest at moszumanska.debian.org
Thu Sep 28 19:18:24 UTC 2017


This is an automated email from the git hooks/post-receive script.

sbodomerle-guest pushed a commit to tag v9.2.1
in repository pytango.

commit 64c8cc9dab4915216d79a69a0c4636287346bdb4
Author: Vincent Michel <vincent.michel at maxlab.lu.se>
Date:   Mon Jan 16 18:11:59 2017 +0100

    Remove metaclasses in the docs
---
 doc/_static/PowerSupplyDS.py | 24 ++++++--------
 doc/_templates/index.html    |  1 -
 doc/howto.rst                | 57 ++++++++++----------------------
 doc/server_api/server.rst    | 79 +++++++++++++++++++-------------------------
 4 files changed, 62 insertions(+), 99 deletions(-)

diff --git a/doc/_static/PowerSupplyDS.py b/doc/_static/PowerSupplyDS.py
index 8dd6fd7..ca42015 100644
--- a/doc/_static/PowerSupplyDS.py
+++ b/doc/_static/PowerSupplyDS.py
@@ -7,23 +7,21 @@ import time
 import numpy
 
 from tango import AttrQuality, AttrWriteType, DispLevel, DevState, DebugIt
-from tango.server import Device, DeviceMeta, attribute, command, pipe, run
-from tango.server import device_property
+from tango.server import Device, attribute, command, pipe, device_property
 
 
 class PowerSupply(Device):
-    __metaclass__ = DeviceMeta
 
     voltage = attribute(label="Voltage", dtype=float,
                         display_level=DispLevel.OPERATOR,
                         access=AttrWriteType.READ,
-                        unit="V",format="8.4f",
+                        unit="V", format="8.4f",
                         doc="the power supply voltage")
 
     current = attribute(label="Current", dtype=float,
                         display_level=DispLevel.EXPERT,
                         access=AttrWriteType.READ_WRITE,
-                        unit="A",format="8.4f",
+                        unit="A", format="8.4f",
                         min_value=0.0, max_value=8.5,
                         min_alarm=0.1, max_alarm=8.4,
                         min_warning=0.5, max_warning=8.0,
@@ -39,16 +37,16 @@ class PowerSupply(Device):
 
     host = device_property(dtype=str)
     port = device_property(dtype=int, default_value=9788)
-    
+
     def init_device(self):
         Device.init_device(self)
         self.__current = 0.0
         self.set_state(DevState.STANDBY)
-    
+
     def read_voltage(self):
         self.info_stream("read_voltage(%s, %d)", self.host, self.port)
         return 9.99, time.time(), AttrQuality.ATTR_WARNING
-    
+
     def get_current(self):
         return self.__current
 
@@ -76,12 +74,12 @@ class PowerSupply(Device):
         self.set_state(DevState.OFF)
 
     @command(dtype_in=float, doc_in="Ramp target current",
-             dtype_out=bool, doc_out="True if ramping went well, False otherwise")
+             dtype_out=bool, doc_out="True if ramping went well, "
+             "False otherwise")
     def Ramp(self, target_current):
         # should do the ramping
         return True
-    
-    
-if __name__ == "__main__":
-    run([PowerSupply])
 
+
+if __name__ == "__main__":
+    PowerSupply.run_server()
diff --git a/doc/_templates/index.html b/doc/_templates/index.html
index b71ff99..8191519 100644
--- a/doc/_templates/index.html
+++ b/doc/_templates/index.html
@@ -87,7 +87,6 @@
 
 
 <span class="k">class</span> <span class="nc">Clock</span><span class="p">(</span><span class="n">Device</span><span class="p">):</span>
-    <span class="n">__metaclass__</span> <span class="o">=</span> <span class="n">DeviceMeta</span>
 
     <span class="n">time</span> <span class="o">=</span> <span class="n">attribute</span><span class="p">()</span>
 
diff --git a/doc/howto.rst b/doc/howto.rst
index 57596a8..01d99b6 100644
--- a/doc/howto.rst
+++ b/doc/howto.rst
@@ -307,13 +307,10 @@ high level API
    :linenos:
 
     import time
-    from tango.server import run
-    from tango.server import Device, DeviceMeta
-    from tango.server import attribute, command, pipe
+    from tango.server import Device, attribute, command, pipe
 
 
     class Clock(Device):
-        __metaclass__ = DeviceMeta
 
         @attribute
         def time(self):
@@ -332,37 +329,32 @@ high level API
 
 
     if __name__ == "__main__":
-        run([Clock])
+        Clock.run_server()
 
 
-**line 2-4**
+**line 2**
     import the necessary symbols
 
-**line 7**
+**line 5**
     tango device class definition. A Tango device must inherit from
     :class:`tango.server.Device`
 
-**line 8**
-    mandatory *magic* line. A Tango device must define the metaclass as
-    :class:`tango.server.DeviceClass`. This has to be done due to a limitation
-    on boost-python
-
-**line 10-12**
+**line 7-9**
     definition of the *time* attribute. By default, attributes are double, scalar,
     read-only. Check the :class:`~tango.server.attribute` for the complete
     list of attribute options.
 
-**line 14-16**
+**line 11-13**
     the method *strftime* is exported as a Tango command. In receives a string
     as argument and it returns a string. If a method is to be exported as a
     Tango command, it must be decorated as such with the
     :func:`~tango.server.command` decorator
 
-**line 18-23**
+**line 15-20**
     definition of the *info* pipe. Check the :class:`~tango.server.pipe`
     for the complete list of pipe options.
 
-**line 28**
+**line 24**
     start the Tango run loop. The mandatory argument is a list of python classes
     that are to be exported as Tango classes. Check :func:`~tango.server.run`
     for the complete list of options
@@ -383,13 +375,12 @@ using the high level API. The example contains:
     from time import time
     from numpy.random import random_sample
 
-    from tango import AttrQuality, AttrWriteType, DispLevel, run
-    from tango.server import Device, DeviceMeta, attribute, command
+    from tango import AttrQuality, AttrWriteType, DispLevel
+    from tango.server import Device, attribute, command
     from tango.server import class_property, device_property
 
 
     class PowerSupply(Device):
-        __metaclass__ = DeviceMeta
 
         current = attribute(label="Current", dtype=float,
                             display_level=DispLevel.EXPERT,
@@ -428,17 +419,7 @@ using the high level API. The example contains:
 
 
     if __name__ == "__main__":
-        run([PowerSupply])
-
-
-.. note::
-    the ``__metaclass__`` statement is mandatory due to a limitation in the
-    *boost-python* library used by PyTango.
-
-    If you are using python 3 you can write instead::
-
-        class PowerSupply(Device, metaclass=DeviceMeta)
-            pass
+        PowerSupply.run_server()
 
 .. _logging:
 
@@ -573,29 +554,27 @@ separated python files: A :class:`PLC` class in a :file:`PLC.py`::
 
     # PLC.py
 
-    from tango.server import Device, DeviceMeta, run
+    from tango.server import Device
 
     class PLC(Device):
-        __metaclass__ = DeviceMeta
 
         # bla, bla my PLC code
 
     if __name__ == "__main__":
-        run([PLC])
+        PLC.run_server()
 
 ... and a :class:`IRMirror` in a :file:`IRMirror.py`::
 
     # IRMirror.py
 
-    from tango.server import Device, DeviceMeta, run
+    from tango.server import Device
 
     class IRMirror(Device):
-        __metaclass__ = DeviceMeta
 
         # bla, bla my IRMirror code
 
     if __name__ == "__main__":
-        run([IRMirror])
+        IRMirror.run_server()
 
 You want to create a Tango server called `PLCMirror` that is able to contain
 devices from both PLC and IRMirror classes. All you have to do is write
@@ -683,10 +662,9 @@ point attribute with the specified name::
 
 
     from tango import Util, Attr
-    from tango.server import DeviceMeta, Device, command
+    from tango.server import Device, command
 
     class MyDevice(Device):
-    	__metaclass__ = DeviceMeta
 
 	@command(dtype_in=str)
         def CreateFloatAttribute(self, attr_name):
@@ -730,10 +708,9 @@ creates a device of some arbitrary class (the example assumes the tango commands
 with two strings. No error processing was done on the code for simplicity sake)::
 
     from tango import Util
-    from tango.server import DeviceMeta, Device, command
+    from tango.server import Device, command
 
     class MyDevice(Device):
-    	__metaclass__ = DeviceMeta
 
 	@command(dtype_in=[str])
         def CreateDevice(self, pars):
diff --git a/doc/server_api/server.rst b/doc/server_api/server.rst
index 6c5094d..f44ffe6 100644
--- a/doc/server_api/server.rst
+++ b/doc/server_api/server.rst
@@ -25,15 +25,14 @@ device server.
 
 Here is a simple example on how to write a *Clock* device server using the
 high level API::
-    
+
     import time
     from tango.server import run
-    from tango.server import Device, DeviceMeta
-    from tango.server import attribute, command   
+    from tango.server import Device
+    from tango.server import attribute, command
 
 
     class Clock(Device):
-        __metaclass__ = DeviceMeta
 
         time = attribute()
 
@@ -65,12 +64,11 @@ using the high level API. The example contains:
     from time import time
     from numpy.random import random_sample
 
-    from tango import AttrQuality, AttrWriteType, DispLevel, server_run
-    from tango.server import Device, DeviceMeta, attribute, command
+    from tango import AttrQuality, AttrWriteType, DispLevel
+    from tango.server import Device, attribute, command
     from tango.server import class_property, device_property
 
     class PowerSupply(Device):
-        __metaclass__ = DeviceMeta
 
         voltage = attribute()
 
@@ -83,11 +81,11 @@ using the high level API. The example contains:
                             min_warning=0.5, max_warning=8.0,
                             fget="get_current", fset="set_current",
                             doc="the power supply current")
-    
+
         noise = attribute(label="Noise", dtype=((float,),),
                           max_dim_x=1024, max_dim_y=1024,
                           fget="get_noise")
- 
+
         host = device_property(dtype=str)
         port = class_property(dtype=int, default_value=9788)
 
@@ -97,10 +95,10 @@ using the high level API. The example contains:
 
         def get_current(self):
             return 2.3456, time(), AttrQuality.ATTR_WARNING
-    
+
         def set_current(self, current):
             print("Current set to %f" % current)
-    
+
         def get_noise(self):
             return random_sample((1024, 1024))
 
@@ -109,19 +107,10 @@ using the high level API. The example contains:
             print("Ramping up...")
 
     if __name__ == "__main__":
-        server_run((PowerSupply,))
+        PowerSupply.run_server()
 
 *Pretty cool, uh?*
 
-.. note::
-    the ``__metaclass__`` statement is mandatory due to a limitation in the
-    *boost-python* library used by PyTango.
-    
-    If you are using python 3 you can write instead::
-        
-        class PowerSupply(Device, metaclass=DeviceMeta)
-            pass
-
 .. _pytango-hlapi-datatypes:
 
 .. rubric:: Data types
@@ -137,9 +126,9 @@ attribute you have several possibilities:
 #. :obj:`int`
 #. 'int'
 #. 'int32'
-#. 'integer' 
+#. 'integer'
 #. :obj:`tango.CmdArgType.DevLong`
-#. 'DevLong' 
+#. 'DevLong'
 #. :obj:`numpy.int32`
 
 To define a *SPECTRUM* attribute simply wrap the scalar data type in any
@@ -159,15 +148,15 @@ python sequence of sequences:
 Below is the complete table of equivalences.
 
 ========================================  ========================================
-dtype argument                            converts to tango type                             
+dtype argument                            converts to tango type
 ========================================  ========================================
  ``None``                                  ``DevVoid``
  ``'None'``                                ``DevVoid``
  ``DevVoid``                               ``DevVoid``
  ``'DevVoid'``                             ``DevVoid``
 
- ``DevState``                              ``DevState``                           
- ``'DevState'``                            ``DevState``                           
+ ``DevState``                              ``DevState``
+ ``'DevState'``                            ``DevState``
 
  :py:obj:`bool`                            ``DevBoolean``
  ``'bool'``                                ``DevBoolean``
@@ -211,20 +200,20 @@ dtype argument                            converts to tango type
  ``DevLong64``                             ``DevLong64``
  ``'DevLong64'``                           ``DevLong64``
  :py:obj:`numpy.int64`                     ``DevLong64``
- 
+
  ``'uint64'``                              ``DevULong64``
  ``DevULong64``                            ``DevULong64``
  ``'DevULong64'``                          ``DevULong64``
  :py:obj:`numpy.uint64`                    ``DevULong64``
 
- ``DevInt``                                ``DevInt``                             
- ``'DevInt'``                              ``DevInt``                             
- 
+ ``DevInt``                                ``DevInt``
+ ``'DevInt'``                              ``DevInt``
+
  ``'float32'``                             ``DevFloat``
  ``DevFloat``                              ``DevFloat``
  ``'DevFloat'``                            ``DevFloat``
  :py:obj:`numpy.float32`                   ``DevFloat``
- 
+
  :py:obj:`float`                           ``DevDouble``
  ``'double'``                              ``DevDouble``
  ``'float'``                               ``DevDouble``
@@ -232,14 +221,14 @@ dtype argument                            converts to tango type
  ``DevDouble``                             ``DevDouble``
  ``'DevDouble'``                           ``DevDouble``
  :py:obj:`numpy.float64`                   ``DevDouble``
- 
+
  :py:obj:`str`                             ``DevString``
  ``'str'``                                 ``DevString``
  ``'string'``                              ``DevString``
  ``'text'``                                ``DevString``
  ``DevString``                             ``DevString``
  ``'DevString'``                           ``DevString``
- 
+
  :py:obj:`bytearray`                       ``DevEncoded``
  ``'bytearray'``                           ``DevEncoded``
  ``'bytes'``                               ``DevEncoded``
@@ -248,40 +237,40 @@ dtype argument                            converts to tango type
 
  ``DevVarBooleanArray``                    ``DevVarBooleanArray``
  ``'DevVarBooleanArray'``                  ``DevVarBooleanArray``
- 
+
  ``DevVarCharArray``                       ``DevVarCharArray``
  ``'DevVarCharArray'``                     ``DevVarCharArray``
- 
+
  ``DevVarShortArray``                      ``DevVarShortArray``
  ``'DevVarShortArray'``                    ``DevVarShortArray``
- 
+
  ``DevVarLongArray``                       ``DevVarLongArray``
  ``'DevVarLongArray'``                     ``DevVarLongArray``
- 
+
  ``DevVarLong64Array``                     ``DevVarLong64Array``
  ``'DevVarLong64Array'``                   ``DevVarLong64Array``
- 
+
  ``DevVarULong64Array``                    ``DevVarULong64Array``
  ``'DevVarULong64Array'``                  ``DevVarULong64Array``
- 
+
  ``DevVarFloatArray``                      ``DevVarFloatArray``
  ``'DevVarFloatArray'``                    ``DevVarFloatArray``
- 
+
  ``DevVarDoubleArray``                     ``DevVarDoubleArray``
  ``'DevVarDoubleArray'``                   ``DevVarDoubleArray``
- 
+
  ``DevVarUShortArray``                     ``DevVarUShortArray``
  ``'DevVarUShortArray'``                   ``DevVarUShortArray``
- 
+
  ``DevVarULongArray``                      ``DevVarULongArray``
  ``'DevVarULongArray'``                    ``DevVarULongArray``
- 
+
  ``DevVarStringArray``                     ``DevVarStringArray``
  ``'DevVarStringArray'``                   ``DevVarStringArray``
- 
+
  ``DevVarLongStringArray``                 ``DevVarLongStringArray``
  ``'DevVarLongStringArray'``               ``DevVarLongStringArray``
- 
+
  ``DevVarDoubleStringArray``               ``DevVarDoubleStringArray``
  ``'DevVarDoubleStringArray'``             ``DevVarDoubleStringArray``
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/pytango.git



More information about the debian-science-commits mailing list