Organizing sikuli scripts into packages.

Asked by Dillon on 2019-01-08

I'm building an automation framework for an application and am attempting to create packages with sikuli scripts with similar structures to normal python packages.



The problem is doesn't recognize the .sikuli files (folders), therefore they don't get added to the package.

I can try to cheat my way around this by adding the following to the file but this causes some other issues where the sikuli modules look in the wrong place for images.

# code

import sys
import os

# Get the base path.
base_path = os.path.dirname(os.path.realpath(__file__))

sys.path.append(os.path.join(os.path.join(base_path, "functions.sikuli")))
import functions

# end

Does Sikuli support package structures similar to python?

Question information

English Edit question
Sikuli Edit question
No assignee Edit question
Solved by:
Last query:
Last reply:
RaiMan (raimund-hocke) said : #1

As long as SikuliX works with .sikuli folders, that contain the .py script file and the images referenced in that script, there will not be an easy solution for that.

Your workaround can be made simpler, since the import in a SikuliX script:
- looks for the script in the folder, the importing script folder is located
- auto-adds the imported .sikuli to the sys.path
- auto-adds the imported .sikuli folder to the imagepath

Be aware:
since all images are looked-up in the imagepath only with their name (without path), you need a naming convention, that avoids name clashes between different scripts.

The only way to just use the plain Python module structure is to separate code and images. As a consequence you only can use the SikuliX IDE for capturing/storing your images and have to use another editor/IDE for your .py files (e.g. IntelliJ's PyCharm).
The one or more image-only .sikuli have to be added to the imagepath when needed.

I have on the list, to support such module structures in the SikuliX IDE.
But this does not help you currently ;-) and will surely take a few months to get ready.

Come back if you run into problems.
In such cases you might contact me directly and send your trials to my mail: sikulix---at---outlook---dot---com.

Dillon (dillonm197) said : #2

Thank you very much for the quick reply RaiMan. Your hard work is greatly appreciated. I thought I'd share that I successful in my attempts of getting python to recognize the modules within the seperate sikuli bundles ny adding each sikuli bundle to the __path__ within each file. Maybe this should be added to the documentation?


from sikuli import *

import os

# Get the base path.
base_path = os.path.dirname(os.path.realpath(__file__))

# Since python packages only recognize .py files
# in the same directory, we need to add the .sikuli
# folders to the __path__. This will add the .py
# files inside them to the package so that we can
# reference them directly.
for dir in os.listdir(base_path):
    if ".sikuli" in dir:
        path = os.path.join(base_path, dir)