From 712670ec60c661c347049ef52174001787e479ce Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Thu, 25 Mar 2021 15:37:57 +0100 Subject: [PATCH 01/11] moved project plugin paths to project settings --- .../schemas/projects_schema/schema_project_global.json | 8 ++++++++ .../entities/schemas/system_schema/schema_general.json | 7 ------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/pype/settings/entities/schemas/projects_schema/schema_project_global.json b/pype/settings/entities/schemas/projects_schema/schema_project_global.json index 1733e04f67..ebc8d08fb8 100644 --- a/pype/settings/entities/schemas/projects_schema/schema_project_global.json +++ b/pype/settings/entities/schemas/projects_schema/schema_project_global.json @@ -22,6 +22,14 @@ { "type": "schema", "name": "schema_project_syncserver" + }, + { + "key": "project_plugins", + "type": "path", + "label": "Additional Project Plugin Paths", + "multiplatform": true, + "multipath": true, + "use_label_wrap": true } ] } diff --git a/pype/settings/entities/schemas/system_schema/schema_general.json b/pype/settings/entities/schemas/system_schema/schema_general.json index b029081c7c..cf88043cd0 100644 --- a/pype/settings/entities/schemas/system_schema/schema_general.json +++ b/pype/settings/entities/schemas/system_schema/schema_general.json @@ -18,13 +18,6 @@ { "type": "splitter" }, - { - "key": "project_plugins", - "type": "path", - "label": "Additional Project Plugins Path", - "multiplatform": true, - "multipath": false - }, { "key": "studio_soft", "type": "path", From bba39ff457bd43e95663574c287d7ae6211ccc66 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Thu, 25 Mar 2021 15:38:17 +0100 Subject: [PATCH 02/11] save defaults of project plugins --- pype/settings/defaults/project_settings/global.json | 5 +++++ pype/settings/defaults/system_settings/general.json | 5 ----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pype/settings/defaults/project_settings/global.json b/pype/settings/defaults/project_settings/global.json index 63c092ec27..e252a103ac 100644 --- a/pype/settings/defaults/project_settings/global.json +++ b/pype/settings/defaults/project_settings/global.json @@ -1,4 +1,9 @@ { + "project_plugins": { + "windows": [], + "darwin": [], + "linux": [] + }, "publish": { "IntegrateHeroVersion": { "enabled": true diff --git a/pype/settings/defaults/system_settings/general.json b/pype/settings/defaults/system_settings/general.json index bf2bb5def0..e03e00aca8 100644 --- a/pype/settings/defaults/system_settings/general.json +++ b/pype/settings/defaults/system_settings/general.json @@ -1,11 +1,6 @@ { "studio_name": "Studio name", "studio_code": "stu", - "project_plugins": { - "windows": "convert from \"PYPE_PROJECT_PLUGINS\"", - "darwin": "", - "linux": "" - }, "studio_soft": { "windows": "convert from \"STUDIO_SOFT\"", "darwin": "", From 2b4890e6594025bfd5d2ccd3bb0a3bf0f19922df Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Thu, 25 Mar 2021 17:05:52 +0100 Subject: [PATCH 03/11] removed usage of PYPE_PROJECT_PLUGINS --- pype/__init__.py | 13 ------------- pype/hosts/celaction/api/cli.py | 8 -------- pype/tools/standalonepublish/publish.py | 8 -------- 3 files changed, 29 deletions(-) diff --git a/pype/__init__.py b/pype/__init__.py index fd0ba321ed..0add849457 100644 --- a/pype/__init__.py +++ b/pype/__init__.py @@ -99,20 +99,7 @@ def install(): pyblish.register_discovery_filter(filter_pyblish_plugins) avalon.register_plugin_path(avalon.Loader, LOAD_PATH) - # Register project specific plugins project_name = os.environ.get("AVALON_PROJECT") - if PROJECT_PLUGINS_PATH and project_name: - for path in PROJECT_PLUGINS_PATH.split(os.pathsep): - if not path: - continue - plugin_path = os.path.join(path, project_name, "plugins") - if os.path.exists(plugin_path): - pyblish.register_plugin_path(plugin_path) - avalon.register_plugin_path(avalon.Loader, plugin_path) - avalon.register_plugin_path(avalon.Creator, plugin_path) - avalon.register_plugin_path( - avalon.InventoryAction, plugin_path - ) # Register studio specific plugins if STUDIO_PLUGINS_PATH and project_name: diff --git a/pype/hosts/celaction/api/cli.py b/pype/hosts/celaction/api/cli.py index 9f2d1a1fdb..476d2f69a9 100644 --- a/pype/hosts/celaction/api/cli.py +++ b/pype/hosts/celaction/api/cli.py @@ -102,14 +102,6 @@ def main(): pyblish.api.register_host(publish_host) - # Register project specific plugins - project_name = os.environ["AVALON_PROJECT"] - project_plugins_paths = os.getenv("PYPE_PROJECT_PLUGINS", "") - for path in project_plugins_paths.split(os.pathsep): - plugin_path = os.path.join(path, project_name, "plugins") - if os.path.exists(plugin_path): - pyblish.api.register_plugin_path(plugin_path) - return publish.show() diff --git a/pype/tools/standalonepublish/publish.py b/pype/tools/standalonepublish/publish.py index a4bb81ad3c..cfa9f8b8e8 100644 --- a/pype/tools/standalonepublish/publish.py +++ b/pype/tools/standalonepublish/publish.py @@ -19,14 +19,6 @@ def main(env): continue pyblish.api.register_plugin_path(path) - # Register project specific plugins - project_name = os.environ["AVALON_PROJECT"] - project_plugins_paths = env.get("PYPE_PROJECT_PLUGINS") or "" - for path in project_plugins_paths.split(os.pathsep): - plugin_path = os.path.join(path, project_name, "plugins") - if os.path.exists(plugin_path): - pyblish.api.register_plugin_path(plugin_path) - return publish.show() From 0b3953d39ec2c563c66787f517247cc0825e388f Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Thu, 25 Mar 2021 17:06:56 +0100 Subject: [PATCH 04/11] fix PUBLISH_PATH variable in celaction cli.py --- pype/hosts/celaction/api/cli.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/pype/hosts/celaction/api/cli.py b/pype/hosts/celaction/api/cli.py index 476d2f69a9..f77bdea451 100644 --- a/pype/hosts/celaction/api/cli.py +++ b/pype/hosts/celaction/api/cli.py @@ -91,14 +91,9 @@ def main(): # Registers pype's Global pyblish plugins pype.install() - for path in PUBLISH_PATHS: - path = os.path.normpath(path) - - if not os.path.exists(path): - continue - - log.info(f"Registering path: {path}") - pyblish.api.register_plugin_path(path) + if os.path.exists(PUBLISH_PATH): + log.info(f"Registering path: {PUBLISH_PATH}") + pyblish.api.register_plugin_path(PUBLISH_PATH) pyblish.api.register_host(publish_host) From 960304a5dec66633f2bffa237997d0dbe77020c9 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Thu, 25 Mar 2021 17:09:28 +0100 Subject: [PATCH 05/11] removed usage of STUDIO_PLUGINS_PATH --- pype/__init__.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/pype/__init__.py b/pype/__init__.py index 0add849457..216ec61784 100644 --- a/pype/__init__.py +++ b/pype/__init__.py @@ -13,8 +13,6 @@ pyblish = avalon = _original_discover = None log = logging.getLogger(__name__) -PROJECT_PLUGINS_PATH = os.environ.get("PYPE_PROJECT_PLUGINS") -STUDIO_PLUGINS_PATH = os.environ.get("PYPE_STUDIO_PLUGINS") PACKAGE_DIR = os.path.dirname(os.path.abspath(__file__)) PLUGINS_DIR = os.path.join(PACKAGE_DIR, "plugins") @@ -101,17 +99,6 @@ def install(): project_name = os.environ.get("AVALON_PROJECT") - # Register studio specific plugins - if STUDIO_PLUGINS_PATH and project_name: - for path in STUDIO_PLUGINS_PATH.split(os.pathsep): - if not path: - continue - if os.path.exists(path): - pyblish.register_plugin_path(path) - avalon.register_plugin_path(avalon.Loader, path) - avalon.register_plugin_path(avalon.Creator, path) - avalon.register_plugin_path(avalon.InventoryAction, path) - if project_name: anatomy = Anatomy(project_name) anatomy.set_root_environments() From 1d279b301d0050fbd3d39ed0b0f4e9bec402853f Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Thu, 25 Mar 2021 17:09:43 +0100 Subject: [PATCH 06/11] register plugins from project settings on pype install --- pype/__init__.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/pype/__init__.py b/pype/__init__.py index 216ec61784..edd48a018d 100644 --- a/pype/__init__.py +++ b/pype/__init__.py @@ -1,12 +1,16 @@ # -*- coding: utf-8 -*- """Pype module.""" import os +import platform import functools import logging from .settings import get_project_settings -from .lib import Anatomy, filter_pyblish_plugins, \ +from .lib import ( + Anatomy, + filter_pyblish_plugins, change_timer_to_current_context +) pyblish = avalon = _original_discover = None @@ -99,10 +103,29 @@ def install(): project_name = os.environ.get("AVALON_PROJECT") + # Register studio specific plugins if project_name: anatomy = Anatomy(project_name) anatomy.set_root_environments() avalon.register_root(anatomy.roots) + + project_settings = get_project_settings(project_name) + platform_name = platform.system().lower() + project_plugins = ( + project_settings + .get("global", {}) + .get("project_plugins", {}) + .get(platform_name) + ) or [] + for path in project_plugins: + if not path or not os.path.exists(path): + continue + + pyblish.register_plugin_path(path) + avalon.register_plugin_path(avalon.Loader, path) + avalon.register_plugin_path(avalon.Creator, path) + avalon.register_plugin_path(avalon.InventoryAction, path) + # apply monkey patched discover to original one log.info("Patching discovery") avalon.discover = patched_discover From 1089c5f3c72655a51ff409f225c2eabcfad03340 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Thu, 25 Mar 2021 17:28:15 +0100 Subject: [PATCH 07/11] it is possible to define project specific environments --- pype/settings/defaults/project_settings/global.json | 1 + .../schemas/projects_schema/schema_project_global.json | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/pype/settings/defaults/project_settings/global.json b/pype/settings/defaults/project_settings/global.json index e252a103ac..fc8e7ddaf8 100644 --- a/pype/settings/defaults/project_settings/global.json +++ b/pype/settings/defaults/project_settings/global.json @@ -4,6 +4,7 @@ "darwin": [], "linux": [] }, + "project_environments": {}, "publish": { "IntegrateHeroVersion": { "enabled": true diff --git a/pype/settings/entities/schemas/projects_schema/schema_project_global.json b/pype/settings/entities/schemas/projects_schema/schema_project_global.json index ebc8d08fb8..6e5cf0671c 100644 --- a/pype/settings/entities/schemas/projects_schema/schema_project_global.json +++ b/pype/settings/entities/schemas/projects_schema/schema_project_global.json @@ -30,6 +30,12 @@ "multiplatform": true, "multipath": true, "use_label_wrap": true + }, + { + "key": "project_environments", + "type": "raw-json", + "label": "Additional Project Environments (set on application launch)", + "use_label_wrap": true } ] } From 71c9fb431a072d1dd5327589a988b325ce3189de Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Thu, 25 Mar 2021 17:28:47 +0100 Subject: [PATCH 08/11] implemented function to apply project specific environments --- pype/lib/applications.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pype/lib/applications.py b/pype/lib/applications.py index abaecf1e9c..039b122bae 100644 --- a/pype/lib/applications.py +++ b/pype/lib/applications.py @@ -940,6 +940,19 @@ def prepare_host_environments(data): data["env"].update(final_env) +def apply_project_environments_value(project_name, env, project_settings=None): + import acre + + if project_settings is None: + project_settings = get_project_settings(project_name) + + env_value = project_settings["global"]["project_environments"] + if not env_value: + return env + parsed = acre.parse(env_value) + return _merge_env(parsed, env) + + def prepare_context_environments(data): """Modify launch environemnts with context data for launched host. @@ -964,6 +977,12 @@ def prepare_context_environments(data): ) return + # Load project specific environments + project_name = project_doc["name"] + data["env"] = apply_project_environments_value( + project_name, data["env"] + ) + app = data["app"] workdir_data = get_workdir_data( project_doc, asset_doc, task_name, app.host_name From 5793f9827398e5abaa0c8b3847256cee8b849cd3 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Thu, 25 Mar 2021 17:32:03 +0100 Subject: [PATCH 09/11] added some docstring --- pype/lib/applications.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pype/lib/applications.py b/pype/lib/applications.py index 039b122bae..a03a845770 100644 --- a/pype/lib/applications.py +++ b/pype/lib/applications.py @@ -941,6 +941,20 @@ def prepare_host_environments(data): def apply_project_environments_value(project_name, env, project_settings=None): + """Apply project specific environments on passed environments. + + Args: + project_name (str): Name of project for which environemnts should be + received. + env (dict): Environment values on which project specific environments + will be applied. + project_settings (dict): Project settings for passed project name. + Optional if project settings are already prepared. + + Raises: + KeyError: If project settings do not contain keys for project specific + environments. + """ import acre if project_settings is None: From c98f4d83e7c57e9a5c9c083c4c5c058a75d9b612 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Thu, 25 Mar 2021 17:44:53 +0100 Subject: [PATCH 10/11] standalone publisher sets project environments before publish is started --- .../tools/standalonepublish/widgets/widget_components.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pype/tools/standalonepublish/widgets/widget_components.py b/pype/tools/standalonepublish/widgets/widget_components.py index d4638ea437..d09c12f0ab 100644 --- a/pype/tools/standalonepublish/widgets/widget_components.py +++ b/pype/tools/standalonepublish/widgets/widget_components.py @@ -1,5 +1,4 @@ import os -import sys import json import tempfile import random @@ -10,7 +9,10 @@ from . import DropDataFrame from .constants import HOST_NAME from avalon import io from pype.api import execute, Logger -from pype.lib import get_pype_execute_args +from pype.lib import ( + get_pype_execute_args, + apply_project_environments_value +) log = Logger().get_logger("standalonepublisher") @@ -209,6 +211,9 @@ def cli_publish(data, publish_paths, gui=True): if data.get("family", "").lower() == "editorial": envcopy["PYBLISH_SUSPEND_LOGS"] = "1" + project_name = os.environ["AVALON_PROJECT"] + env_copy = apply_project_environments_value(project_name, envcopy) + args = get_pype_execute_args("run", PUBLISH_SCRIPT_PATH) result = execute(args, env=envcopy) From 6c74ea04d4aad48acc8354cbb11585d6eed1ca60 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Thu, 25 Mar 2021 17:45:09 +0100 Subject: [PATCH 11/11] added new function to lib's init file --- pype/lib/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pype/lib/__init__.py b/pype/lib/__init__.py index 27dd93c1a1..2150e53b0e 100644 --- a/pype/lib/__init__.py +++ b/pype/lib/__init__.py @@ -81,6 +81,7 @@ from .applications import ( prepare_host_environments, prepare_context_environments, get_app_environments_for_context, + apply_project_environments_value, compile_list_of_regexes ) @@ -174,6 +175,7 @@ __all__ = [ "prepare_host_environments", "prepare_context_environments", "get_app_environments_for_context", + "apply_project_environments_value", "compile_list_of_regexes",