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
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions openpype/hosts/blender/hooks/pre_add_python_use_system_env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from openpype.lib.applications import PreLaunchHook, LaunchTypes


class AddPythonUseSystemEnvArg(PreLaunchHook):
"""Add `--python-use-system-env` arg to blender launch."""

# Append before file argument from add last workfile (at order 10)
order = 5
app_groups = {"blender"}
launch_types = {LaunchTypes.local}

def execute(self):

add_var = self.get_application_setting("add_python_use_system_env",
default=True)
if not add_var:
return

arg = "--python-use-system-env"
if arg not in self.launch_context.launch_args:
self.log.debug(f"Adding required {arg} argument")
self.launch_context.launch_args.append(arg)
else:
self.log.debug(f"Required {arg} argument already provided before "
f"this prelaunch hook.")

def get_application_setting(self, key, default=None):
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)
)
Comment on lines +28 to +34
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

49 changes: 17 additions & 32 deletions openpype/settings/defaults/system_settings/applications.json
Original file line number Diff line number Diff line change
Expand Up @@ -1168,17 +1168,12 @@
"linux": []
},
"arguments": {
"windows": [
"--python-use-system-env"
],
"darwin": [
"--python-use-system-env"
],
"linux": [
"--python-use-system-env"
]
"windows": [],
"darwin": [],
"linux": []
},
"environment": {}
"environment": {},
"add_python_use_system_env": true
},
"2-90": {
"executables": {
Expand All @@ -1189,17 +1184,12 @@
"linux": []
},
"arguments": {
"windows": [
"--python-use-system-env"
],
"darwin": [
"--python-use-system-env"
],
"linux": [
"--python-use-system-env"
]
"windows": [],
"darwin": [],
"linux": []
},
"environment": {}
"environment": {},
"add_python_use_system_env": true
},
"2-91": {
"executables": {
Expand All @@ -1210,17 +1200,12 @@
"linux": []
},
"arguments": {
"windows": [
"--python-use-system-env"
],
"darwin": [
"--python-use-system-env"
],
"linux": [
"--python-use-system-env"
]
"windows": [],
"darwin": [],
"linux": []
},
"environment": {}
"environment": {},
"add_python_use_system_env": true
},
"__dynamic_keys_labels__": {
"2-83": "2.83",
Expand Down Expand Up @@ -1548,8 +1533,8 @@
"environment": {}
},
"__dynamic_keys_labels__": {
"5-1": "Unreal 5.1",
"5-0": "Unreal 5.0"
"5-0": "Unreal 5.0",
"5-1": "Unreal 5.1"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
"type": "schema_template",
"name": "template_host_variant_items",
"skip_paths": ["use_python_2"]
},
{
"type": "boolean",
"key": "add_python_use_system_env",
"label": "Use --python-use-system-env argument"
}
]
}
Expand Down
Loading