From 8c7deb2cbcf86fadc9d840fe62e18731c6a6f887 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Fri, 4 Feb 2022 11:39:15 +0100 Subject: [PATCH] initial commit: draft data structures --- .gitignore | 2 + PyTeX/__init__.py | 0 PyTeX/config/__init__.py | 0 PyTeX/config/enums.py | 12 ++++ PyTeX/config/global_config.py | 34 ++++++++++ PyTeX/config/source_config.py | 35 +++++++++++ PyTeX/formatting/__init__.py | 0 PyTeX/logger/__init__.py | 0 PyTeX/logger/logger.py | 7 +++ PyTeX/pathlib/__init__.py | 0 PyTeX/pathlib/relative_paths.py | 34 ++++++++++ PyTeX/versioning/__init__.py | 0 PyTeX/versioning/git/__init__.py | 0 PyTeX/versioning/version_info/__init__.py | 0 PyTeX/versioning/version_info/constants.py | 12 ++++ PyTeX/versioning/version_info/version_info.py | 63 +++++++++++++++++++ 16 files changed, 199 insertions(+) create mode 100644 .gitignore create mode 100644 PyTeX/__init__.py create mode 100644 PyTeX/config/__init__.py create mode 100644 PyTeX/config/enums.py create mode 100644 PyTeX/config/global_config.py create mode 100644 PyTeX/config/source_config.py create mode 100644 PyTeX/formatting/__init__.py create mode 100644 PyTeX/logger/__init__.py create mode 100644 PyTeX/logger/logger.py create mode 100644 PyTeX/pathlib/__init__.py create mode 100644 PyTeX/pathlib/relative_paths.py create mode 100644 PyTeX/versioning/__init__.py create mode 100644 PyTeX/versioning/git/__init__.py create mode 100644 PyTeX/versioning/version_info/__init__.py create mode 100644 PyTeX/versioning/version_info/constants.py create mode 100644 PyTeX/versioning/version_info/version_info.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5fd3baa --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +__pycache__ +main.py diff --git a/PyTeX/__init__.py b/PyTeX/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/PyTeX/config/__init__.py b/PyTeX/config/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/PyTeX/config/enums.py b/PyTeX/config/enums.py new file mode 100644 index 0000000..5e3cfed --- /dev/null +++ b/PyTeX/config/enums.py @@ -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 diff --git a/PyTeX/config/global_config.py b/PyTeX/config/global_config.py new file mode 100644 index 0000000..3738446 --- /dev/null +++ b/PyTeX/config/global_config.py @@ -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 diff --git a/PyTeX/config/source_config.py b/PyTeX/config/source_config.py new file mode 100644 index 0000000..727b6d2 --- /dev/null +++ b/PyTeX/config/source_config.py @@ -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 diff --git a/PyTeX/formatting/__init__.py b/PyTeX/formatting/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/PyTeX/logger/__init__.py b/PyTeX/logger/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/PyTeX/logger/logger.py b/PyTeX/logger/logger.py new file mode 100644 index 0000000..915e8fd --- /dev/null +++ b/PyTeX/logger/logger.py @@ -0,0 +1,7 @@ +import logging + +logging.basicConfig( + filename='pytex.log', + encoding='utf-8', + level=logging.INFO +) \ No newline at end of file diff --git a/PyTeX/pathlib/__init__.py b/PyTeX/pathlib/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/PyTeX/pathlib/relative_paths.py b/PyTeX/pathlib/relative_paths.py new file mode 100644 index 0000000..6a425f2 --- /dev/null +++ b/PyTeX/pathlib/relative_paths.py @@ -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) diff --git a/PyTeX/versioning/__init__.py b/PyTeX/versioning/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/PyTeX/versioning/git/__init__.py b/PyTeX/versioning/git/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/PyTeX/versioning/version_info/__init__.py b/PyTeX/versioning/version_info/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/PyTeX/versioning/version_info/constants.py b/PyTeX/versioning/version_info/constants.py new file mode 100644 index 0000000..ca02312 --- /dev/null +++ b/PyTeX/versioning/version_info/constants.py @@ -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' diff --git a/PyTeX/versioning/version_info/version_info.py b/PyTeX/versioning/version_info/version_info.py new file mode 100644 index 0000000..69041dc --- /dev/null +++ b/PyTeX/versioning/version_info/version_info.py @@ -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