mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
update_dict moved to anatomy and renamed to merge_dict
This commit is contained in:
parent
c486066798
commit
abcbea0507
3 changed files with 38 additions and 49 deletions
|
|
@ -10,17 +10,13 @@ from .mongo import (
|
|||
get_default_components,
|
||||
PypeMongoConnection
|
||||
)
|
||||
from .anatomy import Anatomy
|
||||
|
||||
from .config import (
|
||||
get_datetime_data,
|
||||
load_json,
|
||||
collect_json_from_path,
|
||||
get_presets,
|
||||
get_init_presets,
|
||||
update_dict
|
||||
from .anatomy import (
|
||||
merge_dict,
|
||||
Anatomy
|
||||
)
|
||||
|
||||
from .config import get_datetime_data
|
||||
|
||||
from .env_tools import (
|
||||
env_value_to_bool,
|
||||
get_paths_from_environ
|
||||
|
|
@ -98,9 +94,6 @@ __all__ = [
|
|||
"get_latest_version",
|
||||
"BuildWorkfile",
|
||||
|
||||
"PypeHook",
|
||||
"execute_hook",
|
||||
|
||||
"ApplicationLaunchFailed",
|
||||
"ApplictionExecutableNotFound",
|
||||
"ApplicationNotFound",
|
||||
|
|
@ -127,13 +120,12 @@ __all__ = [
|
|||
"_subprocess",
|
||||
|
||||
"terminal",
|
||||
|
||||
"merge_dict",
|
||||
"Anatomy",
|
||||
|
||||
"get_datetime_data",
|
||||
"load_json",
|
||||
"collect_json_from_path",
|
||||
"get_presets",
|
||||
"get_init_presets",
|
||||
"update_dict",
|
||||
|
||||
"execute",
|
||||
"PypeLogger",
|
||||
"decompose_url",
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ from pype.settings.lib import (
|
|||
get_default_anatomy_settings,
|
||||
get_anatomy_settings
|
||||
)
|
||||
from . import config
|
||||
from .log import PypeLogger
|
||||
|
||||
log = PypeLogger().get_logger(__name__)
|
||||
|
|
@ -20,6 +19,32 @@ except NameError:
|
|||
StringType = str
|
||||
|
||||
|
||||
def merge_dict(main_dict, enhance_dict):
|
||||
"""Merges dictionaries by keys.
|
||||
|
||||
Function call itself if value on key is again dictionary.
|
||||
|
||||
Args:
|
||||
main_dict (dict): First dict to merge second one into.
|
||||
enhance_dict (dict): Second dict to be merged.
|
||||
|
||||
Returns:
|
||||
dict: Merged result.
|
||||
|
||||
.. note:: does not overrides whole value on first found key
|
||||
but only values differences from enhance_dict
|
||||
|
||||
"""
|
||||
for key, value in enhance_dict.items():
|
||||
if key not in main_dict:
|
||||
main_dict[key] = value
|
||||
elif isinstance(value, dict) and isinstance(main_dict[key], dict):
|
||||
main_dict[key] = merge_dict(main_dict[key], value)
|
||||
else:
|
||||
main_dict[key] = value
|
||||
return main_dict
|
||||
|
||||
|
||||
class ProjectNotSet(Exception):
|
||||
"""Exception raised when is created Anatomy without project name."""
|
||||
|
||||
|
|
@ -395,9 +420,7 @@ class TemplatesDict(dict):
|
|||
if key in invalid_types:
|
||||
continue
|
||||
_invalid_types[key] = val
|
||||
invalid_types = config.update_dict(
|
||||
invalid_types, _invalid_types
|
||||
)
|
||||
invalid_types = merge_dict(invalid_types, _invalid_types)
|
||||
return invalid_types
|
||||
|
||||
@property
|
||||
|
|
@ -405,7 +428,7 @@ class TemplatesDict(dict):
|
|||
"""Return used values for all children templates."""
|
||||
used_values = {}
|
||||
for value in self.values():
|
||||
used_values = config.update_dict(used_values, value.used_values)
|
||||
used_values = merge_dict(used_values, value.used_values)
|
||||
return used_values
|
||||
|
||||
def get_solved(self):
|
||||
|
|
@ -840,7 +863,7 @@ class Templates:
|
|||
|
||||
root_key = "{" + root_key + "}"
|
||||
|
||||
roots_dict = config.update_dict(
|
||||
roots_dict = merge_dict(
|
||||
roots_dict,
|
||||
self._keys_to_dicts(used_root_keys, root_key)
|
||||
)
|
||||
|
|
|
|||
|
|
@ -74,29 +74,3 @@ def get_datetime_data(datetime_obj=None):
|
|||
"S": str(int(seconds)),
|
||||
"SS": str(seconds),
|
||||
}
|
||||
|
||||
|
||||
def update_dict(main_dict, enhance_dict):
|
||||
"""Merges dictionaries by keys.
|
||||
|
||||
Function call itself if value on key is again dictionary.
|
||||
|
||||
Args:
|
||||
main_dict (dict): First dict to merge second one into.
|
||||
enhance_dict (dict): Second dict to be merged.
|
||||
|
||||
Returns:
|
||||
dict: Merged result.
|
||||
|
||||
.. note:: does not overrides whole value on first found key
|
||||
but only values differences from enhance_dict
|
||||
|
||||
"""
|
||||
for key, value in enhance_dict.items():
|
||||
if key not in main_dict:
|
||||
main_dict[key] = value
|
||||
elif isinstance(value, dict) and isinstance(main_dict[key], dict):
|
||||
main_dict[key] = update_dict(main_dict[key], value)
|
||||
else:
|
||||
main_dict[key] = value
|
||||
return main_dict
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue