This repository has been archived by the owner on Sep 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 129
General: Plugin settings handled by plugins #3623
Merged
iLLiCiTiT
merged 8 commits into
develop
from
feature/OP-3679_Plugin-settings-handled-by-plugins
Aug 5, 2022
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5f5aba7
loader plugins can handle settings on their own
iLLiCiTiT b2d5146
LegacyCreator plugin can handle settings on their own
iLLiCiTiT acb4b28
moved filter pyblish plugins function to openpype.pipeline.publish.lib
iLLiCiTiT cf42e8f
mark functions in openpype.lib as deprecated
iLLiCiTiT 08a9cb2
fix typo
iLLiCiTiT 6d2a869
discover loader plugins can expect project name
iLLiCiTiT 0b24237
loader pass project name to discover loader plugins
iLLiCiTiT cbfa901
catch failed applied settings
iLLiCiTiT File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import os | ||
import logging | ||
|
||
from openpype.lib import set_plugin_attributes_from_settings | ||
from openpype.settings import get_system_settings, get_project_settings | ||
from openpype.pipeline import legacy_io | ||
from openpype.pipeline.plugin_discover import ( | ||
discover, | ||
register_plugin, | ||
|
@@ -37,6 +39,46 @@ class LoaderPlugin(list): | |
def __init__(self, context): | ||
self.fname = self.filepath_from_context(context) | ||
|
||
@classmethod | ||
def apply_settings(cls, project_settings, system_settings): | ||
host_name = os.environ.get("AVALON_APP") | ||
plugin_type = "load" | ||
plugin_type_settings = ( | ||
project_settings | ||
.get(host_name, {}) | ||
.get(plugin_type, {}) | ||
) | ||
global_type_settings = ( | ||
project_settings | ||
.get("global", {}) | ||
.get(plugin_type, {}) | ||
) | ||
if not global_type_settings and not plugin_type_settings: | ||
return | ||
|
||
plugin_name = cls.__name__ | ||
|
||
plugin_settings = None | ||
# Look for plugin settings in host specific settings | ||
if plugin_name in plugin_type_settings: | ||
plugin_settings = plugin_type_settings[plugin_name] | ||
|
||
# Look for plugin settings in global settings | ||
elif plugin_name in global_type_settings: | ||
plugin_settings = global_type_settings[plugin_name] | ||
|
||
if not plugin_settings: | ||
return | ||
|
||
print(">>> We have preset for {}".format(plugin_name)) | ||
for option, value in plugin_settings.items(): | ||
if option == "enabled" and value is False: | ||
setattr(cls, "active", False) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do not call setattr with a constant attribute value, it is not any safer than normal property access. |
||
print(" - is disabled by preset") | ||
else: | ||
setattr(cls, option, value) | ||
print(" - setting `{}`: `{}`".format(option, value)) | ||
|
||
@classmethod | ||
def get_representations(cls): | ||
return cls.representations | ||
|
@@ -110,9 +152,25 @@ def __init__(self, context): | |
pass | ||
|
||
|
||
def discover_loader_plugins(): | ||
def discover_loader_plugins(project_name=None): | ||
from openpype.lib import Logger | ||
|
||
log = Logger.get_logger("LoaderDiscover") | ||
plugins = discover(LoaderPlugin) | ||
set_plugin_attributes_from_settings(plugins, LoaderPlugin) | ||
if not project_name: | ||
project_name = legacy_io.active_project() | ||
system_settings = get_system_settings() | ||
project_settings = get_project_settings(project_name) | ||
for plugin in plugins: | ||
try: | ||
plugin.apply_settings(project_settings, system_settings) | ||
except Exception: | ||
log.warning( | ||
"Failed to apply settings to loader {}".format( | ||
plugin.__name__ | ||
), | ||
exc_info=True | ||
) | ||
return plugins | ||
|
||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not call setattr with a constant attribute value, it is not any safer than normal property access.