pytex/PyTeX/format/enums.py

125 lines
3.3 KiB
Python
Raw Normal View History

2022-02-09 11:55:18 +01:00
from __future__ import annotations
2022-02-04 11:39:15 +01:00
from enum import Enum
2022-02-09 11:55:18 +01:00
from typing import Optional
2022-02-04 11:39:15 +01:00
2022-02-09 19:25:25 +01:00
class FormatterMode(Enum):
normal = 0
drop = 1
macrocode = 2
macrocode_drop = 3
2022-02-04 11:39:15 +01:00
class NamingScheme(Enum):
2022-02-09 17:31:06 +01:00
prepend_author = 'prepend_author'
clean = 'clean'
@staticmethod
def parse(naming_scheme: str) -> Optional[NamingScheme]:
if naming_scheme is None:
return None
switcher = {
'prepend-author': NamingScheme.prepend_author,
'prepend author': NamingScheme.prepend_author,
'author': NamingScheme.prepend_author,
'clean': NamingScheme.clean,
'raw': NamingScheme.clean
}
if not naming_scheme in switcher.keys():
raise NotImplementedError
else:
return switcher[naming_scheme]
2022-02-04 11:39:15 +01:00
2022-02-06 00:12:54 +01:00
class TeXType(Enum):
TeXPackage = 'package'
TeXClass = 'class'
TeXDocstrip = 'docstrip file'
TeXDictionary = 'dictionary'
TeXDocumentation = 'documentation'
2022-02-06 00:12:54 +01:00
@staticmethod
2022-02-09 11:55:18 +01:00
def parse(tex_type: str) -> Optional[TeXType]:
if tex_type is None:
return None
2022-02-06 00:12:54 +01:00
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
2022-02-09 11:55:18 +01:00
def parse(flavour: str) -> Optional[TeXFlavour]:
if flavour is None:
return None
2022-02-06 00:12:54 +01:00
switcher = {
'1': TeXFlavour.TeX,
'2': TeXFlavour.LaTeX2e,
'2e': TeXFlavour.LaTeX2e,
'3': TeXFlavour.LaTeX3,
'TeX': TeXFlavour.TeX,
'LaTeX2e': TeXFlavour.LaTeX2e,
2022-02-09 11:55:18 +01:00
'LaTeX2': TeXFlavour.LaTeX2e,
2022-02-06 00:12:54 +01:00
'LateX3': TeXFlavour.LaTeX3
}
if flavour not in switcher.keys():
raise NotImplementedError
else:
return switcher[flavour]
2022-02-09 11:55:18 +01:00
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
file_prefix = 'file_prefix'
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'
2022-02-09 21:11:46 +01:00
Tex_type= 'Tex_type'
tex_flavour = 'latex_flavour'
2022-02-09 19:50:49 +01:00
description = 'description'
class Argument(MacroReplacementAtomIF, Enum):
one = 1
two = 2
three = 3
four = 4
five = 5
six = 6