Implement pre app init
Currently I am developing to ensure that everything we have Maya is also available in Houdini.
Issue Menus cannot be made post launch of the application.
After reading the approach used by Shotgun, see here I tried to do something similar within our current setup. Which is: running a function which writes the xml file needed to create a new menu or extend on an existing menu. Add the file path to an environment variable ( HOUDINI_MENU_PATH ) for Houdini to read out.
Houdini does not check any files after the application has started.
Conclusion: The file and the environment variable need to be create / updated prior to the launch of the application.
Note:
Currenlty I have an alternative but static menu which can be copied or set through the .toml
Proposal: Create a logic which allows the pipeline to set and/or create important items for the application.
Dummy code:
# This case is aimed for Houdini were we use `123.py` to trigger the install at launch
import os
from avalon import pipeline, houdini
if os.environ.get("PRE_APP_INIT", False):
houdini.pre_install()
<host>.install()
The logic to control something like this can be altered but assuming that not all applications need it, it might be better to use an environment variable.
Any other ideas how to tackle such things?
I think being able to run code for applications within Avalon before the application is launched can also aid other areas.
It would allow:
- Overriding Maya's splash screen image from a studio configuration - this needs to be set with
XBMLANGPATHprior to launch to work. It's a nice to have. - Ease the "environment management" for Fusion, as the current state with going through a
master_prefsfile needing to be linked manually through the environment to expose avalon feels off. What if launching Fusion through avalon allows to easily ensure those preferences being present.
The concept basically is, prior to launching the host allow the configuration/avalon to run some code that could customize the local environment (for the app) and produce a temporary file (like @aardschok described).
Any ideas @mottosso on what an easy way would be to implement this? Specifically on where a good place would be to start implementing this?
If I'm reading this correctly, then it'd be like Maya's userSetup.py, but cross-application?
How about if each application got something to subclass?
from avalon import api
class Maya(api.Application):
def before_launch(self):
print("I'm run before the Houdini.exe file has been called")
def after_launch(self):
print("And I'm run afterwards")
def on_exit(self):
pass
def etc(...)
Unsure of where to reference this from though. Could also make it a series of loose functions that get registered, like how signals get assigned?
from avalon import api
def before_launch():
import os
os.environ["XBMLANGPATH"] = "/some/path"
api.before("applicationLaunch", before_launch)
That makes sense I think. Then we can setup a series of common hooks that trigger at relevant points.
It's somewhat like userSetup.py but then running it prior to launching even, but yes... close.
I'll think about these ideas. I think the hardest bit in my head is that now things are running through the .toml files that are launching the application - at a point where there's no more python code manageable in-between. At that point in time the host also isn't registered yet, as currently that's done within the host. :)
I think the hardest bit in my head is that now things are running through the .toml files that are launching the application
I had an idea as I went to bed last night. What if we did what Maya and friends do?
avalonSetup.py
import os
os.environ["I_RAN_BEFORE"] = "maya was started"
Where avalonSetup.py is optionally present on the PYTHONPATH, like how Maya does things. And where there can be many, whereby each is run one after the other, in the order they appear on the PYTHONPATH. Also like Maya.
You could then have a avalonSetup.py per application.. e.g.
c:\projects\hulk\scripts\maya\avalonSetup.py
c:\projects\hulk\scripts\houdini\avalonSetup.py
...
Where which to pick up is specified in the application configuration.
maya2016.toml
[environment]
MAYA_DISABLE_CLIC_IPM = "Yes" # Disable the AdSSO process
MAYA_DISABLE_CIP = "Yes" # Shorten time to boot
MAYA_DISABLE_CER = "Yes"
PYTHONPATH = [
"c:/projects/hulk/scripts/maya",
"{PYTHONPATH}"
]
That could work. I'm looking into to solving this issue over the next few weeks, I'm tagging @mkolar and @tokejepsen as I know they have experience with ftrack - I believe both Shotgun/Ftrack have some sort of "pre app initialization"
Here's some more details:
- I thought it was in Engines in Shotgun but code for it seems to be here in SoftwareLauncher startup.
- Maybe in ftrack you can customize anything prior launch since it's running through a dedicated Python script, a registered action for custom applications instead of from a
.tomlor alike or specifically see Modify environment before application start
And some thoughts so far:
Preferrably it's a pre-app init that studios can also customize, which avalonSetup.py does do in a way - but it should allow to customize the environment of the application that is "about to launch" before it even launched. avalonSetup.py might make it trivial to change the local python environment and settings, but maybe less so for the application that is about to run outside of the avalonSetup.py - unless we pass an object along to it?
Would love some more input for ideas to get into a good starting direction for a proposal I can set up. If anyone has other references feel free to share.
This is how Ftrack does this: http://ftrack-connect.rtd.ftrack.com/en/latest/developing/tutorial/adding_a_location.html#developing-tutorial-adding-a-location-modifying-application-launch
They allow users to register a launch method that gets the event. In the event you can modify the environment and hand it back to the launcher. The event also have data about other things, so you can customize the environment per application or task or user etc.
Sorry if this is clear from that page, but I didn't find it as I quickly went over it - how do you assign it to a specific application instead of on all application launches?
Also, potentially you have had use cases for this in production? What did you typically used this for?
how do you assign it to a specific application instead of on all application launches?
You can filter the event calls based on the data. Think signal and slots with filtering. I filtered in the method, so yeah the the method was called initially on all application launches.
Also, potentially you have had use cases for this in production? What did you typically used this for?
I used this to setup the environment for the application. Everything from ftrack-connect to studio pipeline to artists scripts.