diff --git a/openpype/hosts/blender/hooks/pre_add_python_use_system_env.py b/openpype/hosts/blender/hooks/pre_add_python_use_system_env.py new file mode 100644 index 00000000000..08bf18b27bf --- /dev/null +++ b/openpype/hosts/blender/hooks/pre_add_python_use_system_env.py @@ -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) + ) diff --git a/openpype/settings/defaults/system_settings/applications.json b/openpype/settings/defaults/system_settings/applications.json index a5283751e97..9f2c0a31680 100644 --- a/openpype/settings/defaults/system_settings/applications.json +++ b/openpype/settings/defaults/system_settings/applications.json @@ -1204,17 +1204,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": { @@ -1225,17 +1220,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": { @@ -1246,17 +1236,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", @@ -1584,8 +1569,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" } } }, diff --git a/openpype/settings/entities/schemas/system_schema/host_settings/schema_blender.json b/openpype/settings/entities/schemas/system_schema/host_settings/schema_blender.json index 27ead6e6da1..7a27f40343c 100644 --- a/openpype/settings/entities/schemas/system_schema/host_settings/schema_blender.json +++ b/openpype/settings/entities/schemas/system_schema/host_settings/schema_blender.json @@ -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" } ] }