add proper version info object
This commit is contained in:
parent
f5c1a6c0c3
commit
13b5aa0d2a
5 changed files with 110 additions and 32 deletions
|
@ -1,9 +1,10 @@
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Optional, List, Dict, Tuple, Union
|
from typing import Optional, List, Dict, Tuple, Union
|
||||||
|
|
||||||
from PyTeX.build.paths import RelativePath
|
from .relative_path import RelativePath
|
||||||
from PyTeX.format.formatterif import FormatterIF
|
from PyTeX.format.formatterif import FormatterIF
|
||||||
from PyTeX.build.build.enums import PyTeXFileType
|
from PyTeX.build.build.enums import PyTeXFileType
|
||||||
|
from .hashing import md5
|
||||||
|
|
||||||
|
|
||||||
class PyTeXSourceFile:
|
class PyTeXSourceFile:
|
||||||
|
@ -13,9 +14,19 @@ class PyTeXSourceFile:
|
||||||
formatter: Optional[FormatterIF] = None,
|
formatter: Optional[FormatterIF] = None,
|
||||||
pytex_file_type: Optional[PyTeXFileType] = None
|
pytex_file_type: Optional[PyTeXFileType] = None
|
||||||
):
|
):
|
||||||
self._relative_path: RelativePath = None
|
self._relative_path: RelativePath = relative_path
|
||||||
self._pytex_file_type: PyTeXFileType = None
|
self._pytex_file_type: Optional[PyTeXFileType] = None
|
||||||
self._formatter: FormatterIF = None
|
self._formatter: Optional[FormatterIF] = None
|
||||||
|
self._file_hash: Optional[str] = None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def file_hash(self) -> str:
|
||||||
|
if self._file_hash is None:
|
||||||
|
self.update_file_hash()
|
||||||
|
return self._file_hash
|
||||||
|
|
||||||
|
def update_file_hash(self):
|
||||||
|
self._file_hash = md5(self._relative_path.path)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def relative_path(self):
|
def relative_path(self):
|
||||||
|
|
|
@ -14,3 +14,11 @@ JSON_DIRTY = 'dirty'
|
||||||
DEFAULT_VERSION = '0.0.0'
|
DEFAULT_VERSION = '0.0.0'
|
||||||
DEFAULT_BRANCH = 'NO-BRANCH'
|
DEFAULT_BRANCH = 'NO-BRANCH'
|
||||||
DEFAULT_HASH = '0000000000000000000000000000000000000000000000000000000000000000'
|
DEFAULT_HASH = '0000000000000000000000000000000000000000000000000000000000000000'
|
||||||
|
|
||||||
|
JSON_FILE_HASH = 'file_hash'
|
||||||
|
JSON_SOURCES_HASH = 'sources_hash'
|
||||||
|
JSON_RELATIVE_NAME = 'relative_name'
|
||||||
|
JSON_REPO_STATUS_INFO = 'repo_info'
|
||||||
|
|
||||||
|
NO_RELATIVE_NAME = 'NO_NAME'
|
||||||
|
NO_BUILD_TIME = 'no_build_time'
|
||||||
|
|
|
@ -1,31 +1,90 @@
|
||||||
from typing import Optional
|
from typing import Optional, List, Dict
|
||||||
|
|
||||||
from PyTeX.format.git_version_info import GitVersionInfo
|
from PyTeX.format.repo_status_info import RepoStatusInfo
|
||||||
from .constants import *
|
from .constants import *
|
||||||
|
from ....format.config import Config
|
||||||
|
|
||||||
|
|
||||||
class FileVersionInfo:
|
class FileVersionInfo(Config):
|
||||||
def __init__(self, dictionary: dict):
|
def __init__(self):
|
||||||
if JSON_MD5_CHECKSUM not in dictionary.keys():
|
self._relative_name: Optional[str] = None
|
||||||
raise NotImplementedError
|
self._file_hash: Optional[str] = None
|
||||||
|
self._sources_hash: Optional[str] = None
|
||||||
|
|
||||||
|
# Meta properties actually not needed for build itself
|
||||||
|
self._repo_status_info: Optional[RepoStatusInfo] = None
|
||||||
|
self._build_time: Optional[str] = None
|
||||||
|
|
||||||
|
def set_from_json(self, content: Optional[Dict]):
|
||||||
|
content = self._fill_keys(content)
|
||||||
|
self._relative_name = content[JSON_RELATIVE_NAME]
|
||||||
|
self._file_hash = content[JSON_FILE_HASH]
|
||||||
|
self._sources_hash = content[JSON_SOURCES_HASH]
|
||||||
|
self._build_time = content[JSON_BUILD_TIME]
|
||||||
|
self._repo_status_info = RepoStatusInfo.from_json(
|
||||||
|
content[JSON_REPO_STATUS_INFO]
|
||||||
|
)
|
||||||
|
|
||||||
|
def to_json(self) -> Dict:
|
||||||
|
return {
|
||||||
|
JSON_RELATIVE_NAME: self._relative_name,
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
|
||||||
|
@property
|
||||||
|
def file_hash(self) -> str:
|
||||||
|
if self._file_hash is None:
|
||||||
|
return DEFAULT_HASH
|
||||||
else:
|
else:
|
||||||
self._md5_checksum = dictionary[JSON_MD5_CHECKSUM]
|
return self._file_hash
|
||||||
|
|
||||||
self._source_repository_version: Optional[GitVersionInfo] = \
|
@file_hash.setter
|
||||||
GitVersionInfo(dictionary[JSON_REPOSITORY]) if JSON_REPOSITORY in dictionary.keys() \
|
def file_hash(self, file_hash: str):
|
||||||
else None
|
self._file_hash = file_hash
|
||||||
self._pytex_repository_version: Optional[GitVersionInfo] = \
|
|
||||||
GitVersionInfo(dictionary[JSON_PYTEX]) if JSON_PYTEX in dictionary.keys() \
|
|
||||||
else None
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def md5_checksum(self) -> str:
|
def sources_hash(self) -> str:
|
||||||
return self._md5_checksum
|
if self._sources_hash is None:
|
||||||
|
return DEFAULT_HASH
|
||||||
|
else:
|
||||||
|
return self._sources_hash
|
||||||
|
|
||||||
|
@sources_hash.setter
|
||||||
|
def sources_hash(self, sources_hash: str):
|
||||||
|
self._sources_hash = sources_hash
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def source_repository_version(self) -> Optional[GitVersionInfo]:
|
def relative_name(self) -> str:
|
||||||
return self._source_repository_version
|
if self._relative_name is None:
|
||||||
|
return NO_RELATIVE_NAME
|
||||||
|
else:
|
||||||
|
return self._relative_name
|
||||||
|
|
||||||
|
@relative_name.setter
|
||||||
|
def relative_name(self, relative_name: str):
|
||||||
|
self._relative_name = relative_name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def pytex_repository_version(self) -> Optional[GitVersionInfo]:
|
def repo_status_info(self) -> RepoStatusInfo:
|
||||||
return self._pytex_repository_version
|
if self._repo_status_info is None:
|
||||||
|
return RepoStatusInfo()
|
||||||
|
else:
|
||||||
|
return self._repo_status_info
|
||||||
|
|
||||||
|
@repo_status_info.setter
|
||||||
|
def repo_status_info(self, repo_status_info: RepoStatusInfo):
|
||||||
|
self._repo_status_info = repo_status_info
|
||||||
|
|
||||||
|
@property
|
||||||
|
def build_time(self) -> str:
|
||||||
|
if self._build_time is None:
|
||||||
|
return NO_BUILD_TIME
|
||||||
|
else:
|
||||||
|
return self._build_time
|
||||||
|
|
||||||
|
@build_time.setter
|
||||||
|
def build_time(self, build_time: str):
|
||||||
|
self._build_time = build_time
|
||||||
|
|
|
@ -4,21 +4,21 @@ 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 .repo_status_info import RepoStatusInfo
|
||||||
from .config import Config
|
from .config import Config
|
||||||
|
|
||||||
|
|
||||||
class VersionInfo(Config):
|
class GitVersionInfo(Config):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._repo_version: Optional[GitVersionInfo] = None
|
self._repo_version: Optional[RepoStatusInfo] = None
|
||||||
self._pytex_version: Optional[GitVersionInfo] = None
|
self._pytex_version: Optional[RepoStatusInfo] = None
|
||||||
|
|
||||||
def set_from_json(self, content: Optional[Dict]):
|
def set_from_json(self, content: Optional[Dict]):
|
||||||
content = self._fill_keys(content)
|
content = self._fill_keys(content)
|
||||||
self._repo_version = GitVersionInfo.from_json(
|
self._repo_version = RepoStatusInfo.from_json(
|
||||||
content[YAML_REPO]
|
content[YAML_REPO]
|
||||||
)
|
)
|
||||||
self._pytex_version = GitVersionInfo.from_json(
|
self._pytex_version = RepoStatusInfo.from_json(
|
||||||
content[YAML_PYTEX]
|
content[YAML_PYTEX]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -29,14 +29,14 @@ class VersionInfo(Config):
|
||||||
}
|
}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def pytex_version(self) -> Optional[GitVersionInfo]:
|
def pytex_version(self) -> Optional[RepoStatusInfo]:
|
||||||
if self._pytex_version is None:
|
if self._pytex_version is None:
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
return self._pytex_version
|
return self._pytex_version
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def repo_version(self) -> Optional[GitVersionInfo]:
|
def repo_version(self) -> Optional[RepoStatusInfo]:
|
||||||
if self._repo_version is None:
|
if self._repo_version is None:
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -4,7 +4,7 @@ from PyTeX.build.versioning.version_info.constants import *
|
||||||
from .config import Config
|
from .config import Config
|
||||||
|
|
||||||
|
|
||||||
class GitVersionInfo(Config):
|
class RepoStatusInfo(Config):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
||||||
self._dirty: Optional[bool] = None
|
self._dirty: Optional[bool] = None
|
Loading…
Reference in a new issue