pytex/PyTeX/format/git_version_info.py

72 lines
1.8 KiB
Python
Raw Normal View History

from typing import Optional, Dict
2022-02-06 15:09:49 +01:00
from PyTeX.build.versioning.version_info.constants import *
from .config import Config
2022-02-06 15:09:49 +01:00
class GitVersionInfo(Config):
def __init__(self):
2022-02-06 15:09:49 +01:00
self._dirty: Optional[bool] = None
self._commit_hash: Optional[str] = None
self._branch: Optional[str] = None
self._version: Optional[str] = None
def set_from_json(self, content: Optional[Dict]):
content = self._fill_keys(content)
self._branch = content[JSON_BRANCH]
self._dirty = content[JSON_DIRTY]
self._commit_hash = content[JSON_COMMIT_HASH]
self._version = content[JSON_VERSION]
def to_json(self) -> Dict:
return {
JSON_VERSION: self._version,
JSON_DIRTY: self._version,
JSON_COMMIT_HASH: self._commit_hash,
JSON_BRANCH: self._branch
}
2022-02-06 15:09:49 +01:00
@property
def dirty(self) -> bool:
if self._dirty is None:
return True
else:
return self._dirty
@dirty.setter
def dirty(self, dirty: bool):
self._dirty = dirty
2022-02-06 15:09:49 +01:00
@property
def version(self) -> str:
if self._version is None:
return DEFAULT_VERSION
2022-02-06 15:09:49 +01:00
return self._version
@version.setter
def version(self, version: str):
self._version = version
2022-02-06 15:09:49 +01:00
@property
def commit_hash(self) -> str:
if self._commit_hash is None:
return DEFAULT_HASH
else:
return self._commit_hash
@commit_hash.setter
def commit_hash(self, commit_hash: str):
self._commit_hash = commit_hash
2022-02-06 15:09:49 +01:00
@property
def branch(self) -> str:
if self._branch is None:
return DEFAULT_BRANCH
else:
return self._branch
@branch.setter
def branch(self, branch: str):
self._branch = branch