From 78d0b8c654a01e600130f523ef6774052773fc22 Mon Sep 17 00:00:00 2001 From: Jakub Trllo Date: Fri, 4 Feb 2022 15:22:39 +0100 Subject: [PATCH 1/4] remove environments that are not passed in data --- app_launcher.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app_launcher.py b/app_launcher.py index 6dc1518370..2cb313742b 100644 --- a/app_launcher.py +++ b/app_launcher.py @@ -29,9 +29,16 @@ def main(input_json_path): data = json.load(stream) # Change environment variables - env = data.get("env") or {} - for key, value in env.items(): - os.environ[key] = value + # - environments that are in current environments and are not data are + # removed + if "env" in data: + env = data["env"] + # Pop environment variable keys that are not in source + for key in set(os.environ.keys()) - set(env.keys()): + os.environ.pop(key) + + for key, value in env.items(): + os.environ[key] = value # Prepare launch arguments args = data["args"] From ecf0da7721bf084c2145672d1d9f7ba5f2386a15 Mon Sep 17 00:00:00 2001 From: Jakub Trllo Date: Fri, 4 Feb 2022 15:28:14 +0100 Subject: [PATCH 2/4] temporary fix for nuke --- openpype/hosts/nuke/__init__.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/openpype/hosts/nuke/__init__.py b/openpype/hosts/nuke/__init__.py index 60b37ce1dd..4402d0b48e 100644 --- a/openpype/hosts/nuke/__init__.py +++ b/openpype/hosts/nuke/__init__.py @@ -18,7 +18,13 @@ def add_implementation_envs(env, _app): new_nuke_paths.append(norm_path) env["NUKE_PATH"] = os.pathsep.join(new_nuke_paths) - env.pop("QT_AUTO_SCREEN_SCALE_FACTOR", None) + # NOTE: Poping of the key is right way. But is commented because there is + # a bug in `app_launcher.py` which only change values and not remove + # existing. + # Fixed with https://github.com/pypeclub/OpenPype/pull/2655 + # but this fix requires new build + # env.pop("QT_AUTO_SCREEN_SCALE_FACTOR", None) + env["QT_AUTO_SCREEN_SCALE_FACTOR"] = "" # Try to add QuickTime to PATH quick_time_path = "C:/Program Files (x86)/QuickTime/QTSystem" From 391500b2a03275ebd43d88138d89bdb102b08b2e Mon Sep 17 00:00:00 2001 From: Jakub Trllo Date: Fri, 4 Feb 2022 16:17:04 +0100 Subject: [PATCH 3/4] filter environments before launch --- app_launcher.py | 13 +++---------- openpype/hosts/nuke/__init__.py | 8 +------- openpype/lib/applications.py | 11 ++++++++++- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/app_launcher.py b/app_launcher.py index 2cb313742b..6dc1518370 100644 --- a/app_launcher.py +++ b/app_launcher.py @@ -29,16 +29,9 @@ def main(input_json_path): data = json.load(stream) # Change environment variables - # - environments that are in current environments and are not data are - # removed - if "env" in data: - env = data["env"] - # Pop environment variable keys that are not in source - for key in set(os.environ.keys()) - set(env.keys()): - os.environ.pop(key) - - for key, value in env.items(): - os.environ[key] = value + env = data.get("env") or {} + for key, value in env.items(): + os.environ[key] = value # Prepare launch arguments args = data["args"] diff --git a/openpype/hosts/nuke/__init__.py b/openpype/hosts/nuke/__init__.py index 4402d0b48e..60b37ce1dd 100644 --- a/openpype/hosts/nuke/__init__.py +++ b/openpype/hosts/nuke/__init__.py @@ -18,13 +18,7 @@ def add_implementation_envs(env, _app): new_nuke_paths.append(norm_path) env["NUKE_PATH"] = os.pathsep.join(new_nuke_paths) - # NOTE: Poping of the key is right way. But is commented because there is - # a bug in `app_launcher.py` which only change values and not remove - # existing. - # Fixed with https://github.com/pypeclub/OpenPype/pull/2655 - # but this fix requires new build - # env.pop("QT_AUTO_SCREEN_SCALE_FACTOR", None) - env["QT_AUTO_SCREEN_SCALE_FACTOR"] = "" + env.pop("QT_AUTO_SCREEN_SCALE_FACTOR", None) # Try to add QuickTime to PATH quick_time_path = "C:/Program Files (x86)/QuickTime/QTSystem" diff --git a/openpype/lib/applications.py b/openpype/lib/applications.py index a704c3ae68..4227195235 100644 --- a/openpype/lib/applications.py +++ b/openpype/lib/applications.py @@ -1040,10 +1040,19 @@ class ApplicationLaunchContext: # Prepare data that will be passed to midprocess # - store arguments to a json and pass path to json as last argument # - pass environments to set + app_env = self.kwargs.pop("env", {}) json_data = { "args": self.launch_args, - "env": self.kwargs.pop("env", {}) + "env": app_env } + if app_env: + # Filter environments of subprocess + self.kwargs["env"] = { + key: value + for key, value in os.environ.items() + if key in app_env + } + # Create temp file json_temp = tempfile.NamedTemporaryFile( mode="w", prefix="op_app_args", suffix=".json", delete=False From cda9beb2fd98be211016378072fbaea7b31d44b4 Mon Sep 17 00:00:00 2001 From: Jakub Trllo Date: Fri, 4 Feb 2022 16:22:40 +0100 Subject: [PATCH 4/4] pop 'QT_AUTO_SCREEN_SCALE_FACTOR' in hiero implementation --- openpype/hosts/hiero/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/openpype/hosts/hiero/__init__.py b/openpype/hosts/hiero/__init__.py index 15bd10fdb0..2d674b3fa7 100644 --- a/openpype/hosts/hiero/__init__.py +++ b/openpype/hosts/hiero/__init__.py @@ -18,6 +18,7 @@ def add_implementation_envs(env, _app): new_hiero_paths.append(norm_path) env["HIERO_PLUGIN_PATH"] = os.pathsep.join(new_hiero_paths) + env.pop("QT_AUTO_SCREEN_SCALE_FACTOR", None) # Try to add QuickTime to PATH quick_time_path = "C:/Program Files (x86)/QuickTime/QTSystem"