pytex/PyTeX/format/enums.py

98 lines
2.6 KiB
Python

from __future__ import annotations
from enum import Enum
from typing import Optional
class NamingScheme(Enum):
prepend_author = 0
clean = 1
class TeXType(Enum):
TeXPackage = 'package'
TeXClass = 'class'
TeXDocstrip = 'docstrip file'
TeXDictionary = 'dictionary'
TeXDocumentation = 'documentation'
@staticmethod
def parse(tex_type: str) -> Optional[TeXType]:
if tex_type is None:
return None
switcher = {
'package': TeXType.TeXPackage,
'sty': TeXType.TeXPackage,
'class': TeXType.TeXClass,
'cls': TeXType.TeXClass,
'dictionary': TeXType.TeXDictionary,
'dict': TeXType.TeXDictionary,
'documentation': TeXType.TeXDocumentation,
'doc': TeXType.TeXDocumentation, # TODO: dangerous?
'dtx': TeXType.TeXDocstrip,
'docstrip': TeXType.TeXDocstrip,
'strip': TeXType.TeXDocstrip
}
if tex_type not in switcher.keys():
raise NotImplementedError
else:
return switcher[tex_type]
class TeXFlavour(Enum):
TeX = 'TeX'
LaTeX2e = 'LaTeX2e'
LaTeX3 = 'LaTeX3'
@staticmethod
def parse(flavour: str) -> Optional[TeXFlavour]:
if flavour is None:
return None
switcher = {
'1': TeXFlavour.TeX,
'2': TeXFlavour.LaTeX2e,
'2e': TeXFlavour.LaTeX2e,
'3': TeXFlavour.LaTeX3,
'TeX': TeXFlavour.TeX,
'LaTeX2e': TeXFlavour.LaTeX2e,
'LaTeX2': TeXFlavour.LaTeX2e,
'LateX3': TeXFlavour.LaTeX3
}
if flavour not in switcher.keys():
raise NotImplementedError
else:
return switcher[flavour]
class MacroReplacementAtomIF:
pass
class FormatterProperty(MacroReplacementAtomIF, Enum):
author = 'author'
shortauthor = 'shortauthor'
date = 'date'
year = 'year'
raw_name = 'raw_name' # The 'raw' name of the package, without author prefix
name = 'name' # class or package name
version = 'version'
file_name = 'file_name'
source_file_name = 'source_file_name'
repo_version = 'repo_version'
repo_branch = 'repo_branch'
repo_commit = 'repo_commit'
repo_dirty = 'repo_dirty'
pytex_version = 'pytex_version'
pytex_branch = 'pytex_branch'
pytex_commit = 'pytex_commit'
pytex_dirty = 'pytex_dirty'
tex_type = 'tex_type'
tex_flavour = 'latex_flavour'
class Argument(MacroReplacementAtomIF, Enum):
one = 1
two = 2
three = 3
four = 4
five = 5
six = 6