Hi,
running the following macro
from sardana.macroserver.macro import macro from sardana.macroserver.macros.env import lsenv import sys @macro() def mac_test(self): cmac, _ = self.createMacro("lsenv") gmac = self.getMacroServer().macro_manager.getMacro('lsenv').klass self.output("MANAGER_MACRO: %s, %s" % ( sys.modules[gmac.__module__].__file__, gmac)) self.output("MACRO_CREATED: %s, %s" % ( sys.modules[type(cmac).__module__].__file__, type(cmac))) self.output("MACRO_IMPORTED: %s, %s" % ( sys.modules[lsenv.__module__].__file__, lsenv)) self.output("\nMACRO_CREATED is an instance of MACRO_IMPORTED class: %s" % isinstance(cmac, lsenv) ) self.output("\nMANAGER_MACRO is an instance of MACRO_IMPORTED class: %s" % isinstance(gmac, lsenv) )
I get the following output
MANAGER_MACRO: /usr/lib/python2.7/dist-packages/sardana/macroserver/macros/env.pyc, <class 'env.lsenv'> MACRO_CREATED: /usr/lib/python2.7/dist-packages/sardana/macroserver/macros/env.pyc, <class 'env.lsenv'> MACRO_IMPORTED: /usr/lib/python2.7/dist-packages/sardana/macroserver/macros/env.pyc, <class 'sardana.macroserver.macros.env.lsenv'> MACRO_CREATED is an instance of MACRO_IMPORTED class: False MANAGER_MACRO is an instance of MACRO_IMPORTED class: False
So it means that macros get from MacroManager or created by createMacro command are not instances of the corresponding imported macro classes. This is misleading and could have other consequences in more complicated macros. It is related to the breaking python rules by Sardana (ticket #401), i.e. in sys.modules dictionary we the same module put twice under two different keys.
The important think is that sardana.macroserver.macros (containing __init__.py
file).
Otherwise, when a macro is not a package, in the last two lines of examples we get True, what is expected. (In this case on has to add PYTHONPATH of env manually, e.g by PythonPath macroserver properties).
Those two different behaviors are even more misleading.
A quick fix for this issue would be to remove all __init__.py
files from macro directories.
A better solution would be to fix sardana manage and use it with long module names (i.e. with packages) (ticket #401).
This bug can be also shown for controllers.
Cheers,
Jan