pytex/PyTeX/format/git_version_info.py

38 lines
1.1 KiB
Python
Raw Normal View History

2022-02-06 15:09:49 +01:00
from typing import Optional
from PyTeX.build.versioning.version_info.constants import JSON_BRANCH, JSON_COMMIT_HASH, JSON_DIRTY, JSON_VERSION
class GitVersionInfo:
def __init__(self, dictionary: dict):
if not all(
x in dictionary.keys() for
x in [JSON_BRANCH, JSON_COMMIT_HASH]
):
raise NotImplementedError
self._dirty: bool = dictionary[JSON_DIRTY]
self._commit_hash: str = dictionary[JSON_COMMIT_HASH]
self._branch: Optional[str] = \
dictionary[JSON_BRANCH] if JSON_BRANCH in dictionary.keys() \
2022-02-07 18:36:30 +01:00
else None
2022-02-06 15:09:49 +01:00
self._version: Optional[str] = \
dictionary[JSON_VERSION] if JSON_VERSION in dictionary.keys() \
2022-02-07 18:36:30 +01:00
else None
2022-02-06 15:09:49 +01:00
@property
def is_dirty(self) -> bool:
return self._dirty
@property
def version(self) -> Optional[str]:
return self._version
@property
def commit_hash(self) -> Optional[str]:
return self._commit_hash
@property
def branch(self) -> Optional[str]:
2022-02-07 18:36:30 +01:00
return self._branch