Page 1 of 2

Reload Libraries and Attachments

PostPosted: Wed Jun 19, 2019 9:33 am
by Mark
I was successful (thanks to the excellent example documentation!) in creating a python attachment and making calls to it. It's in the "/Library/Python/2.7/site-packages/" folder. Two questions:

1.
Is that where is must reside? I'd prefer to keep it in Indigo's folder, as I did with AppleScript attachments.

2.
When I edit the code, and select the "Reload Libraries and Attachments" menu item (either from the server's computer or the client computer), the new code does not take affect. I have to actually restart the Indigo server, which, as you can imagine, really slows down development. Am I doing something wrong? Or does that documentation online needed to be corrected?

Re: Reload Libraries and Attachments

PostPosted: Wed Jun 19, 2019 9:55 am
by jay (support)
1) Starting with Indigo 7.3, you can now store them here:

/Library/Application Support/Perceptive Automation/Indigo 7/Scripts/Attachments/

and they will be available from Indigo Python scripts and plugins.

2) What version of Indigo are you using, and where are you running the script from?

Re: Reload Libraries and Attachments

PostPosted: Wed Jun 19, 2019 10:05 am
by Mark
Still running 7.2.

The script is here:
/Library/Python/2.7/site-packages/

Yay to keeping it in the Indigo 7/Scripts/Attachments folder.

Will upgrading to 7.3 and placing it there solve for the Reloading issue I'm having?

Re: Reload Libraries and Attachments

PostPosted: Wed Jun 19, 2019 10:36 am
by matt (support)
Yes, it should.

Re: Reload Libraries and Attachments

PostPosted: Wed Jun 19, 2019 10:37 am
by Mark
I've updated to 7.3.1.

OK!

The script runs while placed in the Attachments folder. Yay! Thanks for that. And Indigo successfully reloaded the script after using the "Reload Libraries and Attachments" menu item. So that's excellent.

But...

This is the log entry:

Stopping embedded script executor host (pid 4894)
Stopped "embedded script executor host"
Loading attachments
"update logs.scpt" script loaded


Note that the while the log indicates that one of my AppleScripts got reloaded, it doesn't list the Python script as reloaded (even though it did, in fact, reload).

And...

There's now a mystery file, with the same name as my Python attachment script, with suffix "pyc". I didn't create that. Just curious about it. I'm assuming I should leave that alone. Unless it's some sort of BBEdit artifact (which is what I use to edit the Python attachment).

Re: Reload Libraries and Attachments

PostPosted: Wed Jun 19, 2019 3:41 pm
by FlyingDiver
Mark wrote:
There's now a mystery file, with the same name as my Python attachment script, with suffix "pyc". I didn't create that. Just curious about it. I'm assuming I should leave that alone. Unless it's some sort of BBEdit artifact (which is what I use to edit the Python attachment).


That's the compiled Python file, which is normal for library type files. Just leave it be. It'll get recreated any time you change the .py file.

Re: Reload Libraries and Attachments

PostPosted: Wed Jun 19, 2019 4:55 pm
by jay (support)
Mark wrote:
Stopping embedded script executor host (pid 4894)
Stopped "embedded script executor host"
Loading attachments
"update logs.scpt" script loaded


Note that the while the log indicates that one of my AppleScripts got reloaded, it doesn't list the Python script as reloaded (even though it did, in fact, reload).


Python works differently than AppleScript. The latter requires the application to explicitly load the attachment scripts when it starts up. The former just requires that the Python interpreter have the path to that directory added to it's list of paths to search in when a script attempts to import something. So when Indigo starts the interpreter (embedded script executor) nothing actually gets loaded, we just add that directory to the path before starting it. Later, when it runs your script which does an import, it looks in all the paths to find the module you specify in your import.

Re: Reload Libraries and Attachments

PostPosted: Wed Jun 19, 2019 5:06 pm
by Mark
Thanks for the explanations guys. Good info to have. The whole thing works pretty fast, but it’s interesting that Indigo/Python loads that attachment script after it’s called, instead of having a compiled version waiting in memory. No matter, it’s all working well, and I’m glad I can still store common code in this way.

Re: Reload Libraries and Attachments

PostPosted: Thu Jun 20, 2019 8:43 am
by jay (support)
Mark wrote:
it’s interesting that Indigo/Python loads that attachment script after it’s called, instead of having a compiled version waiting in memory.


That's how Python works (as a dynamic language) - it never loads anything until it's actually needed. As for compilation, that's what that pyc file you were asking about above is (it's how Python optimizes load times), though "compile" isn't exactly the right word... :)

Re: Reload Libraries and Attachments

PostPosted: Thu Jun 20, 2019 8:46 am
by FlyingDiver
Depends on your definition of compiled, I guess. It's gets pretty blurry with virtual machines running byte-code directly.

Re: Reload Libraries and Attachments

PostPosted: Thu Jun 20, 2019 9:15 am
by Mark
OK, I'm getting the gist of it. Either way, whether's Indigo is just "recording" the path to the code, or readying a compiled version (the pyc file) and "recording" the path to that, I'd still like to see that event in the log. Just so we can get feedback that Indigo is ready to use whatever it finds in the attachment folder, AppleScript or Python...

Re: Reload Libraries and Attachments

PostPosted: Thu Jun 20, 2019 10:07 am
by jay (support)
Mark wrote:
OK, I'm getting the gist of it. Either way, whether's Indigo is just "recording" the path to the code, or readying a compiled version (the pyc file) and "recording" the path to that, I'd still like to see that event in the log. Just so we can get feedback that Indigo is ready to use whatever it finds in the attachment folder, AppleScript or Python...


Indigo isn't directly doing anything other than setting path parameter when it starts up the Python process. Python is doing everything else without Indigo's knowledge, so there's really nothing to log.

Re: Reload Libraries and Attachments

PostPosted: Wed Jul 24, 2019 12:41 pm
by tailwheel
Selecting the menu 'Plugins>Reload Libraries and Attachments' doesn't work reliably. It fails after a variable number of reloads.

Checking the Activity Monitor, there's more than one instance of ScriptExecutor.indigoPlugin running. If I quit them all, the process starts again.. At this point, trying to Reload via the menu creates a new instance of the ScriptExecutor.indigoPlugin. It appears that each time I try the menu Reload, another ScriptExecutor.indigoPlugin begins.

I have Triggers that utilize my Python Attachment files and wonder if that may be getting in the way of the Reload, or maybe it's something else.

Any ideas?

Re: Reload Libraries and Attachments

PostPosted: Wed Jul 24, 2019 1:45 pm
by jay (support)
What OS and Indigo versions are you using? Any errors in the Event Log when you select the menu item?

Re: Reload Libraries and Attachments

PostPosted: Wed Jul 24, 2019 2:27 pm
by tailwheel
OS 10.13.6, Indigo 7.3.1. No errors reported in the log.

When the Reload works properly, Indigo presents a small window, briefly. When it fails, there is no such window.