MakeDataConfig implements RuleSetHolder, complete configuration support
This commit is contained in:
@@ -1,2 +1,3 @@
|
|||||||
from .cli import run
|
from .cli import run
|
||||||
|
|
||||||
run()
|
run()
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ from typing import (TYPE_CHECKING, Any, Callable, Dict, Final, Iterable,
|
|||||||
|
|
||||||
from .config import Config, FileConfig
|
from .config import Config, FileConfig
|
||||||
from .output_directory import expand_paths
|
from .output_directory import expand_paths
|
||||||
|
from .rule_set import RuleSet, RuleSetConfig, RuleSetHolder
|
||||||
from .shell import abort, warn
|
from .shell import abort, warn
|
||||||
from .utils import RuntimeCodeError, ensure_not_whitespace
|
from .utils import RuntimeCodeError, ensure_not_whitespace
|
||||||
|
|
||||||
@@ -142,16 +143,18 @@ class MakeAssetData:
|
|||||||
|
|
||||||
AVAILABLE_DATA_CONFIGS: Dict[Union[str, Callable[[str], str]], type['MakeDataConfig']] = {}
|
AVAILABLE_DATA_CONFIGS: Dict[Union[str, Callable[[str], str]], type['MakeDataConfig']] = {}
|
||||||
|
|
||||||
class MakeDataConfig(FileConfig, metaclass=ABCMeta):
|
class MakeDataConfig(RuleSetConfig, FileConfig, RuleSetHolder, metaclass=ABCMeta):
|
||||||
defaults: FileConfig
|
defaults: FileConfig
|
||||||
current_project: Final[str]
|
current_project: Final[str]
|
||||||
project_unique_name: Final[str]
|
project_unique_name: Final[str]
|
||||||
|
|
||||||
def __init__(self, path: str, defaults: FileConfig) -> None:
|
def __init__(self, path: str, defaults: FileConfig, rule_set: Optional[RuleSet] = None) -> None:
|
||||||
if not isfile(path):
|
if not isfile(path):
|
||||||
abort(f"Not found {basename(path)!r}, are you sure that selected project exists?")
|
abort(f"Not found {basename(path)!r}, are you sure that selected project exists?")
|
||||||
|
RuleSetConfig.__init__(self)
|
||||||
self.current_project = dirname(abspath(path))
|
self.current_project = dirname(abspath(path))
|
||||||
super().__init__(path, defaults, raise_non_existing=True)
|
FileConfig.__init__(self, path, defaults, raise_non_existing=True)
|
||||||
|
RuleSetHolder.__init__(self, rule_set=rule_set)
|
||||||
from .output_directory import unique_folder_name
|
from .output_directory import unique_folder_name
|
||||||
self.project_unique_name = unique_folder_name(self.directory)
|
self.project_unique_name = unique_folder_name(self.directory)
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
from functools import cmp_to_key
|
from functools import cmp_to_key
|
||||||
from os.path import basename, isfile, join, splitext
|
from os.path import basename, isfile, join, splitext
|
||||||
from typing import Any, Iterable, MutableSequence, Optional, Union, override
|
from typing import (Any, Iterable, MutableMapping, MutableSequence, Optional,
|
||||||
|
Union, override)
|
||||||
|
|
||||||
from .config import Config, FileConfig
|
from .config import Config, FileConfig
|
||||||
from .language import (MakeAssetData, MakeDataConfig, MakeJavaData,
|
from .language import (MakeAssetData, MakeDataConfig, MakeJavaData,
|
||||||
@@ -47,6 +48,21 @@ class MakeConfig(MakeDataConfig):
|
|||||||
config.save_as_file()
|
config.save_as_file()
|
||||||
return changes
|
return changes
|
||||||
|
|
||||||
|
@override
|
||||||
|
def update_properties(self) -> None:
|
||||||
|
configurations = self.get_value("configurations")
|
||||||
|
if not isinstance(configurations, MutableMapping):
|
||||||
|
self.overrides = None
|
||||||
|
return
|
||||||
|
overrides = None
|
||||||
|
for value_set, configuration in configurations.items():
|
||||||
|
if not self.is_relevant_configuration(value_set) or not isinstance(configuration, MutableMapping):
|
||||||
|
continue
|
||||||
|
if overrides is None:
|
||||||
|
overrides = Config()
|
||||||
|
overrides.merge_config(configuration)
|
||||||
|
self.overrides = overrides
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@override
|
@override
|
||||||
def is_pack(self) -> bool:
|
def is_pack(self) -> bool:
|
||||||
|
|||||||
@@ -90,11 +90,16 @@ class RuleSetHolder(metaclass=ABCMeta):
|
|||||||
def is_relevant_configuration(self, value_set: str, allow_unresolved_properties: bool = True) -> bool:
|
def is_relevant_configuration(self, value_set: str, allow_unresolved_properties: bool = True) -> bool:
|
||||||
return self.rule_set.is_relevant(self.properties, value_set, allow_unresolved_properties=allow_unresolved_properties)
|
return self.rule_set.is_relevant(self.properties, value_set, allow_unresolved_properties=allow_unresolved_properties)
|
||||||
|
|
||||||
|
def update_properties(self) -> None:
|
||||||
|
pass
|
||||||
|
|
||||||
def bisect_properties(self, *properties: str) -> None:
|
def bisect_properties(self, *properties: str) -> None:
|
||||||
self.rule_set.bisect_values(self.properties, *properties)
|
self.rule_set.bisect_values(self.properties, *properties)
|
||||||
|
self.update_properties()
|
||||||
|
|
||||||
def remove_rules(self, *rules: str) -> None:
|
def remove_rules(self, *rules: str) -> None:
|
||||||
self.rule_set.remove_rules(self.properties, *rules)
|
self.rule_set.remove_rules(self.properties, *rules)
|
||||||
|
self.update_properties()
|
||||||
|
|
||||||
class RuleSetConfig(Config):
|
class RuleSetConfig(Config):
|
||||||
def __init__(self, map: Optional[ConfigSupportsKeysAndGetItem] = None, defaults: Optional[Config] = None, overrides: Optional[Config] = None):
|
def __init__(self, map: Optional[ConfigSupportsKeysAndGetItem] = None, defaults: Optional[Config] = None, overrides: Optional[Config] = None):
|
||||||
|
|||||||
Reference in New Issue
Block a user