Merge branch 'master' of gitlab.com:latexci/packages/PyTeX

This commit is contained in:
Maximilian Keßler 2022-01-11 21:37:42 +01:00
commit d1806d970f
5 changed files with 40 additions and 27 deletions

View file

@ -96,7 +96,8 @@ class BuildInfo:
or include_pytex_info_text
or include_timestamp
or include_pytex_version
or include_git_version):
or include_git_version
or extra_header):
self._header = None
return
else:
@ -113,7 +114,8 @@ class BuildInfo:
self._header += PYTEX_VERSION
if include_git_version:
self._header += SOURCE_CODE_VERSION
self._header += ['']
if len(self._header) > 0:
self._header += ['']
if extra_header:
self._header += extra_header + ['']

View file

@ -21,7 +21,7 @@ class TexFileToFormat:
build_all: bool = False):
self.src_path = src_path
self.build_path = build_dir
self.tex_name = latex_name # Still an identifier on how to name the package when being formatted
self.latex_name = latex_name # Still an identifier on how to name the package when being formatted
self.current_build_info = current_build_info
self.last_build_info = last_build_info
self.allow_dirty = allow_dirty
@ -68,19 +68,20 @@ class TexFileToFormat:
def __format_header(self):
new_header = []
for line in self.current_build_info.header:
if '.pysty' in self.src_path.name:
latex_file_type = 'package'
elif '.pycls' in self.src_path.name:
latex_file_type = 'class'
elif '.pydict' in self.src_path.name:
latex_file_type = 'dictionary'
else:
raise Exception('Programming error. Please contact the developer.')
new_header.append(line.format(
source_file=self.src_path.name,
latex_file_type=latex_file_type
))
if self.current_build_info.header:
for line in self.current_build_info.header:
if '.pysty' in self.src_path.name:
latex_file_type = 'package'
elif '.pycls' in self.src_path.name:
latex_file_type = 'class'
elif '.pydict' in self.src_path.name:
latex_file_type = 'dictionary'
else:
raise Exception('Programming error. Please contact the developer.')
new_header.append(line.format(
source_file=self.src_path.name,
latex_file_type=latex_file_type
))
self._header = new_header
def __format(self) -> dict:
@ -90,28 +91,32 @@ class TexFileToFormat:
author=self.current_build_info.author,
extra_header=self._header,
tex_version='LaTeX2e',
version=self.current_build_info.packages_version)
version=self.current_build_info.packages_version,
latex_name=self.latex_name)
elif self.src_path.name.endswith('.pycls'):
formatter = ClassFormatter(
class_name=self.src_path.with_suffix('').name,
author=self.current_build_info.author,
extra_header=self._header,
tex_version='LaTeX2e',
version=self.current_build_info.packages_version)
version=self.current_build_info.packages_version,
latex_name=self.latex_name)
elif self.src_path.name.endswith('.pysty3'):
formatter = PackageFormatter(
package_name=self.src_path.with_suffix('').name,
author=self.current_build_info.author,
extra_header=self._header,
tex_version='LaTeX3',
version=self.current_build_info.packages_version)
version=self.current_build_info.packages_version,
latex_name=self.latex_name)
elif self.src_path.name.endswith('.pycls3'):
formatter = ClassFormatter(
class_name=self.src_path.with_suffix('').name,
author=self.current_build_info.author,
extra_header=self._header,
tex_version='LaTeX3',
version=self.current_build_info.packages_version)
version=self.current_build_info.packages_version,
latex_name=self.latex_name)
elif self.src_path.name.endswith('.pydict'):
formatter = DictionaryFormatter(
kind=self.src_path.with_suffix('').name,

View file

@ -5,7 +5,7 @@ import PyTeX.macros
class ClassFormatter(PyTeX.formatter.TexFormatter):
def __init__(self, class_name: str, author: str, extra_header: [str] = [], tex_version: str = 'LaTeX2e',
version: str = '0.0.0'):
version: str = '0.0.0', latex_name: str = 'prepend-author'):
PyTeX.formatter.TexFormatter.__init__(
self,
name=class_name,
@ -13,7 +13,8 @@ class ClassFormatter(PyTeX.formatter.TexFormatter):
header=extra_header,
file_extension='.cls',
tex_version=tex_version,
version=version
version=version,
latex_name=latex_name
)
self.tex_version = tex_version

View file

@ -5,7 +5,7 @@ import PyTeX.macros
class PackageFormatter(PyTeX.formatter.TexFormatter):
def __init__(self, package_name: str, author: str, extra_header: [str] = [], tex_version: str = 'LaTeX2e',
version: str = '0.0.0'):
version: str = '0.0.0', latex_name: str = 'prepend-author'):
PyTeX.formatter.TexFormatter.__init__(
self,
name=package_name,
@ -13,7 +13,8 @@ class PackageFormatter(PyTeX.formatter.TexFormatter):
header=extra_header,
file_extension='.sty',
tex_version=tex_version,
version=version
version=version,
latex_name=latex_name
)
self.tex_version = tex_version

View file

@ -9,11 +9,12 @@ from PyTeX.base import Attributes, Args
class TexFormatter:
def __init__(self, name: str, author: str, header: Optional[List[str]], file_extension: str,
tex_version: str, version: str):
tex_version: str, version: str, latex_name: str):
self.version = version
self.header = header
self.name_raw = name
self.author = author
self.latex_name = latex_name
author_parts = self.author.lower().replace('ß', 'ss').split(' ')
self.author_acronym = author_parts[0][0] + author_parts[-1]
self.date = datetime.now().strftime('%Y/%m/%d')
@ -21,8 +22,11 @@ class TexFormatter:
self.replace_dict: Dict = {}
self.arg_replace_dict: Dict = {}
self.source_file_name = "not specified"
self.name_lowercase = r'{prefix}-{name}'.format(prefix=self.author_acronym,
name=self.name_raw.lower().strip().replace(' ', '-'))
if self.latex_name == 'prepend-author':
self.name_lowercase = r'{prefix}-{name}'.format(prefix=self.author_acronym,
name=self.name_raw.lower().strip().replace(' ', '-'))
else:
self.name_lowercase = self.name_raw.lower().strip().replace(' ', '-')
self.file_name = self.name_lowercase + file_extension
if tex_version == 'LaTeX2e':
self.prefix = self.name_lowercase.replace('-', '@') + '@'