add experimental decorator
This commit is contained in:
parent
5f4d9a8cc0
commit
1688463e96
1 changed files with 33 additions and 11 deletions
|
@ -3,37 +3,59 @@ from .enums import NamingScheme, License
|
||||||
from .generic_text import GenericText
|
from .generic_text import GenericText
|
||||||
|
|
||||||
|
|
||||||
|
def generate_properties(attr_names):
|
||||||
|
def decorator(cls):
|
||||||
|
for attr_name in attr_names:
|
||||||
|
def get_attr(self, attr_name=attr_name):
|
||||||
|
return getattr(self, "_" + attr_name)
|
||||||
|
|
||||||
|
prop = property(get_attr)
|
||||||
|
setattr(cls, attr_name, prop)
|
||||||
|
return cls
|
||||||
|
|
||||||
|
return decorator
|
||||||
|
|
||||||
|
|
||||||
|
@generate_properties(['naming_scheme'])
|
||||||
class FormattingConfig:
|
class FormattingConfig:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._naming_scheme: Union[NamingScheme, str] = NamingScheme.clean
|
self._naming_scheme: Optional[Union[NamingScheme, str]] = None
|
||||||
self._license: Optional[List[License]] = None
|
self._license: Optional[List[License]] = None
|
||||||
|
|
||||||
self._extra_header: List[str] = []
|
self._extra_header: Optional[List[str]] = None
|
||||||
self._include_extra_header: bool = True
|
self._include_extra_header: Optional[bool] = None
|
||||||
self._include_build_time: bool = False
|
self._include_build_time: Optional[bool] = None
|
||||||
self._include_pytex_version: bool = False
|
self._include_pytex_version: Optional[bool] = None
|
||||||
self._include_pytex_info_text: bool = False
|
self._include_pytex_info_text: Optional[bool] = None
|
||||||
self._include_repo_version: bool = False
|
self._include_repo_version: Optional[bool] = None
|
||||||
self._include_repo_info_text: bool = False
|
self._include_repo_info_text: Optional[bool] = None
|
||||||
|
|
||||||
self._include_drv: bool = True
|
self._include_drv: Optional[bool] = True
|
||||||
self._include_ins: bool = True
|
self._include_ins: Optional[bool] = True
|
||||||
self._use_docstrip_guards: Optional[List[str]] = None
|
self._use_docstrip_guards: Optional[List[str]] = None
|
||||||
|
|
||||||
self._author: Optional[str] = None
|
self._author: Optional[str] = None
|
||||||
self._licenses = Optional[List[GenericText]]
|
self._licenses = Optional[List[GenericText]]
|
||||||
|
self._version: Optional[str] = None
|
||||||
self._extra_header_file: Optional[GenericText] = None
|
self._extra_header_file: Optional[GenericText] = None
|
||||||
self._pytex_version: Optional[str] = None
|
self._pytex_version: Optional[str] = None
|
||||||
self._pytex_info_text: Optional[GenericText] = None
|
self._pytex_info_text: Optional[GenericText] = None
|
||||||
self._repo_version: Optional[str] = None
|
self._repo_version: Optional[str] = None
|
||||||
self._repo_info_text: Optional[GenericText] = None
|
self._repo_info_text: Optional[GenericText] = None
|
||||||
|
|
||||||
def merge_with(self, other):
|
def merge_with(self, other, strict: bool = False):
|
||||||
"""
|
"""
|
||||||
Merges the other config into this one
|
Merges the other config into this one
|
||||||
:param other:
|
:param other:
|
||||||
|
:param strict: whether conflicting options are allowed or not
|
||||||
:return: self
|
:return: self
|
||||||
"""
|
"""
|
||||||
|
for var in vars(self):
|
||||||
|
if not getattr(self, var):
|
||||||
|
setattr(self, var, getattr(other, var))
|
||||||
|
else:
|
||||||
|
if strict and getattr(other, var) is not None and getattr(self, var) != getattr(other, var):
|
||||||
|
raise NotImplementedError
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue