fix future config handling, use abstract classes
This commit is contained in:
parent
1a6989734e
commit
6cd8d9655d
4 changed files with 17 additions and 9 deletions
|
@ -5,6 +5,7 @@ from typing import List, Dict, Tuple, Optional
|
|||
from .constants import *
|
||||
from .pytex_formatter import PyTeXFormatter
|
||||
from ..logger import logger
|
||||
from .formatting_config import FormattingConfig
|
||||
|
||||
|
||||
class DictFormatter(PyTeXFormatter):
|
||||
|
@ -21,6 +22,9 @@ class DictFormatter(PyTeXFormatter):
|
|||
self._dict_name = self.input_file.name.split('.')[0]
|
||||
self._translations = None
|
||||
|
||||
def dependencies(self) -> List[str]:
|
||||
return [] # No dependencies for dictionaries
|
||||
|
||||
@property
|
||||
def translations(self) -> Dict:
|
||||
if self._translations is None:
|
||||
|
@ -50,7 +54,7 @@ class DictFormatter(PyTeXFormatter):
|
|||
translations[self._languages[n]][line[0]] = line[n]
|
||||
return translations
|
||||
|
||||
def format(self, build_dir: Path, overwrite: bool = False) -> Optional[List[Tuple[str, Dict]]]:
|
||||
def format(self, build_dir: Path, overwrite: bool = False) -> List[Tuple[str, FormattingConfig]]:
|
||||
build_dir.mkdir(parents=True, exist_ok=True)
|
||||
self.make_header()
|
||||
for language in self._languages:
|
||||
|
@ -86,4 +90,4 @@ class DictFormatter(PyTeXFormatter):
|
|||
logger.info(
|
||||
f'Successfully wrote dictionary file {output_file.name}.'
|
||||
)
|
||||
return None # No future configuration needed
|
||||
return [] # No future configuration needed
|
||||
|
|
|
@ -3,6 +3,7 @@ from typing import List, Optional, Dict, Tuple
|
|||
from abc import ABC, abstractmethod
|
||||
|
||||
from .config import Config
|
||||
from .formatting_config import FormattingConfig
|
||||
|
||||
|
||||
class FormatterIF(ABC):
|
||||
|
@ -20,7 +21,7 @@ class FormatterIF(ABC):
|
|||
self._config: Optional[Config] = config
|
||||
|
||||
@abstractmethod
|
||||
def format(self, build_dir: Path, overwrite: bool = False) -> Optional[List[Tuple[str, Dict]]]:
|
||||
def format(self, build_dir: Path, overwrite: bool = False) -> List[Tuple[str, FormattingConfig]]:
|
||||
"""
|
||||
:param build_dir: Directory where output files are written to
|
||||
:param overwrite: overwrite existing files
|
||||
|
@ -44,6 +45,7 @@ class FormatterIF(ABC):
|
|||
:return: List of dependencies (as str filenames)
|
||||
"""
|
||||
|
||||
|
||||
@property
|
||||
def input_file(self) -> Path:
|
||||
if self._input_file is None:
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
from .formatting_config import FormattingConfig
|
||||
from .tex_formatter import TexFormatter
|
||||
from pathlib import Path
|
||||
from typing import Optional, List, Tuple, Dict
|
||||
|
@ -14,11 +15,11 @@ class SimpleTeXFormatter(TexFormatter):
|
|||
def close_output_stream(self):
|
||||
self._output_file.close()
|
||||
|
||||
def future_config(self) -> Optional[List[Tuple[str, Dict]]]:
|
||||
pass
|
||||
def future_config(self) -> List[Tuple[str, FormattingConfig]]:
|
||||
return [] # TODO
|
||||
|
||||
def dependencies(self) -> List[str]:
|
||||
return []
|
||||
return [] # TODO
|
||||
|
||||
def output_files(self) -> List[str]:
|
||||
return []
|
||||
return [self.input_file.with_suffix('').name]
|
||||
|
|
|
@ -2,6 +2,7 @@ from pathlib import Path
|
|||
from typing import List, TextIO, Optional, Tuple, Dict
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from .formatting_config import FormattingConfig
|
||||
from .macros import Macro
|
||||
from .pytex_formatter import PyTeXFormatter
|
||||
|
||||
|
@ -76,7 +77,7 @@ class TexFormatter(PyTeXFormatter, ABC):
|
|||
|
||||
@abstractmethod
|
||||
@property
|
||||
def future_config(self) -> Optional[List[Tuple[str, Dict]]]:
|
||||
def future_config(self) -> List[Tuple[str, FormattingConfig]]:
|
||||
"""
|
||||
# TODO
|
||||
:return:
|
||||
|
@ -135,7 +136,7 @@ class TexFormatter(PyTeXFormatter, ABC):
|
|||
break
|
||||
self._shipout_line()
|
||||
|
||||
def format(self, build_dir: Path, overwrite: bool = False) -> Optional[List[Tuple[str, Dict]]]:
|
||||
def format(self, build_dir: Path, overwrite: bool = False) -> List[Tuple[str, FormattingConfig]]:
|
||||
self.open_output_stream(build_dir)
|
||||
self.format_pre_header()
|
||||
self.format_header()
|
||||
|
|
Loading…
Reference in a new issue