Compare commits
No commits in common. "latex-packages" and "master" have entirely different histories.
latex-pack
...
master
9 changed files with 39 additions and 116 deletions
|
@ -1,8 +1,7 @@
|
|||
from PyTeX.default_formatters import ClassFormatter, PackageFormatter, DictionaryFormatter, DocstripFormatter
|
||||
from PyTeX.default_formatters import ClassFormatter, PackageFormatter, DictionaryFormatter
|
||||
|
||||
__all__ = [
|
||||
"ClassFormatter",
|
||||
"PackageFormatter",
|
||||
"DictionaryFormatter",
|
||||
'DocstripFormatter'
|
||||
"DictionaryFormatter"
|
||||
]
|
||||
|
|
|
@ -76,8 +76,6 @@ def build(
|
|||
files.append(file)
|
||||
for file in src_dir.rglob('*.pycls3'):
|
||||
files.append(file)
|
||||
for file in src_dir.rglob('*.dtx'):
|
||||
files.append(file)
|
||||
else:
|
||||
for file in src_dir.glob('*.pysty'):
|
||||
files.append(file)
|
||||
|
@ -89,15 +87,12 @@ def build(
|
|||
files.append(file)
|
||||
for file in src_dir.glob('*.pycls3'):
|
||||
files.append(file)
|
||||
for file in src_dir.glob('*.dtx'):
|
||||
files.append(file)
|
||||
|
||||
sources_to_build = []
|
||||
for file in files:
|
||||
if last_build_info:
|
||||
last_build_info_for_this_file =\
|
||||
list(filter(lambda i: i['source file'] == str(file.relative_to(src_dir)),
|
||||
last_build_info['tex_sources']))
|
||||
list(filter(lambda i: i['source file'] == str(file.relative_to(src_dir)), last_build_info['tex_sources']))
|
||||
else:
|
||||
last_build_info_for_this_file = []
|
||||
sources_to_build.append(
|
||||
|
@ -148,9 +143,8 @@ def build(
|
|||
file.unlink()
|
||||
elif not str(file.relative_to(output_dir)) in built_files:
|
||||
if not file.is_dir() and not str(file.relative_to(output_dir)) == 'build_info.json':
|
||||
if '.git' not in str(file) and 'documentation/' not in str(file):
|
||||
# PyTeX does not at all know something about this file
|
||||
raise UnknownFileInBuildDirectoryError(file.relative_to(output_dir))
|
||||
raise UnknownFileInBuildDirectory(file.relative_to(output_dir))
|
||||
|
||||
if write_build_information:
|
||||
with open(output_dir / 'build_info.json', 'w') as f:
|
||||
|
|
|
@ -77,7 +77,7 @@ def parse_and_build(arglist: [str]):
|
|||
)
|
||||
parser.add_argument(
|
||||
'-l', '--license',
|
||||
help='Insert LPPL and GPLv3 license into package header',
|
||||
help='Insert MIT license into package header',
|
||||
action='store_true',
|
||||
dest='include_license'
|
||||
)
|
||||
|
|
|
@ -2,7 +2,7 @@ from pathlib import Path
|
|||
from typing import Optional, List
|
||||
|
||||
from PyTeX.build.git_hook import is_recent, get_latest_commit
|
||||
from PyTeX import PackageFormatter, ClassFormatter, DictionaryFormatter, DocstripFormatter
|
||||
from PyTeX import PackageFormatter, ClassFormatter, DictionaryFormatter
|
||||
from PyTeX.errors import *
|
||||
from .pytex_msg import pytex_msg
|
||||
from PyTeX.utils import md5
|
||||
|
@ -79,8 +79,6 @@ class TexFileToFormat:
|
|||
latex_file_type = 'class'
|
||||
elif '.pydict' in self.src_path.name:
|
||||
latex_file_type = 'dictionary'
|
||||
elif '.dtx' in self.src_path.name:
|
||||
latex_file_type = 'ERROR'
|
||||
else:
|
||||
raise ProgrammingError
|
||||
new_header.append(line.format(
|
||||
|
@ -128,8 +126,6 @@ class TexFileToFormat:
|
|||
author=self.current_build_info.author,
|
||||
header=self._header
|
||||
)
|
||||
elif self.src_path.name.endswith('.dtx'):
|
||||
formatter = DocstripFormatter(name=self.src_path.with_suffix('').name)
|
||||
else:
|
||||
raise ProgrammingError
|
||||
formatter.make_default_macros()
|
||||
|
|
|
@ -1,27 +1,22 @@
|
|||
LICENSE = [
|
||||
'Copyright © {year} {copyright_holders}',
|
||||
'',
|
||||
'This work may be distributed and/or modified',
|
||||
'Permission is hereby granted, free of charge, to any person obtaining a copy',
|
||||
'of this software and associated documentation files (the “Software”), to deal',
|
||||
'in the Software without restriction, including without limitation the rights',
|
||||
'to use, copy, modify, merge, publish, distribute, sublicense, and/or sell',
|
||||
'copies of the Software, and to permit persons to whom the Software is',
|
||||
'furnished to do so, subject to the following conditions:',
|
||||
'The above copyright notice and this permission notice shall be included in all',
|
||||
'copies or substantial portions of the Software.',
|
||||
'',
|
||||
'1. under the LaTeX Project Public License and/or',
|
||||
'2. under the GNU General Public License'
|
||||
'',
|
||||
'',
|
||||
'Distribution under conditions of the LaTeX Project Public License,',
|
||||
'requires either version 1.3 of this license or (at your option)',
|
||||
'any later version.',
|
||||
'The latest version of this license is in',
|
||||
' http://www.latex-project.org/lppl.txt',
|
||||
'and version 1.3 or later is part of all distributions of LaTeX',
|
||||
'version 2005/12/01 or later.',
|
||||
'',
|
||||
'This work has the LPPL maintenance status \`maintained\'.',
|
||||
'',
|
||||
'The Current Maintainer of this work is {copyright_holders}.',
|
||||
'',
|
||||
'',
|
||||
'Distribution under the GNU General Public License requires either',
|
||||
'version 3 or (at your opinion) any later version.'
|
||||
'THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR',
|
||||
'IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,',
|
||||
'FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE',
|
||||
'AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER',
|
||||
'LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,',
|
||||
'OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE',
|
||||
'SOFTWARE.'
|
||||
]
|
||||
|
||||
PYTEX_INFO_TEXT = [
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
from .class_formatter import ClassFormatter
|
||||
from .package_formatter import PackageFormatter
|
||||
from .dictionary_formatter import DictionaryFormatter
|
||||
from .docstrip_formatter import DocstripFormatter
|
||||
|
||||
__all__ = [
|
||||
'PackageFormatter',
|
||||
'ClassFormatter',
|
||||
'DictionaryFormatter',
|
||||
'DocstripFormatter'
|
||||
'DictionaryFormatter'
|
||||
]
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
from pathlib import Path
|
||||
from typing import Dict, Optional, List
|
||||
import subprocess
|
||||
|
||||
from PyTeX.formatter import Formatter
|
||||
from PyTeX.utils import ensure_file_integrity
|
||||
from PyTeX.errors import FileNotGeneratedFromDTXFileError, LatexMKError
|
||||
|
||||
|
||||
class DocstripFormatter(Formatter):
|
||||
def __init__(self, name: str):
|
||||
self.name = name
|
||||
self.filename = self.name + '.sty'
|
||||
Formatter.__init__(self)
|
||||
|
||||
def expected_file_name(self) -> str:
|
||||
return self.filename
|
||||
|
||||
def format_file(self, input_path: Path, output_dir: Path,
|
||||
relative_name: Optional[str] = None,
|
||||
last_build_info: Optional[List[Dict]] = None) -> List[str]:
|
||||
ensure_file_integrity(output_dir / self.filename, str(Path(relative_name).parent / self.filename), last_build_info)
|
||||
try:
|
||||
result = subprocess.run(['latexmk', '-gg', '-output-directory=/tmp'], cwd=str(input_path.parent),
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL
|
||||
)
|
||||
except subprocess.CalledProcessError:
|
||||
raise LatexMKError(self.filename)
|
||||
if not result:
|
||||
pass
|
||||
sty_file = (Path('/tmp') / input_path.with_suffix('.sty').name)
|
||||
if sty_file.exists():
|
||||
sty = sty_file.read_text()
|
||||
else:
|
||||
raise FileNotGeneratedFromDTXFileError(self.filename, 'style')
|
||||
output_dir.mkdir(parents=True, exist_ok=True)
|
||||
(output_dir / self.filename).write_text(sty)
|
||||
return [self.filename]
|
|
@ -1,6 +1,6 @@
|
|||
from .errors import PyTexError, SubmoduleDirtyForbiddenError, ProgrammingError, ExtraHeaderFileNotFoundError, \
|
||||
UnknownTexVersionError, ModifiedFileInBuildDirectoryError, UnknownFileInBuildDirectoryNoOverwriteError, \
|
||||
UnknownFileInBuildDirectoryError, LatexMKError, FileNotGeneratedFromDTXFileError
|
||||
UnknownFileInBuildDirectory
|
||||
|
||||
__all__ = [
|
||||
'PyTexError',
|
||||
|
@ -10,7 +10,5 @@ __all__ = [
|
|||
'UnknownTexVersionError',
|
||||
'ModifiedFileInBuildDirectoryError',
|
||||
'UnknownFileInBuildDirectoryNoOverwriteError',
|
||||
'UnknownFileInBuildDirectoryError',
|
||||
'LatexMKError',
|
||||
'FileNotGeneratedFromDTXFileError'
|
||||
'UnknownFileInBuildDirectory'
|
||||
]
|
||||
|
|
|
@ -56,28 +56,10 @@ class UnknownFileInBuildDirectoryNoOverwriteError(PyTexError):
|
|||
)
|
||||
|
||||
|
||||
class UnknownFileInBuildDirectoryError(PyTexError):
|
||||
class UnknownFileInBuildDirectory(PyTexError):
|
||||
def __init__(self, filename):
|
||||
super().__init__(
|
||||
f"Detected unknown file {filename} in build directory."
|
||||
f"PyTeX has no knowledge about this, you should probably"
|
||||
f"remove it."
|
||||
)
|
||||
|
||||
|
||||
class LatexMKError(PyTexError):
|
||||
def __init__(self, filename):
|
||||
super().__init__(
|
||||
f"Running latexmk on file {filename} resulted in an error. "
|
||||
f"Make sure this file is well-formed and an appropriate "
|
||||
f"'.latexmkrc' is present in its directory."
|
||||
)
|
||||
|
||||
|
||||
class FileNotGeneratedFromDTXFileError(PyTexError):
|
||||
def __init__(self, filename, type):
|
||||
super().__init__(
|
||||
f"Running latexmk on {filename} did not produce a LaTeX "
|
||||
f"{type} file as needed. I do not know how to build "
|
||||
f"a {type} from this '.dtx' file."
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue