refactor files and rework git version info into a Config file
This commit is contained in:
parent
07280ce9f2
commit
c83f24798e
12 changed files with 76 additions and 43 deletions
|
@ -1,5 +1,5 @@
|
||||||
from PyTeX.build.paths import PyTeXRootDirType
|
from PyTeX.build.build.enums import PyTeXRootDirType
|
||||||
from PyTeX.build.pytex_file import PyTeXFileType
|
from PyTeX.build.build.enums import PyTeXFileType
|
||||||
|
|
||||||
|
|
||||||
def pytex_file_type2pytex_root_dir(pytex_file_type: PyTeXFileType) -> PyTeXRootDirType:
|
def pytex_file_type2pytex_root_dir(pytex_file_type: PyTeXFileType) -> PyTeXRootDirType:
|
|
@ -1,8 +1,15 @@
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
||||||
|
|
||||||
|
class PyTeXRootDirType(Enum):
|
||||||
|
BUILD = 1
|
||||||
|
PYTEX_SOURCE = 2
|
||||||
|
DOC = 3
|
||||||
|
TEX_SOURCE = 4
|
||||||
|
|
||||||
|
|
||||||
class PyTeXFileType(Enum):
|
class PyTeXFileType(Enum):
|
||||||
PyTeXSourceFile = 'PyTeXSourceFile'
|
PyTeXSourceFile = 'PyTeXSourceFile'
|
||||||
TeXSourceFile = 'TeXSourceFile'
|
TeXSourceFile = 'TeXSourceFile'
|
||||||
TeXOutputFile = 'TeXOutputFile'
|
TeXOutputFile = 'TeXOutputFile'
|
||||||
TeXDocumentationFile = 'TeXDocumentationFile'
|
TeXDocumentationFile = 'TeXDocumentationFile'
|
|
@ -3,7 +3,7 @@ from typing import Optional, List, Dict, Tuple, Union
|
||||||
|
|
||||||
from PyTeX.build.paths import RelativePath
|
from PyTeX.build.paths import RelativePath
|
||||||
from PyTeX.format.formatterif import FormatterIF
|
from PyTeX.format.formatterif import FormatterIF
|
||||||
from .enums import PyTeXFileType
|
from PyTeX.build.build.enums import PyTeXFileType
|
||||||
|
|
||||||
|
|
||||||
class PyTeXSourceFile:
|
class PyTeXSourceFile:
|
|
@ -1,6 +1,6 @@
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from PyTeX.build.enums.enums import PyTeXRootDirType
|
from PyTeX.build.build.enums import PyTeXRootDirType
|
||||||
|
|
||||||
|
|
||||||
class RelativePath:
|
class RelativePath:
|
|
@ -1 +0,0 @@
|
||||||
from .enums import *
|
|
|
@ -1,8 +0,0 @@
|
||||||
from enum import Enum
|
|
||||||
|
|
||||||
|
|
||||||
class PyTeXRootDirType(Enum):
|
|
||||||
BUILD = 1
|
|
||||||
PYTEX_SOURCE = 2
|
|
||||||
DOC = 3
|
|
||||||
TEX_SOURCE = 4
|
|
|
@ -1 +0,0 @@
|
||||||
from .relative_path import RelativePath
|
|
|
@ -1,2 +0,0 @@
|
||||||
from .enums import *
|
|
||||||
from .pytex_file import PyTeXSourceFile
|
|
|
@ -10,3 +10,7 @@ JSON_VERSION = 'source version'
|
||||||
JSON_COMMIT_HASH = 'commit hash'
|
JSON_COMMIT_HASH = 'commit hash'
|
||||||
JSON_BRANCH = 'branch'
|
JSON_BRANCH = 'branch'
|
||||||
JSON_DIRTY = 'dirty'
|
JSON_DIRTY = 'dirty'
|
||||||
|
|
||||||
|
DEFAULT_VERSION = '0.0.0'
|
||||||
|
DEFAULT_BRANCH = 'NO-BRANCH'
|
||||||
|
DEFAULT_HASH = '0000000000000000000000000000000000000000000000000000000000000000'
|
||||||
|
|
|
@ -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:
|
class GitVersionInfo(Config):
|
||||||
def __init__(self, dictionary: dict):
|
def __init__(self):
|
||||||
if not all(
|
|
||||||
x in dictionary.keys() for
|
|
||||||
x in [JSON_BRANCH, JSON_COMMIT_HASH]
|
|
||||||
):
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
self._dirty: bool = dictionary[JSON_DIRTY]
|
self._dirty: Optional[bool] = None
|
||||||
self._commit_hash: str = dictionary[JSON_COMMIT_HASH]
|
self._commit_hash: Optional[str] = None
|
||||||
self._branch: Optional[str] = \
|
self._branch: Optional[str] = None
|
||||||
dictionary[JSON_BRANCH] if JSON_BRANCH in dictionary.keys() \
|
self._version: Optional[str] = None
|
||||||
else None
|
|
||||||
self._version: Optional[str] = \
|
def set_from_json(self, content: Dict):
|
||||||
dictionary[JSON_VERSION] if JSON_VERSION in dictionary.keys() \
|
content = self._fill_keys(content)
|
||||||
else None
|
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
|
@property
|
||||||
def is_dirty(self) -> bool:
|
def dirty(self) -> bool:
|
||||||
return self._dirty
|
if self._dirty is None:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return self._dirty
|
||||||
|
|
||||||
|
@dirty.setter
|
||||||
|
def dirty(self, dirty: bool):
|
||||||
|
self._dirty = dirty
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def version(self) -> Optional[str]:
|
def version(self) -> str:
|
||||||
|
if self._version is None:
|
||||||
|
return DEFAULT_VERSION
|
||||||
return self._version
|
return self._version
|
||||||
|
|
||||||
@property
|
@version.setter
|
||||||
def commit_hash(self) -> Optional[str]:
|
def version(self, version: str):
|
||||||
return self._commit_hash
|
self._version = version
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def branch(self) -> Optional[str]:
|
def commit_hash(self) -> str:
|
||||||
return self._branch
|
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
|
||||||
|
|
|
@ -2,7 +2,7 @@ import os
|
||||||
from pathlib import Path, PurePath, PurePosixPath, PureWindowsPath
|
from pathlib import Path, PurePath, PurePosixPath, PureWindowsPath
|
||||||
|
|
||||||
from PyTeX.build.build import PyTeXBuilder
|
from PyTeX.build.build import PyTeXBuilder
|
||||||
from PyTeX.build.enums.enums import PyTeXRootDirType
|
from PyTeX.build.build.enums import PyTeXRootDirType
|
||||||
|
|
||||||
|
|
||||||
class PyTeXPurePath:
|
class PyTeXPurePath:
|
||||||
|
|
Loading…
Reference in a new issue