filter environments before launch

This commit is contained in:
Jakub Trllo 2022-02-04 16:17:04 +01:00
parent ecf0da7721
commit 391500b2a0
3 changed files with 14 additions and 18 deletions

View file

@ -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"]

View file

@ -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"

View file

@ -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