refactor git version info into own file
This commit is contained in:
parent
c04897c26c
commit
1e8fe43131
3 changed files with 51 additions and 46 deletions
|
@ -1,56 +1,12 @@
|
|||
from typing import List, Optional, Dict, Union
|
||||
from typing import List, Optional, Dict
|
||||
|
||||
from .constants import *
|
||||
from .enums import NamingScheme
|
||||
from .enums import TeXType, TeXFlavour
|
||||
from .generic_text import GenericText
|
||||
from .repo_status_info import RepoStatusInfo
|
||||
from .config import Config
|
||||
|
||||
|
||||
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
|
||||
|
||||
@property
|
||||
def repo_version(self) -> RepoStatusInfo:
|
||||
if self._repo_version is None:
|
||||
return RepoStatusInfo()
|
||||
else:
|
||||
return self._repo_version
|
||||
|
||||
@property
|
||||
def has_pytex_version(self) -> bool:
|
||||
return self._pytex_version is None
|
||||
|
||||
@property
|
||||
def has_repo_version(self) -> bool:
|
||||
return self._repo_version is None
|
||||
|
||||
|
||||
class FormattingConfig(Config):
|
||||
def __init__(self):
|
||||
self._naming_scheme: Optional[NamingScheme] = None
|
||||
|
|
48
PyTeX/format/git_version_info.py
Normal file
48
PyTeX/format/git_version_info.py
Normal file
|
@ -0,0 +1,48 @@
|
|||
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
|
||||
|
||||
|
||||
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
|
||||
|
||||
@property
|
||||
def repo_version(self) -> RepoStatusInfo:
|
||||
if self._repo_version is None:
|
||||
return RepoStatusInfo()
|
||||
else:
|
||||
return self._repo_version
|
||||
|
||||
@property
|
||||
def has_pytex_version(self) -> bool:
|
||||
return self._pytex_version is None
|
||||
|
||||
@property
|
||||
def has_repo_version(self) -> bool:
|
||||
return self._repo_version is None
|
|
@ -4,7 +4,8 @@ from typing import Optional, Dict
|
|||
|
||||
from .constants import *
|
||||
from .formatterif import FormatterIF
|
||||
from .formatting_config import FormattingConfig, GitVersionInfo
|
||||
from .formatting_config import FormattingConfig
|
||||
from .git_version_info import GitVersionInfo
|
||||
from .generic_text import GenericText
|
||||
from ..logger import logger
|
||||
from abc import ABC
|
||||
|
|
Loading…
Reference in a new issue