diff --git a/PyTeX/build/utils/conversions.py b/PyTeX/build/build/conversions.py similarity index 88% rename from PyTeX/build/utils/conversions.py rename to PyTeX/build/build/conversions.py index d92a5fc..073ac54 100644 --- a/PyTeX/build/utils/conversions.py +++ b/PyTeX/build/build/conversions.py @@ -1,5 +1,5 @@ -from PyTeX.build.paths import PyTeXRootDirType -from PyTeX.build.pytex_file import PyTeXFileType +from PyTeX.build.build.enums import PyTeXRootDirType +from PyTeX.build.build.enums import PyTeXFileType def pytex_file_type2pytex_root_dir(pytex_file_type: PyTeXFileType) -> PyTeXRootDirType: diff --git a/PyTeX/build/pytex_file/enums.py b/PyTeX/build/build/enums.py similarity index 52% rename from PyTeX/build/pytex_file/enums.py rename to PyTeX/build/build/enums.py index 3df5313..255a88e 100644 --- a/PyTeX/build/pytex_file/enums.py +++ b/PyTeX/build/build/enums.py @@ -1,8 +1,15 @@ from enum import Enum +class PyTeXRootDirType(Enum): + BUILD = 1 + PYTEX_SOURCE = 2 + DOC = 3 + TEX_SOURCE = 4 + + class PyTeXFileType(Enum): PyTeXSourceFile = 'PyTeXSourceFile' TeXSourceFile = 'TeXSourceFile' TeXOutputFile = 'TeXOutputFile' - TeXDocumentationFile = 'TeXDocumentationFile' + TeXDocumentationFile = 'TeXDocumentationFile' \ No newline at end of file diff --git a/PyTeX/build/pytex_file/pytex_file.py b/PyTeX/build/build/pytex_file.py similarity index 97% rename from PyTeX/build/pytex_file/pytex_file.py rename to PyTeX/build/build/pytex_file.py index 0872d3c..018eedb 100644 --- a/PyTeX/build/pytex_file/pytex_file.py +++ b/PyTeX/build/build/pytex_file.py @@ -3,7 +3,7 @@ from typing import Optional, List, Dict, Tuple, Union from PyTeX.build.paths import RelativePath from PyTeX.format.formatterif import FormatterIF -from .enums import PyTeXFileType +from PyTeX.build.build.enums import PyTeXFileType class PyTeXSourceFile: diff --git a/PyTeX/build/paths/relative_path.py b/PyTeX/build/build/relative_path.py similarity index 96% rename from PyTeX/build/paths/relative_path.py rename to PyTeX/build/build/relative_path.py index a3c39c8..044d671 100644 --- a/PyTeX/build/paths/relative_path.py +++ b/PyTeX/build/build/relative_path.py @@ -1,6 +1,6 @@ from pathlib import Path -from PyTeX.build.enums.enums import PyTeXRootDirType +from PyTeX.build.build.enums import PyTeXRootDirType class RelativePath: diff --git a/PyTeX/build/enums/__init__.py b/PyTeX/build/enums/__init__.py deleted file mode 100644 index b02681c..0000000 --- a/PyTeX/build/enums/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .enums import * diff --git a/PyTeX/build/enums/enums.py b/PyTeX/build/enums/enums.py deleted file mode 100644 index 34376c6..0000000 --- a/PyTeX/build/enums/enums.py +++ /dev/null @@ -1,8 +0,0 @@ -from enum import Enum - - -class PyTeXRootDirType(Enum): - BUILD = 1 - PYTEX_SOURCE = 2 - DOC = 3 - TEX_SOURCE = 4 diff --git a/PyTeX/build/paths/__init__.py b/PyTeX/build/paths/__init__.py deleted file mode 100644 index fcfc9bf..0000000 --- a/PyTeX/build/paths/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .relative_path import RelativePath diff --git a/PyTeX/build/pytex_file/__init__.py b/PyTeX/build/pytex_file/__init__.py deleted file mode 100644 index 825b19e..0000000 --- a/PyTeX/build/pytex_file/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -from .enums import * -from .pytex_file import PyTeXSourceFile diff --git a/PyTeX/build/utils/__init__.py b/PyTeX/build/utils/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/PyTeX/build/versioning/version_info/constants.py b/PyTeX/build/versioning/version_info/constants.py index ca02312..49ce1fc 100644 --- a/PyTeX/build/versioning/version_info/constants.py +++ b/PyTeX/build/versioning/version_info/constants.py @@ -10,3 +10,7 @@ JSON_VERSION = 'source version' JSON_COMMIT_HASH = 'commit hash' JSON_BRANCH = 'branch' JSON_DIRTY = 'dirty' + +DEFAULT_VERSION = '0.0.0' +DEFAULT_BRANCH = 'NO-BRANCH' +DEFAULT_HASH = '0000000000000000000000000000000000000000000000000000000000000000' diff --git a/PyTeX/format/git_version_info.py b/PyTeX/format/git_version_info.py index 48c5ef0..7d3923a 100644 --- a/PyTeX/format/git_version_info.py +++ b/PyTeX/format/git_version_info.py @@ -1,37 +1,71 @@ -from typing import Optional +from typing import Optional, Dict -from PyTeX.build.versioning.version_info.constants import JSON_BRANCH, JSON_COMMIT_HASH, JSON_DIRTY, JSON_VERSION +from PyTeX.build.versioning.version_info.constants import * +from .config import Config -class GitVersionInfo: - def __init__(self, dictionary: dict): - if not all( - x in dictionary.keys() for - x in [JSON_BRANCH, JSON_COMMIT_HASH] - ): - raise NotImplementedError +class GitVersionInfo(Config): + def __init__(self): - 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() \ - else None - self._version: Optional[str] = \ - dictionary[JSON_VERSION] if JSON_VERSION in dictionary.keys() \ - else None + 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: 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 + } @property - def is_dirty(self) -> bool: - return self._dirty + 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 @property - def version(self) -> Optional[str]: + def version(self) -> str: + if self._version is None: + return DEFAULT_VERSION return self._version - @property - def commit_hash(self) -> Optional[str]: - return self._commit_hash + @version.setter + def version(self, version: str): + self._version = version @property - def branch(self) -> Optional[str]: - return self._branch + 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 + + @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 diff --git a/PyTeX/tmp/pytex_path.py b/PyTeX/tmp/pytex_path.py index 7272ff7..5eefa03 100644 --- a/PyTeX/tmp/pytex_path.py +++ b/PyTeX/tmp/pytex_path.py @@ -2,7 +2,7 @@ import os from pathlib import Path, PurePath, PurePosixPath, PureWindowsPath from PyTeX.build.build import PyTeXBuilder -from PyTeX.build.enums.enums import PyTeXRootDirType +from PyTeX.build.build.enums import PyTeXRootDirType class PyTeXPurePath: