pytex/PyTeX/format/formatterif.py

67 lines
1.8 KiB
Python
Raw Normal View History

2022-02-06 15:10:28 +01:00
from pathlib import Path
2022-02-07 18:36:30 +01:00
from typing import List, Optional, Dict, Tuple
2022-02-08 17:04:16 +01:00
from abc import ABC, abstractmethod
2022-02-06 15:10:28 +01:00
2022-02-07 17:32:46 +01:00
from .config import Config
from .formatting_config import FormattingConfig
2022-02-06 15:10:28 +01:00
2022-02-08 17:04:16 +01:00
class FormatterIF(ABC):
2022-02-06 15:10:28 +01:00
"""
A formatter is bound to a specific input file with some
building configuration.
"""
2022-02-07 18:36:30 +01:00
2022-02-06 15:10:28 +01:00
def __init__(
self,
input_file: Optional[Path] = None,
config: Optional[Config] = None,
):
self._input_file: Optional[Path] = input_file
self._config: Optional[Config] = config
2022-02-08 17:04:16 +01:00
@abstractmethod
def format(self, build_dir: Path, overwrite: bool = False) -> List[Tuple[str, FormattingConfig]]:
2022-02-06 15:10:28 +01:00
"""
:param build_dir: Directory where output files are written to
2022-02-06 16:50:09 +01:00
:param overwrite: overwrite existing files
2022-02-06 15:10:28 +01:00
: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
2022-02-08 18:26:25 +01:00
@abstractmethod
2022-02-06 15:10:28 +01:00
def output_files(self) -> List[str]:
"""
:return: List of files that will be built when the formatter is invoked
"""
2022-02-08 17:04:16 +01:00
@property
2022-02-08 18:26:25 +01:00
@abstractmethod
2022-02-08 17:04:16 +01:00
def dependencies(self) -> List[str]:
"""
:return: List of dependencies (as str filenames)
"""
2022-02-06 15:10:28 +01:00
@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