adjust set_from_json method and make GitVersionInfo a config object
This commit is contained in:
parent
c83f24798e
commit
b3eb6f2a90
6 changed files with 31 additions and 13 deletions
|
@ -20,7 +20,7 @@ class BuildDirConfig(Config):
|
||||||
self._tex_source_root: Optional[Path] = tex_root
|
self._tex_source_root: Optional[Path] = tex_root
|
||||||
self._wrapper_dir: Optional[PurePath] = wrapper_dir
|
self._wrapper_dir: Optional[PurePath] = wrapper_dir
|
||||||
|
|
||||||
def set_from_json(self, content: Dict):
|
def set_from_json(self, content: Optional[Dict]):
|
||||||
content = self._fill_keys(content)
|
content = self._fill_keys(content)
|
||||||
|
|
||||||
self._tex_source_root = content[YAML_TEX_SOURCE_ROOT]
|
self._tex_source_root = content[YAML_TEX_SOURCE_ROOT]
|
||||||
|
|
|
@ -38,7 +38,7 @@ class PyTeXConfig(Config):
|
||||||
YAML_CONFIGS: self._configs
|
YAML_CONFIGS: self._configs
|
||||||
}
|
}
|
||||||
|
|
||||||
def set_from_json(self, content: Dict):
|
def set_from_json(self, content: Optional[Dict]):
|
||||||
content = self._fill_keys(content)
|
content = self._fill_keys(content)
|
||||||
|
|
||||||
build = content[YAML_BUILD]
|
build = content[YAML_BUILD]
|
||||||
|
|
|
@ -48,7 +48,7 @@ class Config:
|
||||||
path: Dict = yaml.safe_load(config)
|
path: Dict = yaml.safe_load(config)
|
||||||
return cls.from_json(path)
|
return cls.from_json(path)
|
||||||
|
|
||||||
def set_from_json(self, content: Dict):
|
def set_from_json(self, content: Optional[Dict]):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def to_json(self) -> Dict:
|
def to_json(self) -> Dict:
|
||||||
|
@ -77,7 +77,10 @@ class Config:
|
||||||
pass # TODO
|
pass # TODO
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _fill_keys(cls, dictionary: Dict):
|
def _fill_keys(cls, dictionary: Optional[Dict]):
|
||||||
|
if dictionary is None:
|
||||||
|
return cls().to_json()
|
||||||
|
else:
|
||||||
return recursive_merge_dictionaries(
|
return recursive_merge_dictionaries(
|
||||||
cls().to_json(),
|
cls().to_json(),
|
||||||
dictionary
|
dictionary
|
||||||
|
|
|
@ -1,18 +1,33 @@
|
||||||
from typing import List, Optional, Dict, Union
|
from typing import List, Optional, Dict, Union
|
||||||
|
|
||||||
from .config import Config
|
|
||||||
from .constants import *
|
from .constants import *
|
||||||
from .enums import NamingScheme
|
from .enums import NamingScheme
|
||||||
from .enums import TeXType, TeXFlavour
|
from .enums import TeXType, TeXFlavour
|
||||||
from .generic_text import GenericText
|
from .generic_text import GenericText
|
||||||
from .git_version_info import GitVersionInfo
|
from .git_version_info import GitVersionInfo
|
||||||
|
from .config import Config
|
||||||
|
|
||||||
|
|
||||||
class VersionInfo:
|
class VersionInfo(Config):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._repo_version: Optional[GitVersionInfo] = None
|
self._repo_version: Optional[GitVersionInfo] = None
|
||||||
self._pytex_version: Optional[GitVersionInfo] = None
|
self._pytex_version: Optional[GitVersionInfo] = None
|
||||||
|
|
||||||
|
def set_from_json(self, content: Optional[Dict]):
|
||||||
|
content = self._fill_keys(content)
|
||||||
|
self._repo_version = GitVersionInfo.from_json(
|
||||||
|
content[YAML_REPO]
|
||||||
|
)
|
||||||
|
self._pytex_version = GitVersionInfo.from_json(
|
||||||
|
content[YAML_PYTEX]
|
||||||
|
)
|
||||||
|
|
||||||
|
def to_json(self) -> Dict:
|
||||||
|
return {
|
||||||
|
YAML_PYTEX: self._pytex_version.to_json(),
|
||||||
|
YAML_REPO: self._repo_version.to_json()
|
||||||
|
}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def pytex_version(self) -> Optional[GitVersionInfo]:
|
def pytex_version(self) -> Optional[GitVersionInfo]:
|
||||||
if self._pytex_version is None:
|
if self._pytex_version is None:
|
||||||
|
@ -58,7 +73,7 @@ class FormattingConfig(Config):
|
||||||
self._tex_type: Optional[TeXType] = None
|
self._tex_type: Optional[TeXType] = None
|
||||||
self._tex_flavour: Optional[TeXFlavour] = None
|
self._tex_flavour: Optional[TeXFlavour] = None
|
||||||
|
|
||||||
def set_from_json(self, content: Dict):
|
def set_from_json(self, content: Optional[Dict]):
|
||||||
content = self._fill_keys(content)
|
content = self._fill_keys(content)
|
||||||
|
|
||||||
info = content[YAML_INFO]
|
info = content[YAML_INFO]
|
||||||
|
|
|
@ -12,7 +12,7 @@ class GitVersionInfo(Config):
|
||||||
self._branch: Optional[str] = None
|
self._branch: Optional[str] = None
|
||||||
self._version: Optional[str] = None
|
self._version: Optional[str] = None
|
||||||
|
|
||||||
def set_from_json(self, content: Dict):
|
def set_from_json(self, content: Optional[Dict]):
|
||||||
content = self._fill_keys(content)
|
content = self._fill_keys(content)
|
||||||
self._branch = content[JSON_BRANCH]
|
self._branch = content[JSON_BRANCH]
|
||||||
self._dirty = content[JSON_DIRTY]
|
self._dirty = content[JSON_DIRTY]
|
||||||
|
|
Loading…
Reference in a new issue