Sardana 2.8 - macro is not visible after restarting sardana.

Hello,

There is a problem with macro, when macro file starts with letter 'A' and imports something from another file from the same location (macros directory). See below for more details.

There are two files in macros directory:
AuxilliaryFunctions.py and AMacro.py. First contains only function Func1(), second is a macro with content:
from sardana.macroserver.macro import *
from AuxilliaryFunctions import *
class AMacro(Macro):
def run(self):
self.output(Func1())


We added this macro using command "SetMacroCode". Macro is visible until sardana device is turned off and turned on again.


I noticed that there are two solutions to make macro visible again:
  • remove import in AMacro.py (line: 'from AuxilliaryFunctions import *'),
  • change file name to one with no letter 'A' at the beginnig (without changing class name in file).
This is a little strange, because both files are correct and both generate .pyc files after sardana was turned on again. Could You tell us what cause this, and how to fix it? Thanks for helping us.

We use sardana ver. 2.8 - the latest version available for python 2.7.
Edited 2 weeks ago
Hi Piotr,

I have tried your case and I was not able to reproduce your problem. I was using Sardana 2.8.0. What I did was:

  1. Create Sardana server instance called tatarczyk
  2. Set MacroPath to /home/zreszela/tmp/tatarczyk
  3. Restarted the Sardana server
  4. Created AuxilliaryFunctions.py module in the /home/zreszela/tmp/tatarczyk directory with one funciton Func1 which just prints some text
  5. Executed SetMacroCode command on the MacroServer device proxy inserting the said macro to the /home/zreszela/tmp/tatarczyk/AMacro.py module.
  6. Successfully executed the AMacro macro
  7. Restarted the Sardana server
  8. Again successfully executed the AMacro macro

But, it does not surprise me that it fails to you. The macro loading mechanism is a little bit fragile. If I remember correctly it will get a list of all modules in the MacroPath and import them manually using the imp.load_module function. The order of importing this modules in not easily known. For the cases like you describe we introduced the PythonPath property. Could you set it to the same directory as the MacroPath. I think this should solve your issue.

Note that we are working on refactoring the macro plugin system to avoid this kind of issues in SEP19.

Also, I recommend you to report your issues directly on the Sardana project on GitHub. These will be more visible to the Sardana users and developers.

Thanks for the comprehensive report with all the details!

Cheers!
 
Register or login to create to post a reply.