move macro-related enums. add attributes to pytex formatters

This commit is contained in:
Maximilian Keßler 2022-02-09 11:49:14 +01:00
parent 3f25502be4
commit 5a5f0ef1e4
3 changed files with 40 additions and 25 deletions

View file

@ -1,5 +1,7 @@
from enum import Enum from enum import Enum
from PyTeX.format.macros import MacroReplacementAtomIF
class NamingScheme(Enum): class NamingScheme(Enum):
prepend_author = 0 prepend_author = 0
@ -54,3 +56,24 @@ class TeXFlavour(Enum):
raise NotImplementedError raise NotImplementedError
else: else:
return switcher[flavour] return switcher[flavour]
class FormatterProperty(MacroReplacementAtomIF, Enum):
author = 'author'
shortauthor = 'shortauthor'
date = 'date'
year = 'year'
version = 'version',
source_file_name = 'source_file_name'
name = 'name' # class or package name
repo_version = 'repo_version'
pytex_version = 'pytex_version'
class Argument(MacroReplacementAtomIF, Enum):
one = 1
two = 2
three = 3
four = 4
five = 5
six = 6

View file

@ -1,35 +1,14 @@
import re import re
from enum import Enum
from typing import List, Union from typing import List, Union
from .constants import * from .constants import *
from .enums import FormatterProperty, Argument
class MacroReplacementAtomIF: class MacroReplacementAtomIF:
pass pass
class FormatterProperty(MacroReplacementAtomIF, Enum):
author = 'author'
shortauthor = 'shortauthor'
date = 'date'
year = 'year'
version = 'version',
file_name = 'file_name'
name = 'name' # class or package name
repo_version = 'repo_version'
pytex_version = 'pytex_version'
class Argument(MacroReplacementAtomIF, Enum):
one = 1
two = 2
three = 3
four = 4
five = 5
six = 6
class MacroReplacement: class MacroReplacement:
def __init__( def __init__(
self, self,

View file

@ -4,17 +4,18 @@ from typing import Optional
from .constants import * from .constants import *
from .formatterif import FormatterIF from .formatterif import FormatterIF
from .formatting_config import FormattingConfig from .formatting_config import FormattingConfig, GitVersionInfo
from .generic_text import GenericText from .generic_text import GenericText
from ..logger import logger from ..logger import logger
from abc import ABC from abc import ABC
from .enums import *
class PyTeXFormatter(FormatterIF, ABC): class PyTeXFormatter(FormatterIF, ABC):
def __init__( def __init__(
self, self,
input_file: Optional[Path] = None, input_file: Optional[Path] = None,
config: Optional[FormattingConfig] = None, config: Optional[FormattingConfig] = None,
git_version_info: Optional[GitVersionInfo] = None,
locate_file_config: bool = True, locate_file_config: bool = True,
allow_infile_config: bool = True allow_infile_config: bool = True
): ):
@ -23,7 +24,8 @@ class PyTeXFormatter(FormatterIF, ABC):
config=config config=config
) )
self._config: Optional[FormattingConfig] = self._config # for type-hinting self._config: Optional[FormattingConfig] = self._config # for type-hinting
self._allow_infile_config = allow_infile_config self._git_version_info: Optional[GitVersionInfo] = git_version_info
self._allow_infile_config: bool = allow_infile_config
self._header: Optional[GenericText] = None self._header: Optional[GenericText] = None
if locate_file_config: if locate_file_config:
file_config = self.parse_file_config() file_config = self.parse_file_config()
@ -117,6 +119,17 @@ class PyTeXFormatter(FormatterIF, ABC):
return self._header return self._header
@property
def attribute_dict(self) -> Dict:
return {
FormatterProperty.author.value: self.config.author,
FormatterProperty.shortauthor.value: '',
FormatterProperty.version.value: self.config.version,
FormatterProperty.source_file_name.value: self._input_file.name,
FormatterProperty.name.value: '',
}
# TODO
def make_header(self, **kwargs) -> str: def make_header(self, **kwargs) -> str:
return '\n'.join( return '\n'.join(
[ [