initial commit: draft data structures

This commit is contained in:
Maximilian Keßler 2022-02-04 11:39:15 +01:00
commit 8c7deb2cbc
16 changed files with 199 additions and 0 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
__pycache__
main.py

0
PyTeX/__init__.py Normal file
View file

0
PyTeX/config/__init__.py Normal file
View file

12
PyTeX/config/enums.py Normal file
View file

@ -0,0 +1,12 @@
from enum import Enum
class NamingScheme(Enum):
prepend_author = 0
clean = 1
class License(Enum):
LPPL = 0
GPLv3 = 1
MIT = 2

View file

@ -0,0 +1,34 @@
from pathlib import Path
from typing import Optional
from .source_config import BasicSourceConfig
class GlobalPyTeXConfig:
_source_root: Optional[Path] = None
_build_root: Optional[Path] = None
_doc_root: Optional[Path] = None
_tex_root: Optional[Path] = None
_default_source_config: Optional[BasicSourceConfig] = None
_recursive: bool = True
_overwrite_existing_files: bool = False
_clean_old_files: True
_allow_dirty: bool = False
@classmethod
def build_root(cls) -> Path:
return cls._build_root
@classmethod
def doc_root(cls) -> Path:
return cls._doc_root
@classmethod
def source_root(cls) -> Path:
return cls._source_root
@classmethod
def tex_root(cls) -> Path:
return cls._tex_root

View file

@ -0,0 +1,35 @@
from typing import List, Optional, Union
from .enums import NamingScheme, License
class BasicSourceConfig:
def __init__(self):
self._naming_scheme: Union[NamingScheme, str] = NamingScheme.clean # either some predefined scheme, or a formatting string
self._author: Optional[str] = None
self._license: Optional[List[License]] = None
self._extra_header: List[str] = []
self._include_extra_header: bool = True
self._include_build_time: bool = False
self._include_pytex_version: bool = False
self._include_pytex_info_text: bool = False
self._include_repo_version: bool = False
self._include_repo_info_text: bool = False
self._include_drv: bool = True
self._include_ins: bool = True
self._default_docstrip_guards: Optional[List[str]] = None
class PyTeXSourceConfig(BasicSourceConfig):
def __init__(self):
super().__init__()
self._available_docstrip_guards: Optional[List[str]] = None
self._doc_dependencies: Optional[List[str]] = None
self._tex_dependencies: Optional[List[str]] = None
class DocSourceConfig:
def __init__(self):
self._documents: Optional[List[str]] = None
self._dependencies: Optional[List[str]] = None

View file

0
PyTeX/logger/__init__.py Normal file
View file

7
PyTeX/logger/logger.py Normal file
View file

@ -0,0 +1,7 @@
import logging
logging.basicConfig(
filename='pytex.log',
encoding='utf-8',
level=logging.INFO
)

View file

View file

@ -0,0 +1,34 @@
from pathlib import Path
from enum import Enum
from PyTeX.config.global_config import GlobalPyTeXConfig
class PyTeXRootDir(Enum):
BUILD = 1
SOURCE = 2
DOC = 3
TEX = 4
class RelativePath:
def __init__(self, path: Path):
self._path: Path = path
@property
def path(self) -> Path:
return self._path
def absolute_path(self, pytex_root_dir: PyTeXRootDir) -> Path:
root: Path = {
PyTeXRootDir.BUILD: GlobalPyTeXConfig.build_root(),
PyTeXRootDir.SOURCE: GlobalPyTeXConfig.source_root(),
PyTeXRootDir.DOC: GlobalPyTeXConfig.doc_root(),
PyTeXRootDir.TEX: GlobalPyTeXConfig.tex_root()
}[pytex_root_dir]
return root / self._path
def __eq__(self, other):
return self.path == other.path
def __str__(self):
return str(self.path)

View file

View file

View file

@ -0,0 +1,12 @@
JSON_NAME = 'name'
JSON_BUILD_TIME = 'build time'
JSON_SOURCE_FILES = 'source files'
JSON_MD5_CHECKSUM = 'md5 checksum'
JSON_PYTEX = 'pytex'
JSON_REPOSITORY = 'repository'
JSON_VERSION = 'source version'
JSON_COMMIT_HASH = 'commit hash'
JSON_BRANCH = 'branch'
JSON_DIRTY = 'dirty'

View file

@ -0,0 +1,63 @@
from typing import Optional
from .constants import *
class GitVersionInfo:
def __init__(self, dictionary: dict):
if not all(
x in dictionary.keys() for
x in [JSON_BRANCH, JSON_COMMIT_HASH]
):
raise ValueError # TODO
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
@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]:
return self._branch
class FileVersionInfo:
def __init__(self, dictionary: dict):
if JSON_MD5_CHECKSUM not in dictionary.keys():
raise ValueError # TODO
else:
self._md5_checksum = dictionary[JSON_MD5_CHECKSUM]
self._source_repository_version: Optional[GitVersionInfo] = \
GitVersionInfo(dictionary[JSON_REPOSITORY]) if JSON_REPOSITORY in dictionary.keys() \
else None
self._pytex_repository_version: Optional[GitVersionInfo] = \
GitVersionInfo(dictionary[JSON_PYTEX]) if JSON_PYTEX in dictionary.keys() \
else None
@property
def md5_checksum(self) -> str:
return self._md5_checksum
@property
def source_repository_version(self) -> Optional[GitVersionInfo]:
return self._source_repository_version
@property
def pytex_repository_version(self) -> Optional[GitVersionInfo]:
return self._pytex_repository_version