add i/o methods to build dir specification / make it a config
This commit is contained in:
parent
bcae59052c
commit
4557f282ce
8 changed files with 49 additions and 15 deletions
|
@ -1,2 +1,2 @@
|
||||||
from .build_dir_spec import BuildDirSpecification
|
from .build_dir_spec import BuildDirConfig
|
||||||
from .builder import PyTeXBuilder
|
from .builder import PyTeXBuilder
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
from pathlib import Path, PurePath
|
from pathlib import Path, PurePath
|
||||||
from typing import Optional
|
from typing import Optional, Dict
|
||||||
|
from .constants import *
|
||||||
|
from ...format.config import Config, recursive_merge_dictionaries, clean_dict
|
||||||
|
|
||||||
|
|
||||||
class BuildDirSpecification:
|
class BuildDirConfig(Config):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
source_root: Optional[Path] = None,
|
source_root: Optional[Path] = None,
|
||||||
|
@ -17,6 +19,24 @@ class BuildDirSpecification:
|
||||||
self._tex_source_root: Optional[Path] = tex_root
|
self._tex_source_root: Optional[Path] = tex_root
|
||||||
self._wrapper_dir: Optional[PurePath] = wrapper_dir
|
self._wrapper_dir: Optional[PurePath] = wrapper_dir
|
||||||
|
|
||||||
|
def set_from_json(self, content: Dict):
|
||||||
|
content = self._fill_keys(content)
|
||||||
|
|
||||||
|
self._tex_source_root = content[YAML_TEX_SOURCE_ROOT]
|
||||||
|
self._pytex_source_root = content[YAML_PYTEX_SOURCE_ROOT]
|
||||||
|
self._build_root = content[YAML_BUILD_ROOT]
|
||||||
|
self._doc_root = content[YAML_DOC_ROOT]
|
||||||
|
self._wrapper_dir = content[YAML_WRAPPER_DIR]
|
||||||
|
|
||||||
|
def to_json(self) -> Dict:
|
||||||
|
return {
|
||||||
|
YAML_WRAPPER_DIR: self._wrapper_dir,
|
||||||
|
YAML_BUILD_ROOT: self._build_root,
|
||||||
|
YAML_DOC_ROOT: self._doc_root,
|
||||||
|
YAML_TEX_SOURCE_ROOT: self._tex_source_root,
|
||||||
|
YAML_PYTEX_SOURCE_ROOT: self._pytex_source_root
|
||||||
|
}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def build_root(self) -> Path:
|
def build_root(self) -> Path:
|
||||||
if self._build_root is None:
|
if self._build_root is None:
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from PyTeX.build.build import BuildDirSpecification
|
from PyTeX.build.build import BuildDirConfig
|
||||||
from PyTeX.build.enums import PyTeXRootDirType
|
from PyTeX.build.enums import PyTeXRootDirType
|
||||||
from ...logger import logger
|
from ...logger import logger
|
||||||
from .pytex_config import PyTeXConfig
|
from .pytex_config import PyTeXConfig
|
||||||
|
@ -10,7 +10,7 @@ from .pytex_config import PyTeXConfig
|
||||||
class PyTeXBuilder:
|
class PyTeXBuilder:
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
build_dir_spec: BuildDirSpecification
|
build_dir_spec: BuildDirConfig
|
||||||
):
|
):
|
||||||
|
|
||||||
self._build_target_type: Optional[PyTeXRootDirType] = None
|
self._build_target_type: Optional[PyTeXRootDirType] = None
|
||||||
|
|
10
PyTeX/build/build/constants.py
Normal file
10
PyTeX/build/build/constants.py
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
YAML_BUILD_ROOT = 'build'
|
||||||
|
YAML_PYTEX_SOURCE_ROOT = 'source'
|
||||||
|
YAML_TEX_SOURCE_ROOT = 'tex'
|
||||||
|
YAML_DOC_ROOT = 'doc'
|
||||||
|
YAML_RECURSIVE = 'recursive'
|
||||||
|
YAML_CLEAN_OLD_FILES = 'clean'
|
||||||
|
YAML_OVERWRITE_FILES = 'overwrite'
|
||||||
|
YAML_ALLOW_DIRTY_BUILD = 'dirty'
|
||||||
|
YAML_FORCE_MODE = 'force'
|
||||||
|
YAML_WRAPPER_DIR = 'wrapper'
|
|
@ -1,15 +1,15 @@
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from PyTeX.build.build import BuildDirSpecification
|
from PyTeX.build.build import BuildDirConfig
|
||||||
from PyTeX.format.formatting_config import FormattingConfig
|
from PyTeX.format.formatting_config import FormattingConfig
|
||||||
|
|
||||||
|
|
||||||
class PyTeXConfig:
|
class PyTeXConfig:
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
build_dir_spec: Optional[BuildDirSpecification] = None
|
build_dir_spec: Optional[BuildDirConfig] = None
|
||||||
):
|
):
|
||||||
self._build_dir_specification: Optional[BuildDirSpecification] = build_dir_spec
|
self._build_dir_specification: Optional[BuildDirConfig] = build_dir_spec
|
||||||
|
|
||||||
self._default_formatting_config: Optional[FormattingConfig] = None
|
self._default_formatting_config: Optional[FormattingConfig] = None
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ class PyTeXConfig:
|
||||||
@property
|
@property
|
||||||
def build_dir_specification(self):
|
def build_dir_specification(self):
|
||||||
if self._build_dir_specification is None:
|
if self._build_dir_specification is None:
|
||||||
return BuildDirSpecification()
|
return BuildDirConfig()
|
||||||
else:
|
else:
|
||||||
return self._build_dir_specification
|
return self._build_dir_specification
|
||||||
|
|
||||||
|
|
|
@ -76,6 +76,13 @@ class Config:
|
||||||
else:
|
else:
|
||||||
pass # TODO
|
pass # TODO
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _fill_keys(cls, dictionary: Dict):
|
||||||
|
return recursive_merge_dictionaries(
|
||||||
|
cls().to_json(),
|
||||||
|
dictionary
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def recursive_merge_dictionaries(dict1: Dict, dict2: Dict) -> Dict:
|
def recursive_merge_dictionaries(dict1: Dict, dict2: Dict) -> Dict:
|
||||||
|
|
||||||
|
|
|
@ -59,10 +59,7 @@ class FormattingConfig(Config):
|
||||||
self._tex_flavour: Optional[TeXFlavour] = None
|
self._tex_flavour: Optional[TeXFlavour] = None
|
||||||
|
|
||||||
def set_from_json(self, content: Dict):
|
def set_from_json(self, content: Dict):
|
||||||
content = recursive_merge_dictionaries(
|
content = self._fill_keys(content)
|
||||||
FormattingConfig().to_json(),
|
|
||||||
content
|
|
||||||
)
|
|
||||||
|
|
||||||
info = content[YAML_INFO]
|
info = content[YAML_INFO]
|
||||||
self._author = info[YAML_AUTHOR]
|
self._author = info[YAML_AUTHOR]
|
||||||
|
|
4
main.py
4
main.py
|
@ -1,13 +1,13 @@
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from PyTeX.build.build import PyTeXBuilder
|
from PyTeX.build.build import PyTeXBuilder
|
||||||
from PyTeX.build.build.build_dir_spec import BuildDirSpecification
|
from PyTeX.build.build.build_dir_spec import BuildDirConfig
|
||||||
from PyTeX.build.enums import *
|
from PyTeX.build.enums import *
|
||||||
from PyTeX.build.paths import RelativePath
|
from PyTeX.build.paths import RelativePath
|
||||||
|
|
||||||
from PyTeX.format.formatting_config import FormattingConfig
|
from PyTeX.format.formatting_config import FormattingConfig
|
||||||
from PyTeX.format.generic_text import GenericText
|
from PyTeX.format.generic_text import GenericText
|
||||||
|
|
||||||
spec = BuildDirSpecification(
|
spec = BuildDirConfig(
|
||||||
source_root=Path('src'),
|
source_root=Path('src'),
|
||||||
tex_root=Path('build/source'),
|
tex_root=Path('build/source'),
|
||||||
build_root=Path('build'),
|
build_root=Path('build'),
|
||||||
|
|
Loading…
Reference in a new issue