add experimental decorator

This commit is contained in:
Maximilian Keßler 2022-02-05 23:54:45 +01:00
parent 5f4d9a8cc0
commit 1688463e96

View file

@ -3,37 +3,59 @@ from .enums import NamingScheme, License
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:
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._extra_header: List[str] = []
self._include_extra_header: bool = True
self._include_build_time: bool = False
self._include_pytex_version: bool = False
self._include_pytex_info_text: bool = False
self._include_repo_version: bool = False
self._include_repo_info_text: bool = False
self._extra_header: Optional[List[str]] = None
self._include_extra_header: Optional[bool] = None
self._include_build_time: Optional[bool] = None
self._include_pytex_version: Optional[bool] = None
self._include_pytex_info_text: Optional[bool] = None
self._include_repo_version: Optional[bool] = None
self._include_repo_info_text: Optional[bool] = None
self._include_drv: bool = True
self._include_ins: bool = True
self._include_drv: Optional[bool] = True
self._include_ins: Optional[bool] = True
self._use_docstrip_guards: Optional[List[str]] = None
self._author: Optional[str] = None
self._licenses = Optional[List[GenericText]]
self._version: Optional[str] = None
self._extra_header_file: Optional[GenericText] = None
self._pytex_version: Optional[str] = None
self._pytex_info_text: Optional[GenericText] = None
self._repo_version: Optional[str] = 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
:param other:
:param strict: whether conflicting options are allowed or not
: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