From 315e3647ab7279084c0662801eefb611fda957c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Fri, 17 Dec 2021 15:09:04 +0100 Subject: [PATCH] handle package naming style Option --name can now be set to either raw or prepend-author this controls the derivation of the name of the formatted package from the source file read in. --- build/utils/pytex_file.py | 8 +++++--- default_formatters/class_formatter.py | 5 +++-- default_formatters/package_formatter.py | 5 +++-- formatter/tex_formatter.py | 12 +++++++++--- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/build/utils/pytex_file.py b/build/utils/pytex_file.py index 42a5758..044b840 100644 --- a/build/utils/pytex_file.py +++ b/build/utils/pytex_file.py @@ -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 @@ -80,12 +80,14 @@ class TexFileToFormat: formatter = PackageFormatter( package_name=self.src_path.with_suffix('').name, author=self.current_build_info.author, - extra_header=self._header) + extra_header=self._header, + latex_name=self.latex_name) elif '.pycls' in self.src_path.name: formatter = ClassFormatter( class_name=self.src_path.with_suffix('').name, author=self.current_build_info.author, - extra_header=self._header) + extra_header=self._header, + latex_name=self.latex_name) else: raise Exception('Programming error. Please contact the developer.') pytex_msg('Writing file {}'.format(formatter.file_name)) diff --git a/default_formatters/class_formatter.py b/default_formatters/class_formatter.py index c93a8a4..3e8c541 100644 --- a/default_formatters/class_formatter.py +++ b/default_formatters/class_formatter.py @@ -4,8 +4,9 @@ import PyTeX.macros class ClassFormatter(PyTeX.formatter.TexFormatter): - def __init__(self, class_name: str, author: str, extra_header: [str] = []): - PyTeX.formatter.TexFormatter.__init__(self, class_name, author, extra_header, '.cls') + def __init__(self, class_name: str, author: str, extra_header: [str] = [], + latex_name: str = 'prepend-author'): + PyTeX.formatter.TexFormatter.__init__(self, class_name, author, extra_header, '.cls', latex_name) def make_default_macros(self): PyTeX.macros.make_default_macros(self, 'class') diff --git a/default_formatters/package_formatter.py b/default_formatters/package_formatter.py index 774e4ab..afb7555 100644 --- a/default_formatters/package_formatter.py +++ b/default_formatters/package_formatter.py @@ -4,8 +4,9 @@ import PyTeX.macros class PackageFormatter(PyTeX.formatter.TexFormatter): - def __init__(self, package_name: str, author: str, extra_header: [str] = []): - PyTeX.formatter.TexFormatter.__init__(self, package_name, author, extra_header, '.sty') + def __init__(self, package_name: str, author: str, extra_header: [str] = [], + latex_name: str = 'prepend-author'): + PyTeX.formatter.TexFormatter.__init__(self, package_name, author, extra_header, '.sty', latex_name) def make_default_macros(self): PyTeX.macros.make_default_macros(self, 'package') diff --git a/formatter/tex_formatter.py b/formatter/tex_formatter.py index 60ca700..79ff550 100644 --- a/formatter/tex_formatter.py +++ b/formatter/tex_formatter.py @@ -8,14 +8,20 @@ from PyTeX.base import Attributes, Args class TexFormatter: - def __init__(self, name: str, author: str, header: Optional[List[str]], file_extension: str): + def __init__(self, name: str, author: str, header: Optional[List[str]], file_extension: str, + latex_name: str): 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.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.prefix = self.name_lowercase.replace('-', '@') + '@' self.file_name = self.name_lowercase + file_extension self.date = datetime.now().strftime('%Y/%m/%d')