Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Settings: Remove environment groups from settings #3115

Merged
merged 7 commits into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions openpype/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
get_project_settings,
get_current_project_settings,
get_anatomy_settings,
get_environments,

SystemSettings,
ProjectSettings
Expand All @@ -23,7 +22,6 @@
get_app_environments_for_context,
source_hash,
get_latest_version,
get_global_environments,
get_local_site_id,
change_openpype_mongo_url,
create_project_folders,
Expand Down Expand Up @@ -69,10 +67,10 @@
"get_project_settings",
"get_current_project_settings",
"get_anatomy_settings",
"get_environments",
"get_project_basic_paths",

"SystemSettings",
"ProjectSettings",

"PypeLogger",
"Logger",
Expand Down Expand Up @@ -102,16 +100,16 @@

# get contextual data
"version_up",
"get_hierarchy",
"get_asset",
"get_hierarchy",
"get_workdir_data",
"get_version_from_path",
"get_last_version_from_path",
"get_app_environments_for_context",
"source_hash",

"run_subprocess",
"get_latest_version",
"get_global_environments",

"get_local_site_id",
"change_openpype_mongo_url",
Expand Down
54 changes: 0 additions & 54 deletions openpype/lib/env_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,57 +69,3 @@ def get_paths_from_environ(env_key=None, env_value=None, return_first=False):
return None
# Return all existing paths from environment variable
return existing_paths


def get_global_environments(env=None):
"""Load global environments from Pype.

Return prepared and parsed global environments by pype's settings. Use
combination of "global" environments set in pype's settings and enabled
modules.

Args:
env (dict, optional): Initial environments. Empty dictionary is used
when not entered.

Returns;
dict of str: Loaded and processed environments.

"""
import acre
from openpype.modules import ModulesManager
from openpype.settings import get_environments

if env is None:
env = {}

# Get global environments from settings
all_settings_env = get_environments()
parsed_global_env = acre.parse(all_settings_env["global"])

# Merge with entered environments
merged_env = acre.append(env, parsed_global_env)

# Get environments from Pype modules
modules_manager = ModulesManager()

module_envs = modules_manager.collect_global_environments()
publish_plugin_dirs = modules_manager.collect_plugin_paths()["publish"]

# Set pyblish plugins paths if any module want to register them
if publish_plugin_dirs:
publish_paths_str = os.environ.get("PYBLISHPLUGINPATH") or ""
publish_paths = publish_paths_str.split(os.pathsep)
_publish_paths = {
os.path.normpath(path) for path in publish_paths if path
}
for path in publish_plugin_dirs:
_publish_paths.add(os.path.normpath(path))
module_envs["PYBLISHPLUGINPATH"] = os.pathsep.join(_publish_paths)

# Merge environments with current environments and update values
if module_envs:
parsed_envs = acre.parse(module_envs)
merged_env = acre.merge(parsed_envs, merged_env)

return acre.compute(merged_env, cleanup=True)
2 changes: 0 additions & 2 deletions openpype/settings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
get_project_settings,
get_current_project_settings,
get_anatomy_settings,
get_environments,
get_local_settings
)
from .entities import (
Expand Down Expand Up @@ -54,7 +53,6 @@
"get_project_settings",
"get_current_project_settings",
"get_anatomy_settings",
"get_environments",
"get_local_settings",

"SystemSettings",
Expand Down
4 changes: 0 additions & 4 deletions openpype/settings/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@

# Metadata keys for work with studio and project overrides
M_OVERRIDDEN_KEY = "__overriden_keys__"
# Metadata key for storing information about environments
M_ENVIRONMENT_KEY = "__environment_keys__"
# Metadata key for storing dynamic created labels
M_DYNAMIC_KEY_LABEL = "__dynamic_keys_labels__"

METADATA_KEYS = frozenset([
M_OVERRIDDEN_KEY,
M_ENVIRONMENT_KEY,
M_DYNAMIC_KEY_LABEL
])

Expand All @@ -35,7 +32,6 @@

__all__ = (
"M_OVERRIDDEN_KEY",
"M_ENVIRONMENT_KEY",
"M_DYNAMIC_KEY_LABEL",

"METADATA_KEYS",
Expand Down
21 changes: 0 additions & 21 deletions openpype/settings/entities/base_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,6 @@ def __init__(self, schema_data):
# Entity is in hierarchy of dynamically created entity
self.is_in_dynamic_item = False

# Entity will save metadata about environments
# - this is current possible only for RawJsonEnity
self.is_env_group = False
# Key of environment group key must be unique across system settings
self.env_group_key = None

# Roles of an entity
self.roles = None

Expand Down Expand Up @@ -286,16 +280,6 @@ def schema_validations(self):
).format(self.group_item.path)
raise EntitySchemaError(self, reason)

# Validate that env group entities will be stored into file.
# - env group entities must store metadata which is not possible if
# metadata would be outside of file
if self.file_item is None and self.is_env_group:
reason = (
"Environment item is not inside file"
" item so can't store metadata for defaults."
)
raise EntitySchemaError(self, reason)

# Dynamic items must not have defined labels. (UI specific)
if self.label and self.is_dynamic_item:
raise EntitySchemaError(
Expand Down Expand Up @@ -862,11 +846,6 @@ def __init__(self, schema_data, parent, is_dynamic_item=False):
if self.is_dynamic_item:
self.require_key = False

# If value should be stored to environments and uder which group key
# - the key may be dynamically changed by it's parent on save
self.env_group_key = self.schema_data.get("env_group_key")
self.is_env_group = bool(self.env_group_key is not None)

# Root item reference
self.root_item = self.parent.root_item

Expand Down
34 changes: 6 additions & 28 deletions openpype/settings/entities/dict_mutable_keys_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from openpype.settings.constants import (
METADATA_KEYS,
M_DYNAMIC_KEY_LABEL,
M_ENVIRONMENT_KEY,
KEY_REGEX,
KEY_ALLOWED_SYMBOLS
)
Expand Down Expand Up @@ -148,11 +147,7 @@ def _add_key(self, key, _ingore_key_validation=False):
):
raise InvalidKeySymbols(self.path, key)

if self.value_is_env_group:
item_schema = copy.deepcopy(self.item_schema)
item_schema["env_group_key"] = key
else:
item_schema = self.item_schema
item_schema = self.item_schema

new_child = self.create_schema_object(item_schema, self, True)
self.children_by_key[key] = new_child
Expand Down Expand Up @@ -216,9 +211,7 @@ def _item_initialization(self):
self.children_label_by_id = {}

self.store_as_list = self.schema_data.get("store_as_list") or False
self.value_is_env_group = (
self.schema_data.get("value_is_env_group") or False
)

self.required_keys = self.schema_data.get("required_keys") or []
self.collapsible_key = self.schema_data.get("collapsible_key") or False
# GUI attributes
Expand All @@ -241,9 +234,6 @@ def _item_initialization(self):
object_type.update(input_modifiers)
self.item_schema = object_type

if self.value_is_env_group:
self.item_schema["env_group_key"] = ""

if self.group_item is None:
self.is_group = True

Expand All @@ -259,10 +249,6 @@ def schema_validations(self):
if used_temp_label:
self.label = None

if self.value_is_env_group and self.store_as_list:
reason = "Item can't store environments metadata to list output."
raise EntitySchemaError(self, reason)

if not self.schema_data.get("object_type"):
reason = (
"Modifiable dictionary must have specified `object_type`."
Expand Down Expand Up @@ -579,18 +565,10 @@ def _settings_value(self):
output.append([key, child_value])
return output

output = {}
for key, child_entity in self.children_by_key.items():
child_value = child_entity.settings_value()
# TODO child should have setter of env group key se child can
# know what env group represents.
if self.value_is_env_group:
if key not in child_value[M_ENVIRONMENT_KEY]:
_metadata = child_value[M_ENVIRONMENT_KEY]
_m_keykey = tuple(_metadata.keys())[0]
env_keys = child_value[M_ENVIRONMENT_KEY].pop(_m_keykey)
child_value[M_ENVIRONMENT_KEY][key] = env_keys
output[key] = child_value
output = {
key: child_entity.settings_value()
for key, child_entity in self.children_by_key.items()
}
output.update(self.metadata)
return output

Expand Down
25 changes: 2 additions & 23 deletions openpype/settings/entities/input_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
EntitySchemaError
)

from openpype.settings.constants import (
METADATA_KEYS,
M_ENVIRONMENT_KEY
)
from openpype.settings.constants import METADATA_KEYS


class EndpointEntity(ItemEntity):
Expand Down Expand Up @@ -534,13 +531,7 @@ def set(self, value):

@property
def metadata(self):
output = {}
if isinstance(self._current_value, dict) and self.is_env_group:
output[M_ENVIRONMENT_KEY] = {
self.env_group_key: list(self._current_value.keys())
}

return output
return {}

@property
def has_unsaved_changes(self):
Expand All @@ -549,15 +540,6 @@ def has_unsaved_changes(self):
result = self.metadata != self._metadata_for_current_state()
return result

def schema_validations(self):
if self.store_as_string and self.is_env_group:
reason = (
"RawJson entity can't store environment group metadata"
" as string."
)
raise EntitySchemaError(self, reason)
super(RawJsonEntity, self).schema_validations()

def _convert_to_valid_type(self, value):
if isinstance(value, STRING_TYPE):
try:
Expand All @@ -583,9 +565,6 @@ def _metadata_for_current_state(self):

def _settings_value(self):
value = super(RawJsonEntity, self)._settings_value()
if self.is_env_group and isinstance(value, dict):
value.update(self.metadata)

if self.store_as_string:
return json.dumps(value)
return value
Expand Down
36 changes: 0 additions & 36 deletions openpype/settings/entities/root_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
get_available_studio_project_settings_overrides_versions,
get_available_studio_project_anatomy_overrides_versions,

find_environments,
apply_overrides
)

Expand Down Expand Up @@ -422,11 +421,6 @@ def defaults_dir(self):
"""
pass

@abstractmethod
def _validate_defaults_to_save(self, value):
"""Validate default values before save."""
pass

def _save_default_values(self):
"""Save default values.

Expand All @@ -435,7 +429,6 @@ def _save_default_values(self):
DEFAULTS.
"""
settings_value = self.settings_value()
self._validate_defaults_to_save(settings_value)

defaults_dir = self.defaults_dir()
for file_path, value in settings_value.items():
Expand Down Expand Up @@ -604,38 +597,13 @@ def defaults_dir(self):
def _save_studio_values(self):
settings_value = self.settings_value()

self._validate_duplicated_env_group(settings_value)

self.log.debug("Saving system settings: {}".format(
json.dumps(settings_value, indent=4)
))
save_studio_settings(settings_value)
# Reset source version after restart
self._source_version = None

def _validate_defaults_to_save(self, value):
"""Valiations of default values before save."""
self._validate_duplicated_env_group(value)

def _validate_duplicated_env_group(self, value, override_state=None):
""" Validate duplicated environment groups.

Raises:
DuplicatedEnvGroups: When value contain duplicated env groups.
"""
value = copy.deepcopy(value)
if override_state is None:
override_state = self._override_state

if override_state is OverrideState.STUDIO:
default_values = get_default_settings()[SYSTEM_SETTINGS_KEY]
final_value = apply_overrides(default_values, value)
else:
final_value = value

# Check if final_value contain duplicated environment groups
find_environments(final_value)

def _save_project_values(self):
"""System settings can't have project overrides.

Expand Down Expand Up @@ -911,10 +879,6 @@ def _save_studio_values(self):
if warnings:
raise SaveWarningExc(warnings)

def _validate_defaults_to_save(self, value):
"""Valiations of default values before save."""
pass

def _validate_values_to_save(self, value):
pass

Expand Down
Loading