mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-27 06:12:19 +01:00
exceptions moved to single file
This commit is contained in:
parent
9c4b841695
commit
33beb4ffc6
10 changed files with 125 additions and 99 deletions
|
|
@ -1,7 +1,15 @@
|
|||
from .exceptions import (
|
||||
DefaultsNotDefined,
|
||||
InvalidValueType,
|
||||
SchemaMissingFileInfo,
|
||||
SchemeGroupHierarchyBug,
|
||||
SchemaDuplicatedKeys,
|
||||
SchemaDuplicatedEnvGroupKeys,
|
||||
SchemaTemplateMissingKeys
|
||||
)
|
||||
from .lib import (
|
||||
NOT_SET,
|
||||
OverrideState,
|
||||
DefaultsNotDefined
|
||||
OverrideState
|
||||
)
|
||||
from .base_entity import (
|
||||
BaseEntity,
|
||||
|
|
@ -33,9 +41,16 @@ from .dict_mutable_keys_entity import DictMutableKeysEntity
|
|||
|
||||
|
||||
__all__ = (
|
||||
"DefaultsNotDefined",
|
||||
"InvalidValueType",
|
||||
"SchemaMissingFileInfo",
|
||||
"SchemeGroupHierarchyBug",
|
||||
"SchemaDuplicatedKeys",
|
||||
"SchemaDuplicatedEnvGroupKeys",
|
||||
"SchemaTemplateMissingKeys",
|
||||
|
||||
"NOT_SET",
|
||||
"OverrideState",
|
||||
"DefaultsNotDefined",
|
||||
|
||||
"BaseEntity",
|
||||
"GUIEntity",
|
||||
|
|
|
|||
|
|
@ -8,25 +8,14 @@ from .lib import (
|
|||
OverrideState
|
||||
)
|
||||
|
||||
from .exceptions import (
|
||||
InvalidValueType,
|
||||
SchemeGroupHierarchyBug
|
||||
)
|
||||
|
||||
from pype.lib import PypeLogger
|
||||
|
||||
|
||||
class InvalidValueType(Exception):
|
||||
msg_template = "{}"
|
||||
|
||||
def __init__(self, valid_types, invalid_type, path):
|
||||
msg = "Path \"{}\". ".format(path)
|
||||
|
||||
joined_types = ", ".join(
|
||||
[str(valid_type) for valid_type in valid_types]
|
||||
)
|
||||
msg += "Got invalid type \"{}\". Expected: {}".format(
|
||||
invalid_type, joined_types
|
||||
)
|
||||
self.msg = msg
|
||||
super(InvalidValueType, self).__init__(msg)
|
||||
|
||||
|
||||
@six.add_metaclass(ABCMeta)
|
||||
class BaseEntity:
|
||||
"""Partially abstract class for Setting's item type workflow."""
|
||||
|
|
|
|||
|
|
@ -3,8 +3,7 @@ import copy
|
|||
from .lib import (
|
||||
WRAPPER_TYPES,
|
||||
OverrideState,
|
||||
NOT_SET,
|
||||
SchemaDuplicatedKeys
|
||||
NOT_SET
|
||||
)
|
||||
from pype.settings.constants import (
|
||||
METADATA_KEYS,
|
||||
|
|
@ -15,6 +14,7 @@ from . import (
|
|||
BoolEntity,
|
||||
GUIEntity
|
||||
)
|
||||
from .exceptions import SchemaDuplicatedKeys
|
||||
|
||||
|
||||
class DictImmutableKeysEntity(ItemEntity):
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@ import copy
|
|||
|
||||
from .lib import (
|
||||
NOT_SET,
|
||||
OverrideState,
|
||||
DefaultsNotDefined
|
||||
OverrideState
|
||||
)
|
||||
from . import ItemEntity
|
||||
from .exceptions import DefaultsNotDefined
|
||||
from pype.settings.constants import (
|
||||
METADATA_KEYS,
|
||||
M_DYNAMIC_KEY_LABEL,
|
||||
|
|
|
|||
86
pype/settings/entities/exceptions.py
Normal file
86
pype/settings/entities/exceptions.py
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
class DefaultsNotDefined(Exception):
|
||||
def __init__(self, obj):
|
||||
msg = "Default values for object are not set. {}".format(obj.path)
|
||||
super(DefaultsNotDefined, self).__init__(msg)
|
||||
|
||||
|
||||
class InvalidValueType(Exception):
|
||||
msg_template = "{}"
|
||||
|
||||
def __init__(self, valid_types, invalid_type, path):
|
||||
msg = "Path \"{}\". ".format(path)
|
||||
|
||||
joined_types = ", ".join(
|
||||
[str(valid_type) for valid_type in valid_types]
|
||||
)
|
||||
msg += "Got invalid type \"{}\". Expected: {}".format(
|
||||
invalid_type, joined_types
|
||||
)
|
||||
self.msg = msg
|
||||
super(InvalidValueType, self).__init__(msg)
|
||||
|
||||
|
||||
class SchemaMissingFileInfo(Exception):
|
||||
def __init__(self, invalid):
|
||||
full_path_keys = []
|
||||
for item in invalid:
|
||||
full_path_keys.append("\"{}\"".format("/".join(item)))
|
||||
|
||||
msg = (
|
||||
"Schema has missing definition of output file (\"is_file\" key)"
|
||||
" for keys. [{}]"
|
||||
).format(", ".join(full_path_keys))
|
||||
super(SchemaMissingFileInfo, self).__init__(msg)
|
||||
|
||||
|
||||
class SchemeGroupHierarchyBug(Exception):
|
||||
def __init__(self, entity_path):
|
||||
msg = (
|
||||
"Items with attribute \"is_group\" can't have another item with"
|
||||
" \"is_group\" attribute as child. Error happened in entity: {}"
|
||||
).format(entity_path)
|
||||
super(SchemeGroupHierarchyBug, self).__init__(msg)
|
||||
|
||||
|
||||
class SchemaDuplicatedKeys(Exception):
|
||||
def __init__(self, entity_path, key):
|
||||
msg = (
|
||||
"Schema item contain duplicated key \"{}\" in"
|
||||
" one hierarchy level. {}"
|
||||
).format(key, entity_path)
|
||||
super(SchemaDuplicatedKeys, self).__init__(msg)
|
||||
|
||||
|
||||
class SchemaDuplicatedEnvGroupKeys(Exception):
|
||||
def __init__(self, invalid):
|
||||
items = []
|
||||
for key_path, keys in invalid.items():
|
||||
joined_keys = ", ".join([
|
||||
"\"{}\"".format(key) for key in keys
|
||||
])
|
||||
items.append("\"{}\" ({})".format(key_path, joined_keys))
|
||||
|
||||
msg = (
|
||||
"Schema items contain duplicated environment group keys. {}"
|
||||
).format(" || ".join(items))
|
||||
super(SchemaDuplicatedEnvGroupKeys, self).__init__(msg)
|
||||
|
||||
|
||||
class SchemaTemplateMissingKeys(Exception):
|
||||
def __init__(self, missing_keys, required_keys, template_name=None):
|
||||
self.missing_keys = missing_keys
|
||||
self.required_keys = required_keys
|
||||
if template_name:
|
||||
msg = f"Schema template \"{template_name}\" require more keys.\n"
|
||||
else:
|
||||
msg = ""
|
||||
msg += "Required keys: {}\nMissing keys: {}".format(
|
||||
self.join_keys(required_keys),
|
||||
self.join_keys(missing_keys)
|
||||
)
|
||||
super(SchemaTemplateMissingKeys, self).__init__(msg)
|
||||
|
||||
def join_keys(self, keys):
|
||||
return ", ".join([
|
||||
f"\"{key}\"" for key in keys
|
||||
])
|
||||
|
|
@ -2,9 +2,9 @@ import copy
|
|||
from .item_entities import ItemEntity
|
||||
from .lib import (
|
||||
NOT_SET,
|
||||
OverrideState,
|
||||
DefaultsNotDefined
|
||||
OverrideState
|
||||
)
|
||||
from .exceptions import DefaultsNotDefined
|
||||
from pype.settings.constants import (
|
||||
METADATA_KEYS,
|
||||
M_ENVIRONMENT_KEY
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@ from abc import abstractmethod
|
|||
|
||||
from .lib import (
|
||||
NOT_SET,
|
||||
OverrideState,
|
||||
OverrideState
|
||||
)
|
||||
from .exceptions import (
|
||||
DefaultsNotDefined,
|
||||
SchemeGroupHierarchyBug
|
||||
)
|
||||
|
|
|
|||
|
|
@ -3,11 +3,10 @@ import re
|
|||
import json
|
||||
import copy
|
||||
|
||||
|
||||
class DefaultsNotDefined(Exception):
|
||||
def __init__(self, obj):
|
||||
msg = "Default values for object are not set. {}".format(obj.path)
|
||||
super(DefaultsNotDefined, self).__init__(msg)
|
||||
from .exceptions import (
|
||||
SchemaTemplateMissingKeys,
|
||||
SchemaDuplicatedEnvGroupKeys
|
||||
)
|
||||
|
||||
|
||||
WRAPPER_TYPES = ["form", "collapsible-wrap"]
|
||||
|
|
@ -190,72 +189,6 @@ def _fill_inner_schemas(schema_data, schema_collection, schema_templates):
|
|||
return schema_data
|
||||
|
||||
|
||||
class SchemaTemplateMissingKeys(Exception):
|
||||
def __init__(self, missing_keys, required_keys, template_name=None):
|
||||
self.missing_keys = missing_keys
|
||||
self.required_keys = required_keys
|
||||
if template_name:
|
||||
msg = f"Schema template \"{template_name}\" require more keys.\n"
|
||||
else:
|
||||
msg = ""
|
||||
msg += "Required keys: {}\nMissing keys: {}".format(
|
||||
self.join_keys(required_keys),
|
||||
self.join_keys(missing_keys)
|
||||
)
|
||||
super(SchemaTemplateMissingKeys, self).__init__(msg)
|
||||
|
||||
def join_keys(self, keys):
|
||||
return ", ".join([
|
||||
f"\"{key}\"" for key in keys
|
||||
])
|
||||
|
||||
|
||||
class SchemaMissingFileInfo(Exception):
|
||||
def __init__(self, invalid):
|
||||
full_path_keys = []
|
||||
for item in invalid:
|
||||
full_path_keys.append("\"{}\"".format("/".join(item)))
|
||||
|
||||
msg = (
|
||||
"Schema has missing definition of output file (\"is_file\" key)"
|
||||
" for keys. [{}]"
|
||||
).format(", ".join(full_path_keys))
|
||||
super(SchemaMissingFileInfo, self).__init__(msg)
|
||||
|
||||
|
||||
class SchemeGroupHierarchyBug(Exception):
|
||||
def __init__(self, entity_path):
|
||||
msg = (
|
||||
"Items with attribute \"is_group\" can't have another item with"
|
||||
" \"is_group\" attribute as child. Error happened in entity: {}"
|
||||
).format(entity_path)
|
||||
super(SchemeGroupHierarchyBug, self).__init__(msg)
|
||||
|
||||
|
||||
class SchemaDuplicatedKeys(Exception):
|
||||
def __init__(self, entity_path, key):
|
||||
msg = (
|
||||
"Schema item contain duplicated key \"{}\" in"
|
||||
" one hierarchy level. {}"
|
||||
).format(key, entity_path)
|
||||
super(SchemaDuplicatedKeys, self).__init__(msg)
|
||||
|
||||
|
||||
class SchemaDuplicatedEnvGroupKeys(Exception):
|
||||
def __init__(self, invalid):
|
||||
items = []
|
||||
for key_path, keys in invalid.items():
|
||||
joined_keys = ", ".join([
|
||||
"\"{}\"".format(key) for key in keys
|
||||
])
|
||||
items.append("\"{}\" ({})".format(key_path, joined_keys))
|
||||
|
||||
msg = (
|
||||
"Schema items contain duplicated environment group keys. {}"
|
||||
).format(" || ".join(items))
|
||||
super(SchemaDuplicatedEnvGroupKeys, self).__init__(msg)
|
||||
|
||||
|
||||
# TODO reimplement logic inside entities
|
||||
def validate_environment_groups_uniquenes(
|
||||
schema_data, env_groups=None, keys=None
|
||||
|
|
|
|||
|
|
@ -5,9 +5,9 @@ from . import (
|
|||
)
|
||||
from .lib import (
|
||||
NOT_SET,
|
||||
OverrideState,
|
||||
DefaultsNotDefined
|
||||
OverrideState
|
||||
)
|
||||
from .exceptions import DefaultsNotDefined
|
||||
|
||||
|
||||
class ListEntity(ItemEntity):
|
||||
|
|
|
|||
|
|
@ -114,6 +114,7 @@ class RootEntity(BaseItemEntity):
|
|||
|
||||
known_abstract_classes = (
|
||||
entities.BaseEntity,
|
||||
entities.BaseItemEntity,
|
||||
entities.ItemEntity,
|
||||
entities.InputEntity
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue