mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
Merge pull request #1193 from pypeclub/feature/project_plugin_paths
Project plugin paths and envs
This commit is contained in:
commit
68e5e7df21
10 changed files with 88 additions and 64 deletions
|
|
@ -1,20 +1,22 @@
|
|||
# -*- 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
|
||||
|
||||
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")
|
||||
|
||||
|
|
@ -99,36 +101,31 @@ 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:
|
||||
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()
|
||||
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
|
||||
|
|
|
|||
|
|
@ -91,25 +91,12 @@ 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)
|
||||
|
||||
# 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()
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
||||
|
|
|
|||
|
|
@ -940,6 +940,33 @@ def prepare_host_environments(data):
|
|||
data["env"].update(final_env)
|
||||
|
||||
|
||||
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:
|
||||
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 +991,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
|
||||
|
|
|
|||
|
|
@ -1,4 +1,10 @@
|
|||
{
|
||||
"project_plugins": {
|
||||
"windows": [],
|
||||
"darwin": [],
|
||||
"linux": []
|
||||
},
|
||||
"project_environments": {},
|
||||
"publish": {
|
||||
"IntegrateHeroVersion": {
|
||||
"enabled": true
|
||||
|
|
|
|||
|
|
@ -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": "",
|
||||
|
|
|
|||
|
|
@ -22,6 +22,20 @@
|
|||
{
|
||||
"type": "schema",
|
||||
"name": "schema_project_syncserver"
|
||||
},
|
||||
{
|
||||
"key": "project_plugins",
|
||||
"type": "path",
|
||||
"label": "Additional Project Plugin Paths",
|
||||
"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
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue