← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #232998]: Eclipse and Sikuli IDE are inconsistent in some places

 

Question #232998 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/232998

    Status: Open => Answered

RaiMan proposed the following answer:
according to the Python rules (language level 2.5), a module to be
imported must be found in one of the folders contained in sys.path at
time of import.

This is simulated for .sikuli folders with respect to the contained .py
files by a Sikuli plugin to the Jython import support
(SikuliImporter.py) which is initialized at startup (from sikuli import
*). The internal magic is, that not only the sys.path is managed
accordingly, but also the image path, so no handling of bundlepath is
needed in this case.

Python supports having a folder structure, that in turn contains
modules, that can be imported using the dotted notation. Only the top
folder must be in sys.path.

# example
main.py or main.sikuli
subsfolder
    sub1.py
    sub2.py
    subsubsfolder
        subsub1.py
        subsub2.py

so in main you could say:
import subsfolder.sub1
import subsfolder.subsubsfolder.subsub2

running main.py with "from sikuli import *" or main.sikuli this will
work, since the Sikuli import support looks in the same directory.

*** Now there is one important prereq for this to work: 
every folder in such a tree MUST have an __init__.py, which might be empty.

So the finally working structure is:

main.py or main.sikuli
subsfolder
    __init__.py
    sub1.py
    sub2.py
    subsubsfolder
        __init__.py
        subsub1.py
        subsub2.py

Besides being a signal for a module structure, __init__.py can contain
code, that supports some features of this folder and is once run at
import (or again at reload())

You might as well put additional .sikuli folders into this structure,
but to make them importable, currently their parent folder must be in
sys.path at time of import. I have on the list, to support such mixed
structures via SikuliImporter.

Why this works in Eclipse without the __init__.py I cannot tell you. But
with them it should work too.

*** Looking now at step 2 of your concept:
Everything, that your users should access via Sikuli-IDE GUI, must be in a folder .sikuli having a .py with the same name and might be additional images (to be able to edit standalone .py files with Sikuli IDE is on the list).

To just run the main.sikuli or main.py, you only need sikuli-script.jar:

java -jar sikuli-script.jar -r main.sikuli

or

java -cp sikuli-script.jar org.python.util.jython main.py

So the user of your package only needs sikuli-script.jar or sikuli-ide.jar. 
version 1.0.1 will make all this much easier. 

In any case: the challenge is the organization of the images needed for
the find operations.

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.