← Back to team overview

sikuli-driver team mailing list archive

[Question #210973]: Sikuli code organization / code reuse

 

New question #210973 on Sikuli:
https://answers.launchpad.net/sikuli/+question/210973

I am trying to create a good structure for Sikuli code to use across many tests on many projects. I am trying to organize my code as follows:

parent/
parent/project1
parent/project1/(project1 .sikuli files here)
parent/shared
parent/shared/(shared .sikuli files here)

In order to do this, there needs to be a way to either:
1) Package the project at the parent level
2) Import the other modules dynamically

I couldn't find a way to create a sikuli package, so I went with method #2, which is fine. The problem with method #2 is that you need to import all of the folders dynamically into os.path for _every_ file. This is really a big problem. Also, I'm currently statically getting the directories by using getBundlePath(). This is another problem because you have to update this anytime you add another folder to the directory structure.

In other words, In order to import other modules dynamically, I need to include something similar to the following code at the top of _each_ .py file.

import os
project1Path = os.path.dirname(getBundlePath()) + "\.." + "\project1Path"
if not project1Path in sys.path: sys.path.append(project1Path)
sharedPath = os.path.dirname(getBundlePath()) + "\.." + "\shared"
if not sharedPath in sys.path: sys.path.append(sharedPath)

Is there a way that I can:
1) Create one __init__.py file (or similar) to preload all of the modules required so that I do not have to repeat the previous code at the top of _every_ file?
2) Recursively get all of the folders under the parent directory and import all the .sikuli modules so I do not have to update the __init__ file every time there is a change to the directory structure?

Alternatively, is there a way to create a package of .sikuli files?

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