refactor files and rework git version info into a Config file

This commit is contained in:
Maximilian Keßler 2022-02-07 21:18:03 +01:00
parent 07280ce9f2
commit c83f24798e
12 changed files with 76 additions and 43 deletions

View file

@ -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:

View file

@ -1,6 +1,13 @@
from enum import Enum
class PyTeXRootDirType(Enum):
BUILD = 1
PYTEX_SOURCE = 2
DOC = 3
TEX_SOURCE = 4
class PyTeXFileType(Enum):
PyTeXSourceFile = 'PyTeXSourceFile'
TeXSourceFile = 'TeXSourceFile'

View file

@ -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:

View file

@ -1,6 +1,6 @@
from pathlib import Path
from PyTeX.build.enums.enums import PyTeXRootDirType
from PyTeX.build.build.enums import PyTeXRootDirType
class RelativePath:

View file

@ -1 +0,0 @@
from .enums import *

View file

@ -1,8 +0,0 @@
from enum import Enum
class PyTeXRootDirType(Enum):
BUILD = 1
PYTEX_SOURCE = 2
DOC = 3
TEX_SOURCE = 4

View file

@ -1 +0,0 @@
from .relative_path import RelativePath

View file

@ -1,2 +0,0 @@
from .enums import *
from .pytex_file import PyTeXSourceFile

View file

@ -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'

View file

@ -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

View file

@ -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: