2022-02-09 12:06:15 +01:00
|
|
|
from typing import List, Optional, Dict
|
2022-02-07 17:32:46 +01:00
|
|
|
|
2022-02-07 18:36:30 +01:00
|
|
|
from .constants import *
|
2022-02-06 22:37:41 +01:00
|
|
|
from .enums import NamingScheme
|
2022-02-07 18:36:30 +01:00
|
|
|
from .enums import TeXType, TeXFlavour
|
2022-02-05 22:40:10 +01:00
|
|
|
from .generic_text import GenericText
|
2022-02-07 21:42:31 +01:00
|
|
|
from .config import Config
|
2022-02-04 11:39:15 +01:00
|
|
|
|
|
|
|
|
2022-02-06 15:09:25 +01:00
|
|
|
class FormattingConfig(Config):
|
2022-02-04 11:39:15 +01:00
|
|
|
def __init__(self):
|
2022-02-08 16:24:42 +01:00
|
|
|
self._naming_scheme: Optional[NamingScheme] = None
|
2022-02-06 22:37:41 +01:00
|
|
|
self._license: Optional[GenericText] = None
|
2022-02-06 16:52:24 +01:00
|
|
|
self._description: Optional[str] = None
|
2022-02-04 11:39:15 +01:00
|
|
|
|
2022-02-05 23:54:45 +01:00
|
|
|
self._include_extra_header: 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
|
2022-02-06 22:29:44 +01:00
|
|
|
self._include_time: Optional[bool] = None
|
2022-02-06 23:52:44 +01:00
|
|
|
self._include_license: Optional[bool] = None
|
2022-02-04 11:39:15 +01:00
|
|
|
|
2022-02-06 15:28:04 +01:00
|
|
|
self._extra_header: Optional[GenericText] = None
|
2022-02-05 22:40:10 +01:00
|
|
|
self._author: Optional[str] = None
|
2022-02-05 23:54:45 +01:00
|
|
|
self._version: Optional[str] = None
|
2022-02-05 22:40:10 +01:00
|
|
|
self._pytex_info_text: Optional[GenericText] = None
|
|
|
|
self._repo_info_text: Optional[GenericText] = None
|
|
|
|
|
2022-02-06 20:38:14 +01:00
|
|
|
self._include_drv: Optional[bool] = None
|
|
|
|
self._include_ins: Optional[bool] = None
|
2022-02-06 22:34:43 +01:00
|
|
|
self._docstrip_guards: Optional[List[str]] = None
|
|
|
|
|
|
|
|
self._doc_dependencies: Optional[List[str]] = None
|
|
|
|
self._tex_dependencies: Optional[List[str]] = None
|
2022-02-06 15:09:25 +01:00
|
|
|
|
2022-02-06 23:52:44 +01:00
|
|
|
self._tex_type: Optional[TeXType] = None
|
|
|
|
self._tex_flavour: Optional[TeXFlavour] = None
|
|
|
|
|
2022-02-08 16:34:59 +01:00
|
|
|
self._escape_character: Optional[str] = None
|
|
|
|
|
2022-02-07 21:42:31 +01:00
|
|
|
def set_from_json(self, content: Optional[Dict]):
|
2022-02-08 16:24:42 +01:00
|
|
|
filled_content = self._fill_keys(content)
|
2022-02-07 00:42:03 +01:00
|
|
|
|
2022-02-08 16:24:42 +01:00
|
|
|
info = filled_content[YAML_INFO]
|
2022-02-07 00:42:03 +01:00
|
|
|
self._author = info[YAML_AUTHOR]
|
2022-02-09 17:31:06 +01:00
|
|
|
self._naming_scheme = NamingScheme.parse(info[YAML_NAMING_SCHEME])
|
2022-02-09 11:55:18 +01:00
|
|
|
self._tex_flavour = TeXFlavour.parse(info[YAML_TEX_FLAVOUR])
|
|
|
|
self._tex_type = TeXType.parse(info[YAML_TEX_TYPE])
|
2022-02-07 00:42:03 +01:00
|
|
|
self._description = info[YAML_DESCRIPTION]
|
2022-02-07 18:33:00 +01:00
|
|
|
self._version = info[YAML_VERSION]
|
2022-02-07 00:42:03 +01:00
|
|
|
|
2022-02-08 16:24:42 +01:00
|
|
|
header = filled_content[YAML_HEADER]
|
2022-02-07 00:42:03 +01:00
|
|
|
extra = header[YAML_EXTRA]
|
|
|
|
self._include_extra_header = extra[YAML_INCLUDE_EXTRA_HEADER]
|
2022-02-09 19:14:00 +01:00
|
|
|
if extra[YAML_PATH] or extra[YAML_TEXT]:
|
|
|
|
self._extra_header = GenericText(
|
|
|
|
extra[YAML_PATH] if extra[YAML_PATH] else extra[YAML_TEXT]
|
|
|
|
)
|
2022-02-06 23:52:44 +01:00
|
|
|
|
2022-02-07 01:15:14 +01:00
|
|
|
repo = header[YAML_REPO]
|
|
|
|
self._include_repo_info_text = repo[YAML_INCLUDE_INFO_TEXT]
|
|
|
|
self._include_repo_version = repo[YAML_INCLUDE_VERSION]
|
2022-02-09 19:14:00 +01:00
|
|
|
if repo[YAML_PATH] or repo[YAML_TEXT]:
|
|
|
|
self._repo_info_text = GenericText(
|
|
|
|
repo[YAML_PATH] if repo[YAML_PATH] else repo[YAML_TEXT]
|
|
|
|
)
|
2022-02-07 01:15:14 +01:00
|
|
|
|
|
|
|
pytex = header[YAML_PYTEX]
|
|
|
|
self._include_pytex_info_text = pytex[YAML_INCLUDE_INFO_TEXT]
|
|
|
|
self._include_pytex_version = pytex[YAML_INCLUDE_VERSION]
|
2022-02-09 19:14:00 +01:00
|
|
|
if pytex[YAML_PATH] or pytex[YAML_TEXT]:
|
|
|
|
self._pytex_info_text = GenericText(
|
|
|
|
pytex[YAML_PATH] if pytex[YAML_PATH] else pytex[YAML_TEXT]
|
|
|
|
)
|
2022-02-07 01:15:14 +01:00
|
|
|
|
|
|
|
self._include_time = header[YAML_INCLUDE_TIME]
|
|
|
|
|
2022-02-07 17:10:12 +01:00
|
|
|
license_ = header[YAML_LICENSE]
|
|
|
|
self._include_license = license_[YAML_INCLUDE_LICENSE]
|
2022-02-09 19:14:00 +01:00
|
|
|
if license_[YAML_PATH] or license_[YAML_TEXT]:
|
|
|
|
self._license = GenericText(
|
|
|
|
license_[YAML_PATH] if license_[YAML_PATH] else license_[YAML_TEXT]
|
|
|
|
)
|
2022-02-07 01:15:14 +01:00
|
|
|
|
2022-02-08 16:24:42 +01:00
|
|
|
docstrip = filled_content[YAML_DOCSTRIP]
|
2022-02-07 01:15:14 +01:00
|
|
|
self._include_drv = docstrip[YAML_INCLUDE_DRV]
|
|
|
|
self._include_ins = docstrip[YAML_INCLUDE_INS]
|
|
|
|
self._docstrip_guards = docstrip[YAML_DOCSTRIP_GUARDS]
|
|
|
|
|
2022-02-06 23:52:44 +01:00
|
|
|
def to_json(self) -> Dict:
|
|
|
|
return {
|
|
|
|
YAML_INFO: {
|
|
|
|
YAML_AUTHOR: self._author,
|
|
|
|
YAML_NAMING_SCHEME: self._naming_scheme,
|
|
|
|
YAML_TEX_FLAVOUR: self._tex_flavour,
|
|
|
|
YAML_TEX_TYPE: self._tex_type,
|
2022-02-07 00:04:31 +01:00
|
|
|
YAML_VERSION: self._version,
|
|
|
|
YAML_DESCRIPTION: self._description
|
2022-02-06 23:52:44 +01:00
|
|
|
},
|
|
|
|
YAML_HEADER: {
|
|
|
|
YAML_EXTRA: {
|
|
|
|
YAML_INCLUDE_EXTRA_HEADER: self._include_extra_header,
|
2022-02-07 00:42:03 +01:00
|
|
|
YAML_PATH: self._extra_header.pathname if self._extra_header else None,
|
2022-02-07 00:04:31 +01:00
|
|
|
YAML_TEXT: self._extra_header.real_text if self._extra_header else None
|
2022-02-06 23:52:44 +01:00
|
|
|
},
|
|
|
|
YAML_REPO: {
|
|
|
|
YAML_INCLUDE_INFO_TEXT: self._include_repo_info_text,
|
|
|
|
YAML_INCLUDE_VERSION: self._include_repo_version,
|
2022-02-07 00:42:03 +01:00
|
|
|
YAML_PATH: self._repo_info_text.pathname if self._repo_info_text else None,
|
2022-02-07 00:04:31 +01:00
|
|
|
YAML_TEXT: self._repo_info_text.real_text if self._repo_info_text else None
|
2022-02-06 23:52:44 +01:00
|
|
|
},
|
|
|
|
YAML_PYTEX: {
|
|
|
|
YAML_INCLUDE_INFO_TEXT: self._include_pytex_info_text,
|
|
|
|
YAML_INCLUDE_VERSION: self._include_pytex_version,
|
2022-02-07 00:04:31 +01:00
|
|
|
YAML_PATH: self._pytex_info_text.path if self._pytex_info_text else None,
|
|
|
|
YAML_TEXT: self._pytex_info_text.real_text if self._pytex_info_text else None
|
2022-02-06 23:52:44 +01:00
|
|
|
},
|
|
|
|
YAML_INCLUDE_TIME: self._include_time,
|
|
|
|
YAML_LICENSE: {
|
|
|
|
YAML_INCLUDE_LICENSE: self._include_license,
|
2022-02-07 00:04:31 +01:00
|
|
|
YAML_PATH: self._license.path if self._license else None,
|
|
|
|
YAML_TEXT: self._license.real_text if self._license else None
|
2022-02-06 23:52:44 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
YAML_DOCSTRIP: {
|
|
|
|
YAML_INCLUDE_DRV: self._include_drv,
|
|
|
|
YAML_INCLUDE_INS: self._include_ins,
|
|
|
|
YAML_DOCSTRIP_GUARDS: self._docstrip_guards
|
|
|
|
},
|
|
|
|
YAML_DEPENDENCIES: {
|
|
|
|
YAML_DOC_DEPENDENCIES: self._doc_dependencies,
|
|
|
|
YAML_TEX_DEPENDENCIES: self._tex_dependencies
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-09 21:11:46 +01:00
|
|
|
@property
|
|
|
|
def has_description(self) -> bool:
|
|
|
|
return self._description is not None
|
|
|
|
|
2022-02-06 15:09:25 +01:00
|
|
|
@property
|
|
|
|
def naming_scheme(self) -> NamingScheme:
|
|
|
|
if self._naming_scheme is None:
|
|
|
|
return NamingScheme.prepend_author
|
|
|
|
else:
|
|
|
|
return self._naming_scheme
|
|
|
|
|
2022-02-06 22:58:43 +01:00
|
|
|
@naming_scheme.setter
|
|
|
|
def naming_scheme(self, naming_scheme: NamingScheme):
|
|
|
|
self._naming_scheme = naming_scheme
|
|
|
|
|
2022-02-06 15:09:25 +01:00
|
|
|
@property
|
2022-02-06 22:37:41 +01:00
|
|
|
def license(self) -> GenericText:
|
2022-02-06 15:09:25 +01:00
|
|
|
if self._license is None:
|
2022-02-06 23:52:44 +01:00
|
|
|
return GenericText()
|
2022-02-06 15:09:25 +01:00
|
|
|
else:
|
|
|
|
return self._license
|
|
|
|
|
2022-02-06 22:58:43 +01:00
|
|
|
@license.setter
|
2022-02-07 17:33:45 +01:00
|
|
|
def license(self, license_: GenericText):
|
|
|
|
self._license = license_
|
2022-02-06 22:58:43 +01:00
|
|
|
|
2022-02-06 15:09:25 +01:00
|
|
|
@property
|
|
|
|
def include_extra_header(self) -> bool:
|
|
|
|
if self._include_extra_header is None:
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
return self._include_extra_header
|
|
|
|
|
2022-02-06 22:58:43 +01:00
|
|
|
@include_extra_header.setter
|
|
|
|
def include_extra_header(self, include: bool):
|
|
|
|
self._include_extra_header = include
|
|
|
|
|
2022-02-06 15:09:25 +01:00
|
|
|
@property
|
|
|
|
def include_pytex_version(self) -> bool:
|
|
|
|
if self._include_pytex_version is None:
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
return self._include_pytex_version
|
|
|
|
|
2022-02-06 22:58:43 +01:00
|
|
|
@include_pytex_version.setter
|
|
|
|
def include_pytex_version(self, include: bool):
|
|
|
|
self._include_pytex_version = include
|
|
|
|
|
2022-02-06 15:09:25 +01:00
|
|
|
@property
|
|
|
|
def include_pytex_info_text(self) -> bool:
|
|
|
|
if self._include_pytex_info_text is None:
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
return self._include_pytex_info_text
|
|
|
|
|
2022-02-06 22:58:43 +01:00
|
|
|
@include_pytex_info_text.setter
|
|
|
|
def include_pytex_info_text(self, include: bool):
|
|
|
|
self._include_pytex_info_text = include
|
|
|
|
|
2022-02-06 15:09:25 +01:00
|
|
|
@property
|
|
|
|
def include_repo_version(self) -> bool:
|
|
|
|
if self._include_repo_version is None:
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
return self._include_repo_version
|
|
|
|
|
2022-02-06 22:58:43 +01:00
|
|
|
@include_repo_version.setter
|
|
|
|
def include_repo_version(self, include: bool):
|
|
|
|
self._include_repo_version = include
|
|
|
|
|
2022-02-06 15:09:25 +01:00
|
|
|
@property
|
|
|
|
def include_repo_info_text(self) -> bool:
|
|
|
|
if self._include_repo_info_text is None:
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
return self._include_repo_info_text
|
|
|
|
|
2022-02-06 22:58:43 +01:00
|
|
|
@include_repo_info_text.setter
|
|
|
|
def include_repo_info_text(self, include: bool):
|
|
|
|
self._include_repo_info_text = include
|
|
|
|
|
2022-02-06 15:09:25 +01:00
|
|
|
@property
|
2022-02-06 15:28:04 +01:00
|
|
|
def extra_header(self) -> GenericText:
|
2022-02-06 15:09:25 +01:00
|
|
|
if self._extra_header is None:
|
2022-02-06 23:52:44 +01:00
|
|
|
return GenericText()
|
2022-02-06 15:09:25 +01:00
|
|
|
else:
|
|
|
|
return self._extra_header
|
|
|
|
|
2022-02-06 22:58:43 +01:00
|
|
|
@extra_header.setter
|
|
|
|
def extra_header(self, extra_header: GenericText):
|
|
|
|
self._extra_header = extra_header
|
|
|
|
|
2022-02-06 15:09:25 +01:00
|
|
|
@property
|
|
|
|
def author(self) -> str:
|
|
|
|
if self._author is None:
|
|
|
|
return "MISSING AUTHOR"
|
|
|
|
else:
|
|
|
|
return self._author
|
|
|
|
|
2022-02-06 22:58:43 +01:00
|
|
|
@author.setter
|
|
|
|
def author(self, author: str):
|
|
|
|
self._author = author
|
|
|
|
|
2022-02-06 15:09:25 +01:00
|
|
|
@property
|
|
|
|
def version(self) -> str:
|
|
|
|
if self._version is None:
|
|
|
|
return "0.0.0"
|
|
|
|
else:
|
|
|
|
return self._version
|
|
|
|
|
2022-02-06 22:58:43 +01:00
|
|
|
@version.setter
|
|
|
|
def version(self, version: str):
|
|
|
|
self._version = version
|
|
|
|
|
2022-02-06 15:09:25 +01:00
|
|
|
@property
|
|
|
|
def pytex_info_text(self) -> GenericText:
|
|
|
|
if self._pytex_info_text is None:
|
2022-02-06 23:52:44 +01:00
|
|
|
return GenericText()
|
2022-02-06 15:09:25 +01:00
|
|
|
else:
|
|
|
|
return self._pytex_info_text
|
|
|
|
|
2022-02-06 22:58:43 +01:00
|
|
|
@pytex_info_text.setter
|
|
|
|
def pytex_info_text(self, info_text: GenericText):
|
|
|
|
self._pytex_info_text = info_text
|
|
|
|
|
2022-02-06 15:09:25 +01:00
|
|
|
@property
|
|
|
|
def repo_info_text(self) -> GenericText:
|
|
|
|
if self._repo_info_text is None:
|
2022-02-06 23:52:44 +01:00
|
|
|
return GenericText()
|
2022-02-06 15:09:25 +01:00
|
|
|
else:
|
|
|
|
return self._repo_info_text
|
|
|
|
|
2022-02-06 22:58:43 +01:00
|
|
|
@repo_info_text.setter
|
|
|
|
def repo_info_text(self, info_text: GenericText):
|
|
|
|
self._repo_info_text = info_text
|
|
|
|
|
2022-02-06 15:09:25 +01:00
|
|
|
@property
|
|
|
|
def include_drv(self) -> bool:
|
|
|
|
if self._include_drv is None:
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
return self._include_drv
|
|
|
|
|
2022-02-06 22:58:43 +01:00
|
|
|
@include_drv.setter
|
|
|
|
def include_drv(self, include: bool):
|
|
|
|
self._include_drv = include
|
|
|
|
|
2022-02-06 15:09:25 +01:00
|
|
|
@property
|
|
|
|
def include_ins(self) -> bool:
|
|
|
|
if self._include_ins is None:
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
return self._include_ins
|
|
|
|
|
2022-02-06 22:58:43 +01:00
|
|
|
@include_ins.setter
|
|
|
|
def include_ins(self, include):
|
|
|
|
self._include_ins = include
|
|
|
|
|
2022-02-06 15:09:25 +01:00
|
|
|
@property
|
2022-02-06 22:58:43 +01:00
|
|
|
def docstrip_guards(self) -> List[str]:
|
2022-02-06 22:34:43 +01:00
|
|
|
if self._docstrip_guards is None:
|
2022-02-06 15:09:25 +01:00
|
|
|
return []
|
|
|
|
else:
|
2022-02-06 22:34:43 +01:00
|
|
|
return self._docstrip_guards
|
2022-02-06 15:09:25 +01:00
|
|
|
|
2022-02-06 22:58:43 +01:00
|
|
|
@docstrip_guards.setter
|
|
|
|
def docstrip_guards(self, guards: List[str]):
|
|
|
|
self._docstrip_guards = guards
|
|
|
|
|
2022-02-06 16:52:24 +01:00
|
|
|
@property
|
|
|
|
def description(self) -> str:
|
|
|
|
if self._description is None:
|
|
|
|
return ''
|
|
|
|
else:
|
|
|
|
return self._description
|
|
|
|
|
2022-02-06 22:58:43 +01:00
|
|
|
@description.setter
|
|
|
|
def description(self, description: str):
|
|
|
|
self._description = description
|
|
|
|
|
2022-02-06 22:29:44 +01:00
|
|
|
@property
|
|
|
|
def include_time(self) -> bool:
|
|
|
|
if self._include_time is None:
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
return self._include_time
|
|
|
|
|
2022-02-06 22:58:43 +01:00
|
|
|
@include_time.setter
|
|
|
|
def include_time(self, include: bool):
|
|
|
|
self._include_time = include
|
|
|
|
|
2022-02-06 22:34:43 +01:00
|
|
|
@property
|
|
|
|
def doc_dependencies(self) -> List[str]:
|
|
|
|
if self._doc_dependencies is None:
|
|
|
|
return []
|
|
|
|
else:
|
|
|
|
return self._doc_dependencies
|
|
|
|
|
2022-02-06 22:58:43 +01:00
|
|
|
@doc_dependencies.setter
|
|
|
|
def doc_dependencies(self, dependencies: List[str]):
|
|
|
|
self._doc_dependencies = dependencies
|
|
|
|
|
2022-02-06 22:34:43 +01:00
|
|
|
@property
|
|
|
|
def tex_dependencies(self) -> List[str]:
|
|
|
|
if self._tex_dependencies is None:
|
|
|
|
return []
|
|
|
|
else:
|
|
|
|
return self._tex_dependencies
|
|
|
|
|
2022-02-06 22:58:43 +01:00
|
|
|
@tex_dependencies.setter
|
|
|
|
def tex_dependencies(self, dependencies: List[str]):
|
|
|
|
self._tex_dependencies = dependencies
|
|
|
|
|
2022-02-08 16:34:59 +01:00
|
|
|
@property
|
|
|
|
def escape_character(self) -> str:
|
2022-02-09 11:39:58 +01:00
|
|
|
if self._escape_character is None:
|
2022-02-08 16:34:59 +01:00
|
|
|
return '!'
|
|
|
|
else:
|
|
|
|
return self._escape_character
|
|
|
|
|
2022-02-09 11:39:58 +01:00
|
|
|
@property
|
|
|
|
def tex_type(self) -> TeXType:
|
|
|
|
if self._tex_type is None:
|
|
|
|
return TeXType.TeXClass
|
|
|
|
else:
|
|
|
|
return self._tex_type
|
|
|
|
|
|
|
|
@tex_type.setter
|
|
|
|
def tex_type(self, tex_type: TeXType):
|
|
|
|
self._tex_type = tex_type
|
|
|
|
|
|
|
|
@property
|
|
|
|
def tex_flavour(self) -> TeXFlavour:
|
|
|
|
if self._tex_flavour is None:
|
|
|
|
return TeXFlavour.LaTeX2e
|
|
|
|
else:
|
|
|
|
return self._tex_flavour
|
|
|
|
|
|
|
|
@tex_flavour.setter
|
|
|
|
def tex_flavour(self, tex_flavour: TeXFlavour) -> None:
|
|
|
|
self._tex_flavour = tex_flavour
|
2022-02-04 11:39:15 +01:00
|
|
|
|
2022-02-04 11:46:06 +01:00
|
|
|
class DocFormattingConfig:
|
2022-02-04 11:39:15 +01:00
|
|
|
def __init__(self):
|
|
|
|
self._documents: Optional[List[str]] = None
|
|
|
|
self._dependencies: Optional[List[str]] = None
|