diff --git a/PyTeX/format/formatting_config.py b/PyTeX/format/formatting_config.py index edaafd0..c1384a8 100644 --- a/PyTeX/format/formatting_config.py +++ b/PyTeX/format/formatting_config.py @@ -1,4 +1,7 @@ -from typing import List, Optional, Union, Any, Tuple +from typing import List, Optional, Union, Dict +from pathlib import Path +import yaml +import json from .enums import NamingScheme from .generic_text import GenericText from .formatterif import Config @@ -53,8 +56,17 @@ class FormattingConfig(Config): self._tex_dependencies: Optional[List[str]] = None @classmethod - def from_yaml(cls, yaml): - pass + def from_yaml(cls, content: Path): + with open(content, 'r') as config: + content: Dict = yaml.safe_load(config) + return cls.from_json(content) + + @classmethod + def from_json(cls, content: Union[Path, Dict]): + if isinstance(content, Path): + with open(content, 'r') as config: + content: Dict = json.load(config) + def to_yaml(self) -> str: pass @@ -66,6 +78,10 @@ class FormattingConfig(Config): else: return self._naming_scheme + @naming_scheme.setter + def naming_scheme(self, naming_scheme: NamingScheme): + self._naming_scheme = naming_scheme + @property def license(self) -> GenericText: if self._license is None: @@ -73,6 +89,10 @@ class FormattingConfig(Config): else: return self._license + @license.setter + def license(self, license: GenericText): + self._license = license + @property def include_extra_header(self) -> bool: if self._include_extra_header is None: @@ -80,6 +100,10 @@ class FormattingConfig(Config): else: return self._include_extra_header + @include_extra_header.setter + def include_extra_header(self, include: bool): + self._include_extra_header = include + @property def include_build_time(self) -> bool: if self._include_build_time is None: @@ -87,6 +111,10 @@ class FormattingConfig(Config): else: return self._include_build_time + @include_build_time.setter + def include_build_time(self, include: bool): + self._include_build_time = include + @property def include_pytex_version(self) -> bool: if self._include_pytex_version is None: @@ -94,6 +122,10 @@ class FormattingConfig(Config): else: return self._include_pytex_version + @include_pytex_version.setter + def include_pytex_version(self, include: bool): + self._include_pytex_version = include + @property def include_pytex_info_text(self) -> bool: if self._include_pytex_info_text is None: @@ -101,6 +133,10 @@ class FormattingConfig(Config): else: return self._include_pytex_info_text + @include_pytex_info_text.setter + def include_pytex_info_text(self, include: bool): + self._include_pytex_info_text = include + @property def include_repo_version(self) -> bool: if self._include_repo_version is None: @@ -108,6 +144,10 @@ class FormattingConfig(Config): else: return self._include_repo_version + @include_repo_version.setter + def include_repo_version(self, include: bool): + self._include_repo_version = include + @property def include_repo_info_text(self) -> bool: if self._include_repo_info_text is None: @@ -115,6 +155,10 @@ class FormattingConfig(Config): else: return self._include_repo_info_text + @include_repo_info_text.setter + def include_repo_info_text(self, include: bool): + self._include_repo_info_text = include + @property def extra_header(self) -> GenericText: if self._extra_header is None: @@ -122,6 +166,10 @@ class FormattingConfig(Config): else: return self._extra_header + @extra_header.setter + def extra_header(self, extra_header: GenericText): + self._extra_header = extra_header + @property def author(self) -> str: if self._author is None: @@ -129,6 +177,10 @@ class FormattingConfig(Config): else: return self._author + @author.setter + def author(self, author: str): + self._author = author + @property def version(self) -> str: if self._version is None: @@ -136,6 +188,10 @@ class FormattingConfig(Config): else: return self._version + @version.setter + def version(self, version: str): + self._version = version + @property def pytex_info_text(self) -> GenericText: if self._pytex_info_text is None: @@ -143,6 +199,10 @@ class FormattingConfig(Config): else: return self._pytex_info_text + @pytex_info_text.setter + def pytex_info_text(self, info_text: GenericText): + self._pytex_info_text = info_text + @property def repo_info_text(self) -> GenericText: if self._repo_info_text is None: @@ -150,6 +210,10 @@ class FormattingConfig(Config): else: return self._repo_info_text + @repo_info_text.setter + def repo_info_text(self, info_text: GenericText): + self._repo_info_text = info_text + @property def include_drv(self) -> bool: if self._include_drv is None: @@ -157,6 +221,10 @@ class FormattingConfig(Config): else: return self._include_drv + @include_drv.setter + def include_drv(self, include: bool): + self._include_drv = include + @property def include_ins(self) -> bool: if self._include_ins is None: @@ -164,13 +232,21 @@ class FormattingConfig(Config): else: return self._include_ins + @include_ins.setter + def include_ins(self, include): + self._include_ins = include + @property - def docstrip_guards(self) -> list: + def docstrip_guards(self) -> List[str]: if self._docstrip_guards is None: return [] else: return self._docstrip_guards + @docstrip_guards.setter + def docstrip_guards(self, guards: List[str]): + self._docstrip_guards = guards + @property def description(self) -> str: if self._description is None: @@ -178,6 +254,10 @@ class FormattingConfig(Config): else: return self._description + @description.setter + def description(self, description: str): + self._description = description + @property def include_time(self) -> bool: if self._include_time is None: @@ -185,6 +265,10 @@ class FormattingConfig(Config): else: return self._include_time + @include_time.setter + def include_time(self, include: bool): + self._include_time = include + @property def doc_dependencies(self) -> List[str]: if self._doc_dependencies is None: @@ -192,6 +276,10 @@ class FormattingConfig(Config): else: return self._doc_dependencies + @doc_dependencies.setter + def doc_dependencies(self, dependencies: List[str]): + self._doc_dependencies = dependencies + @property def tex_dependencies(self) -> List[str]: if self._tex_dependencies is None: @@ -199,6 +287,10 @@ class FormattingConfig(Config): else: return self._tex_dependencies + @tex_dependencies.setter + def tex_dependencies(self, dependencies: List[str]): + self._tex_dependencies = dependencies + class DocFormattingConfig: def __init__(self):