fix some bugs in parsing

This commit is contained in:
Maximilian Keßler 2022-02-07 18:33:00 +01:00
parent fd54e5221a
commit 3dfb889728
5 changed files with 13 additions and 23 deletions

View file

@ -32,14 +32,10 @@ class PyTeXConfig(Config):
YAML_CLEAN_OLD_FILES: self._clean_old_files, YAML_CLEAN_OLD_FILES: self._clean_old_files,
YAML_ALLOW_DIRTY_BUILD: self._allow_dirty, YAML_ALLOW_DIRTY_BUILD: self._allow_dirty,
YAML_FORCE_MODE: self._force_mode, YAML_FORCE_MODE: self._force_mode,
YAML_DIRS: self._build_dir_specification.to_json() YAML_DIRS: self.build_dir_specification.to_json()
}, },
YAML_DEFAULT: { YAML_DEFAULT: self.default_formatting_config.to_json(),
self._default_formatting_config.to_json() YAML_CONFIGS: self._configs
},
YAML_CONFIGS: {
self._configs
}
} }
def set_from_json(self, content: Dict): def set_from_json(self, content: Dict):

View file

@ -15,7 +15,7 @@ YAML_HEADER = 'header'
YAML_INCLUDE_EXTRA_HEADER = 'include' YAML_INCLUDE_EXTRA_HEADER = 'include'
YAML_INCLUDE_BUILD_TIME = 'time' YAML_INCLUDE_BUILD_TIME = 'time'
YAML_INCLUDE_VERSION = 'version' YAML_INCLUDE_VERSION = 'version'
YAML_INCLUDE_INFO_TEXT = 'text' YAML_INCLUDE_INFO_TEXT = 'info'
YAML_INCLUDE_TIME = 'time' YAML_INCLUDE_TIME = 'time'
YAML_AUTHOR = 'author' YAML_AUTHOR = 'author'
YAML_VERSION = 'version' YAML_VERSION = 'version'

View file

@ -67,6 +67,7 @@ class FormattingConfig(Config):
self._tex_flavour = info[YAML_TEX_FLAVOUR] self._tex_flavour = info[YAML_TEX_FLAVOUR]
self._tex_type = info[YAML_TEX_TYPE] self._tex_type = info[YAML_TEX_TYPE]
self._description = info[YAML_DESCRIPTION] self._description = info[YAML_DESCRIPTION]
self._version = info[YAML_VERSION]
header = content[YAML_HEADER] header = content[YAML_HEADER]
extra = header[YAML_EXTRA] extra = header[YAML_EXTRA]

View file

@ -4,14 +4,14 @@ from ..logger import logger
class GenericText: class GenericText:
def __init__(self, content: Optional[Union[List[str], Path]] = None): def __init__(self, content: Optional[Union[List[str], Path, str]] = None):
if isinstance(content, list): if isinstance(content, list):
self._content: Optional[List[str]] = content self._content: Optional[List[str]] = content
self._path = None self._path = None
self._initialized = True self._initialized = True
elif isinstance(content, Path): elif isinstance(content, Path) or isinstance(content, str):
self._content: Optional[List[str]] = None self._content: Optional[List[str]] = None
self._path = content self._path = Path(content)
self._initialized = True self._initialized = True
else: else:
self._content = None self._content = None

17
main.py
View file

@ -1,9 +1,11 @@
from pathlib import Path from pathlib import Path
from PyTeX.build.build import PyTeXBuilder from PyTeX.build.build import PyTeXBuilder, BuildDirConfig
from PyTeX.build.build.build_dir_spec import BuildDirConfig 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.build.build.pytex_config import PyTeXConfig
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
@ -53,20 +55,11 @@ config: FormattingConfig = FormattingConfig()
dump = config.to_json() dump = config.to_json()
config.naming_scheme = 'prepend-author'
conf_path = Path('/home/maximilian/git/LatexPackages/.pytexrc')
config.extra_header = GenericText(Path('header.txt')) pytex_config = PyTeXConfig.from_yaml(conf_path)
config.extra_header = GenericText(['hello', 'world'])
config.dump_as_yaml(Path('test.yaml'))
json = config.to_json()
config2 = FormattingConfig()
config2.set_from_json(json)
config3 = FormattingConfig.from_yaml(Path('test.yaml'))
pass pass