reorganize git versioning types

clean dict also recursively in lists
This commit is contained in:
Maximilian Keßler 2022-02-09 12:26:24 +01:00
parent 1e8fe43131
commit 591e6533b4
6 changed files with 29 additions and 23 deletions

View file

@ -18,7 +18,7 @@ DEFAULT_HASH = '0000000000000000000000000000000000000000000000000000000000000000
JSON_FILE_HASH = 'file_hash'
JSON_SOURCES_HASH = 'sources_hash'
JSON_RELATIVE_NAME = 'relative_name'
JSON_REPO_STATUS_INFO = 'repo_info'
JSON_GIT_VERSION_INFO = 'git_version_info'
NO_RELATIVE_NAME = 'NO_NAME'
NO_BUILD_TIME = 'no_build_time'

View file

@ -1,8 +1,8 @@
from typing import Optional, List, Dict
from PyTeX.format.repo_status_info import RepoStatusInfo
from .constants import *
from ....format.config import Config
from ....format.git_version_info import GitVersionInfo
from ...build.enums import *
@ -13,7 +13,7 @@ class FileVersionInfo(Config):
self._sources_hash: Optional[str] = None
# Meta properties actually not needed for build itself
self._repo_status_info: Optional[RepoStatusInfo] = None
self._git_version_info: Optional[GitVersionInfo] = None
self._build_time: Optional[str] = None
def set_from_json(self, content: Optional[Dict]):
@ -22,8 +22,8 @@ class FileVersionInfo(Config):
self._file_hash = filled_content[JSON_FILE_HASH]
self._sources_hash = filled_content[JSON_SOURCES_HASH]
self._build_time = filled_content[JSON_BUILD_TIME]
self._repo_status_info = RepoStatusInfo.from_json(
filled_content[JSON_REPO_STATUS_INFO]
self._git_version_info = GitVersionInfo.from_json(
filled_content[JSON_GIT_VERSION_INFO]
)
def to_json(self) -> Dict:
@ -32,7 +32,7 @@ class FileVersionInfo(Config):
JSON_FILE_HASH: self._file_hash,
JSON_SOURCES_HASH: self._sources_hash,
JSON_BUILD_TIME: self._build_time,
JSON_REPO_STATUS_INFO: self.repo_status_info.to_json()
JSON_GIT_VERSION_INFO: self.git_version_info.to_json()
}
@property
@ -69,15 +69,15 @@ class FileVersionInfo(Config):
self._relative_name = relative_name
@property
def repo_status_info(self) -> RepoStatusInfo:
if self._repo_status_info is None:
return RepoStatusInfo()
def git_version_info(self) -> GitVersionInfo:
if self._git_version_info is None:
return GitVersionInfo()
else:
return self._repo_status_info
return self._git_version_info
@repo_status_info.setter
def repo_status_info(self, repo_status_info: RepoStatusInfo):
self._repo_status_info = repo_status_info
@git_version_info.setter
def git_version_info(self, git_version_info: GitVersionInfo):
self._git_version_info = git_version_info
@property
def build_time(self) -> str:

View file

@ -7,12 +7,17 @@ import yaml
def clean_dict(dictionary: Dict) -> Optional[Dict]:
aux = {
aux: Dict = {
k: clean_dict(v) for k, v in dictionary.items() if type(v) == dict
} | {
k: v for k, v in dictionary.items() if type(v) != dict
}
aux2 = {
} | {
k: [
clean_dict(elem) if type(elem) == dict else elem
for elem in elems
] for k, elems in dictionary.items() if type(elems) == list
} | {
k: v for k, v in dictionary.items() if type(v) != dict and type(v) != list
}
aux2: Dict = {
k: v for k, v in aux.items() if v is not None
}
return aux2 if aux2 != {} else None

View file

@ -3,6 +3,7 @@ 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):
@ -41,8 +42,8 @@ class GitVersionInfo(Config):
@property
def has_pytex_version(self) -> bool:
return self._pytex_version is None
return self._pytex_version is not None
@property
def has_repo_version(self) -> bool:
return self._repo_version is None
return self._repo_version is not None

View file

@ -5,7 +5,7 @@ from typing import Optional, Dict
from .constants import *
from .formatterif import FormatterIF
from .formatting_config import FormattingConfig
from .git_version_info import GitVersionInfo
from .git_version_info import RepoStatusInfo
from .generic_text import GenericText
from ..logger import logger
from abc import ABC
@ -16,7 +16,7 @@ class PyTeXFormatter(FormatterIF, ABC):
self,
input_file: Optional[Path] = None,
config: Optional[FormattingConfig] = None,
git_version_info: Optional[GitVersionInfo] = None,
git_version_info: Optional[RepoStatusInfo] = None,
locate_file_config: bool = True,
allow_infile_config: bool = True
):
@ -25,7 +25,7 @@ class PyTeXFormatter(FormatterIF, ABC):
config=config
)
self._config: Optional[FormattingConfig] = self._config # for type-hinting
self._git_version_info: Optional[GitVersionInfo] = git_version_info
self._git_version_info: Optional[RepoStatusInfo] = git_version_info
self._allow_infile_config: bool = allow_infile_config
self._header: Optional[GenericText] = None
if locate_file_config: