From 46c603464f1fb04d7f310dd381fc284af67e489e Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 18 May 2021 13:46:07 +0200 Subject: [PATCH] skip duplicated python paths --- openpype/hosts/maya/__init__.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/openpype/hosts/maya/__init__.py b/openpype/hosts/maya/__init__.py index 10a128583e..43a1e6f7bf 100644 --- a/openpype/hosts/maya/__init__.py +++ b/openpype/hosts/maya/__init__.py @@ -4,15 +4,21 @@ import os def add_implementation_envs(env): # Add requirements to PYTHONPATH pype_root = os.environ["OPENPYPE_REPOS_ROOT"] - new_python_path = os.pathsep.join([ + new_python_paths = [ os.path.join(pype_root, "openpype", "hosts", "maya", "startup"), os.path.join(pype_root, "repos", "avalon-core", "setup", "maya"), os.path.join(pype_root, "tools", "mayalookassigner") - ]) - old_python_path = env.get("PYTHONPATH") - if old_python_path: - new_python_path = os.pathsep.join([new_python_path, old_python_path]) - env["PYTHONPATH"] = new_python_path + ] + old_python_path = env.get("PYTHONPATH") or "" + for path in old_python_path.split(os.pathsep): + if not path or not os.path.exists(path): + continue + + norm_path = os.path.normpath(path) + if norm_path not in new_python_paths: + new_python_paths.append(norm_path) + + env["PYTHONPATH"] = os.pathsep.join(new_python_paths) # Set default values if are not already set via settings defaults = { @@ -24,6 +30,5 @@ def add_implementation_envs(env): "OPENPYPE_LOG_NO_COLORS": "Yes" } for key, value in defaults.items(): - if env.get(key): - continue - env[key] = value + if not env.get(key): + env[key] = value