Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Blender: Set --python-use-system-env from PreLaunchHook #5565

Closed

Conversation

BigRoy
Copy link
Collaborator

@BigRoy BigRoy commented Sep 4, 2023

Changelog Description

Automatically add --python-use-system-env when running Blender when it's not pre-configured in the application settings for Blender (In Studio Settings > System Settings > Applications > Blender > {version} > arguments.

Additional info

It often happens that admins add a new Blender version in the applications but don't also apply the --python-use-system-env arguments meaning OpenPype will not be loaded for Blender plus won't be available in Blender on PYTHONPATH.

This avoids that issue by always enforcing the argument is added on launch plus updates the defaults so that --python-use-system-env isn't there by default either.

@iLLiCiTiT I've set it to run on launch_types = set() so it always runs. I basically want it to run on ANY Blender launch where prior to this it'd have also been applied due to being in the arguments settings for the application. (I feel like that's likely more than just 'local', right?)


Before:
image

After:
image


See this reference discussion on Discord for somebody who was hitting this issue. Although there have also been reports that it should be working without the flag.

Note: For those who were already succsesfully launching blender without --python-use-system-env this PR might be giving unexpected results if - for whatever reason - they don't actually use the system env in Blender.

Testing notes:

  1. Run blender without --python-use-system-env argument in settings
  2. Run blender with --python-use-system-env argument in settings (this is just to ensure it's backwards compatible with any settings a studio might currently have for custom versions.)
  3. Everything should load and run fine for both

@BigRoy BigRoy added type: enhancement Enhancements to existing functionality host: Blender community contribution labels Sep 4, 2023
@ynbot ynbot added the size/XS Denotes a PR changes 0-99 lines, ignoring general files label Sep 4, 2023
@iLLiCiTiT
Copy link
Member

iLLiCiTiT commented Sep 5, 2023

Automatically add --python-use-system-env when running Blender when it's not pre-configured in the application settings for Blender (In Studio Settings > System Settings > Applications > Blender > {version} > arguments.

We didn't add it automatically because someone wanted to launch it using rez or script (.bat/.sh) where it caused issues... (not saying I'm against).

EDITED: It would nice to have option to turn the prelaunch hook off.

I've set it to run on launch_types = set() so it always runs. I basically want it to run on ANY Blender launch where prior to this it'd have also been applied due to being in the arguments settings for the application. (I feel like that's likely more than just 'local', right?)

It make sense only for {LaunchTypes.local, LaunchTypes.remote, LaunchTypes.automated}, the others are farm specific, where blender is not launched. But because remote and automated are not implemented for blender it could be just {LaunchTypes.local}.

@BigRoy
Copy link
Collaborator Author

BigRoy commented Sep 5, 2023

We didn't add it automatically because someone wanted to launch it using rez or script (.bat/.sh) where it caused issues... (not saying I'm against).

EDITED: It would nice to have option to turn the prelaunch hook off.

Thanks - yes, then I suspect instead having a toggle somewhere in settings might be the decent other solution? But I was expecting this might've been the case. Any good place you think this could work? Should it somehow be a part of the Blender-specific application versions? or more globally?

It make sense only for {LaunchTypes.local, LaunchTypes.remote, LaunchTypes.automated}, the others are farm specific, where blender is not launched. But because remote and automated are not implemented for blender it could be just {LaunchTypes.local}.

Thanks - I'll just make it the first three just in preparation of what might come; will save some debugging for those cases maybe?

@iLLiCiTiT
Copy link
Member

will save some debugging for those cases maybe?

Not needed, that's unrelated to the launch hook itself.

@BigRoy
Copy link
Collaborator Author

BigRoy commented Sep 5, 2023

It would nice to have option to turn the prelaunch hook off.

Any pointers on where I could best put that?

Here's an example option:
image

@LiborBatek
Copy link
Member

@iLLiCiTiT any insight for aformentioned things? thx

Copy link
Collaborator

@Tilix4 Tilix4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code LGTM!

About the UI, I'd move it right before the custom arguments list, before the executables, it is confusing.

@BigRoy
Copy link
Collaborator Author

BigRoy commented Oct 2, 2023

Added a commit that added the toggle in settings:
image

@BigRoy
Copy link
Collaborator Author

BigRoy commented Oct 2, 2023

About the UI, I'd move it right before the custom arguments list, before the executables, it is confusing.

@Tilix4 This unfortunately wasn't as trivial because it builds that section using a template which is the full environment section - so I've opted to just add it at the end.

@Tilix4
Copy link
Collaborator

Tilix4 commented Oct 3, 2023

@BigRoy This is fine for me!

Comment on lines +28 to +34
app = self.launch_context.application
group_name = app.group.name
app_name = app.name
return (
self.data["system_settings"]["applications"][group_name]
["variants"][app_name].get(key, default)
)
Copy link
Collaborator Author

@BigRoy BigRoy Oct 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This likely moves in AYON? Is there a better approach to this @iLLiCiTiT ?

Basically I'm trying to get an extra key from the variant setting.
(I'd also need to update the settings + defaults in AYON of course - if I know where those are)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep this will need to be made forward compatible with AYON. Settings and their defaults are here ;) https://github.com/ynput/OpenPype/tree/develop/server_addon/applications/server

Copy link
Member

@LiborBatek LiborBatek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me in both scenarios...

when still having that Argument present
image

and also when removed but using the new Python path knob Enabled
image

Comment on lines +28 to +34
app = self.launch_context.application
group_name = app.group.name
app_name = app.name
return (
self.data["system_settings"]["applications"][group_name]
["variants"][app_name].get(key, default)
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep this will need to be made forward compatible with AYON. Settings and their defaults are here ;) https://github.com/ynput/OpenPype/tree/develop/server_addon/applications/server

@mkolar
Copy link
Member

mkolar commented Feb 7, 2024

Because we're splitting OpenPype into ayon-core and individual host addons, this PR would have to be re-created to target one of those. It will need to be AYON compatible for it to get merged.

We're closing it down, but we'll he happy for a new PRs to ynput/ayon-blender repository once it's up.

@mkolar mkolar closed this Feb 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
community contribution host: Blender size/XS Denotes a PR changes 0-99 lines, ignoring general files target: OpenPype type: enhancement Enhancements to existing functionality
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

7 participants