Python Script Development in own IDE

In our project we want to make use of shared project scripts (see picture below)

I would like to develop the python module in my own IDE, since the built in python script editor does not have an autocomplete feature. Every time I change the python module I am forced to restart the designer otherwise the latest updates do not seem to be included into the module.

I also want to execute the python code of my own module immediately in my own IDE. I managed already to copy the relevant jars into my jython classpath but the execution fails because the jython interpreter does not find the corresponding module for “system.util.getLogger”.

How can it be achieved to develop and execute shared python scripts in the own python IDE?

You pretty much cannot. Or at least, you can (and should) use an IDE to edit scripts and script modules in the python libs folder of your install, but the shared and project scripts in the gateway are stored as serialized resources, not as plain text.
You simply cannot execute scripts outside of Ignition, as all of the system.* script modules depend on the runtime Ignition environment. Even if you worked out all of the right jars to include in your jython classpath, those functions wouldn’t work.
I think Ignition really needs to offer a proper source-controllable text-based backend for gateway and project resources, but that’s not a simple task.

5 Likes

Thank you for your thoughts. I thought already that it would not be possible. It is i good idea to store these python modules in the python libs folder as described in the following blog: http://www.perfectabstractions.com/blog/new-scripting-features-in-ignition-77-part-1#external-python-modules

If the Ignition Designer could also make these own python modules visible in the script editor these would be very helpful.

1 Like

I understand that Ignition its not only python base, (in fact its jython) + sql +expression… if you want to use a IDE, use Sublimetext (ok its not and IDE but its very helpfull) or atom.

Certain things are very easy to mock in an IDE. F.e. the DB functions are largely based on JDBC functionality. To mock tags, you can just use your own dictionaries and set/get methods. A logger can be a simple print, …

When you’ve implemented a few of those basic mock methods, it gets quite easy to test scripts against the Ignition API, without the chance to actually modify data inside Ignition.

Currently we’re even unit-testing our libraries using these mock methods.

We also have a small script to send files from our development environment to the Ignition server (just copying the files and checking for old files to delete). Then Ignition picks up those new files and just runs them. Exactly like saving a shared script.

For some scripts that interact deeply with Ignition, we still need to develop directly into ignition, but most logic can be taken out into external functions on external libraries.

PS. I don’t know why you need to import the PyDataSet and BasicDataset into that script you posted. If you mock the system.dataset.toDataSet and system.dataset.toPyDataSet to return something comparable, you already get a long way. Duck typing is a powerful thing in Python

3 Likes

Interesting, good idea. The PyDataSet and BasicDataset classes have been used in connection with database calls. For these classes I imported already the corresponding jars and jython is able to resolve them.

We developed a module to source control all of our scripts and WebDev resources. As Phil said, you can’t have auto-complete on the system.* functions, but you can with everything else, and it means you can edit everything in a separate IDE and have git version control, which is enough of a win for us.

2 Likes