Have to close and reopen Sikuli after editing any imported modules

Asked by David Adnitt

----- known problem
----- workaround according to related bug comment #2
---------------------------------------------------------------------------------

I've created a Sikuli script which imports functions from another Sikuli script (MyModule).
Each time I edit the imported script, I have to close and reopen Sikuli IDE so that the changes take effect.

It would be a huge time saver if I could compile or have the imported modules recompile each time I run my script.

Example:

from sikuli.Sikuli import *
from MyModule import *

After making changes to MyModule I have to close and reopen Sikuli IDE so that the changes take effect.

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

known problem and on the list

Revision history for this message
Roman Podolyan (podolyan-roman) said :
#2

For combating this problem with RC3 I used for import code like this:

==========
 # my module import

 sys.path.append("/Users/username/scriptfolder.sikuli/")
 if 'mymodule' in sys.modules:
   del sys.modules['mymodule']
 mymodule = None
 del mymodule
 import mymodule
==========

Didn't test it with 1.0.1 so far, but you can give it a try. Replace path string and module name with yours (of course).

Revision history for this message
Best RaiMan (raimund-hocke) said :
#3

@ Roman
Thanks. forgot about this solution.
But will this work with <from foo import *> too, since the imported names are not purged from the current context?

So will this work too:

if 'mymodule' in sys.modules:
   del sys.modules['mymodule']
 mymodule = None
 del mymodule
 from mymodule import *

the recommended solution

import foo
reload foo
from foo import *

works with the exception that the first time first level code in foo will be executed twice.

Revision history for this message
David Adnitt (dadnitt) said :
#4

Hi,

Thanks for the quick response.

A little adjustment to your solution, there needs to be brackets around 'foo' for the reload.

Example:

import foo
reload (foo)
from foo import *

Otherwise this works great. Solves my problem!

I really appropriate your help and work done on Sikuli.

Thanks,
David