pytex/PyTeX/format/formatterif.py

66 lines
1.8 KiB
Python

from pathlib import Path
from typing import List, Optional, Dict, Tuple
from abc import ABC, abstractmethod
from .config import Config
from .formatting_config import FormattingConfig
class FormatterIF(ABC):
"""
A formatter is bound to a specific input file with some
building configuration.
"""
def __init__(
self,
input_file: Optional[Path] = None,
config: Optional[Config] = None,
):
self._input_file: Optional[Path] = input_file
self._config: Optional[Config] = config
@abstractmethod
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
:return: When configuration files are needed for a future
build of the output files, a list of the file names and their
needed configurations. Else None.
"""
@property
@abstractmethod
def output_files(self) -> List[str]:
"""
:return: List of files that will be built when the formatter is invoked
"""
@property
@abstractmethod
def dependencies(self) -> List[str]:
"""
:return: List of dependencies (as str filenames)
"""
@property
def input_file(self) -> Path:
if self._input_file is None:
raise NotImplementedError
return self._input_file
@input_file.setter
def input_file(self, input_file: Path) -> None:
self._input_file = input_file
@property
def config(self) -> Config:
if self._config is None:
raise NotImplementedError
return self._config
@config.setter
def config(self, config: Config):
self._config = config