pytex/PyTeX/format/git_version_info.py

57 lines
No EOL
1.7 KiB
Python

from typing import Optional, Dict
from PyTeX.format.config import Config
from PyTeX.format.constants import YAML_REPO, YAML_PYTEX
from PyTeX.format.repo_status_info import RepoStatusInfo
from .repo_status_info import RepoStatusInfo
class GitVersionInfo(Config):
def __init__(self):
self._repo_version: Optional[RepoStatusInfo] = None
self._pytex_version: Optional[RepoStatusInfo] = None
def set_from_json(self, content: Optional[Dict]):
filled_content = self._fill_keys(content)
self._repo_version = RepoStatusInfo.from_json(
filled_content[YAML_REPO]
)
self._pytex_version = RepoStatusInfo.from_json(
filled_content[YAML_PYTEX]
)
def to_json(self) -> Dict:
return {
YAML_PYTEX: self.pytex_version.to_json(),
YAML_REPO: self.repo_version.to_json()
}
@property
def pytex_version(self) -> RepoStatusInfo:
if self._pytex_version is None:
return RepoStatusInfo()
else:
return self._pytex_version
@pytex_version.setter
def pytex_version(self, pytex_version: RepoStatusInfo):
self._pytex_version = pytex_version
@property
def repo_version(self) -> RepoStatusInfo:
if self._repo_version is None:
return RepoStatusInfo()
else:
return self._repo_version
@repo_version.setter
def repo_version(self, repo_version: RepoStatusInfo):
self._repo_version = repo_version
@property
def has_pytex_version(self) -> bool:
return self._pytex_version is not None
@property
def has_repo_version(self) -> bool:
return self._repo_version is not None