integrate docstrip source files
This commit is contained in:
parent
6277050e22
commit
e661ceee64
5 changed files with 46 additions and 4 deletions
|
@ -1,7 +1,8 @@
|
||||||
from PyTeX.default_formatters import ClassFormatter, PackageFormatter, DictionaryFormatter
|
from PyTeX.default_formatters import ClassFormatter, PackageFormatter, DictionaryFormatter, DocstripFormatter
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"ClassFormatter",
|
"ClassFormatter",
|
||||||
"PackageFormatter",
|
"PackageFormatter",
|
||||||
"DictionaryFormatter"
|
"DictionaryFormatter",
|
||||||
|
'DocstripFormatter'
|
||||||
]
|
]
|
||||||
|
|
|
@ -76,6 +76,8 @@ def build(
|
||||||
files.append(file)
|
files.append(file)
|
||||||
for file in src_dir.rglob('*.pycls3'):
|
for file in src_dir.rglob('*.pycls3'):
|
||||||
files.append(file)
|
files.append(file)
|
||||||
|
for file in src_dir.rglob('*.dtx'):
|
||||||
|
files.append(file)
|
||||||
else:
|
else:
|
||||||
for file in src_dir.glob('*.pysty'):
|
for file in src_dir.glob('*.pysty'):
|
||||||
files.append(file)
|
files.append(file)
|
||||||
|
@ -87,6 +89,8 @@ def build(
|
||||||
files.append(file)
|
files.append(file)
|
||||||
for file in src_dir.glob('*.pycls3'):
|
for file in src_dir.glob('*.pycls3'):
|
||||||
files.append(file)
|
files.append(file)
|
||||||
|
for file in src_dir.glob('*.dtx'):
|
||||||
|
files.append(file)
|
||||||
|
|
||||||
sources_to_build = []
|
sources_to_build = []
|
||||||
for file in files:
|
for file in files:
|
||||||
|
|
|
@ -2,7 +2,7 @@ from pathlib import Path
|
||||||
from typing import Optional, List
|
from typing import Optional, List
|
||||||
|
|
||||||
from PyTeX.build.git_hook import is_recent, get_latest_commit
|
from PyTeX.build.git_hook import is_recent, get_latest_commit
|
||||||
from PyTeX import PackageFormatter, ClassFormatter, DictionaryFormatter
|
from PyTeX import PackageFormatter, ClassFormatter, DictionaryFormatter, DocstripFormatter
|
||||||
from PyTeX.errors import *
|
from PyTeX.errors import *
|
||||||
from .pytex_msg import pytex_msg
|
from .pytex_msg import pytex_msg
|
||||||
from PyTeX.utils import md5
|
from PyTeX.utils import md5
|
||||||
|
@ -79,6 +79,8 @@ class TexFileToFormat:
|
||||||
latex_file_type = 'class'
|
latex_file_type = 'class'
|
||||||
elif '.pydict' in self.src_path.name:
|
elif '.pydict' in self.src_path.name:
|
||||||
latex_file_type = 'dictionary'
|
latex_file_type = 'dictionary'
|
||||||
|
elif '.dtx' in self.src_path.name:
|
||||||
|
latex_file_type = 'ERROR'
|
||||||
else:
|
else:
|
||||||
raise ProgrammingError
|
raise ProgrammingError
|
||||||
new_header.append(line.format(
|
new_header.append(line.format(
|
||||||
|
@ -126,6 +128,8 @@ class TexFileToFormat:
|
||||||
author=self.current_build_info.author,
|
author=self.current_build_info.author,
|
||||||
header=self._header
|
header=self._header
|
||||||
)
|
)
|
||||||
|
elif self.src_path.name.endswith('.dtx'):
|
||||||
|
formatter = DocstripFormatter(name=self.src_path.with_suffix('').name)
|
||||||
else:
|
else:
|
||||||
raise ProgrammingError
|
raise ProgrammingError
|
||||||
formatter.make_default_macros()
|
formatter.make_default_macros()
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
from .class_formatter import ClassFormatter
|
from .class_formatter import ClassFormatter
|
||||||
from .package_formatter import PackageFormatter
|
from .package_formatter import PackageFormatter
|
||||||
from .dictionary_formatter import DictionaryFormatter
|
from .dictionary_formatter import DictionaryFormatter
|
||||||
|
from .docstrip_formatter import DocstripFormatter
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
'PackageFormatter',
|
'PackageFormatter',
|
||||||
'ClassFormatter',
|
'ClassFormatter',
|
||||||
'DictionaryFormatter'
|
'DictionaryFormatter',
|
||||||
|
'DocstripFormatter'
|
||||||
]
|
]
|
||||||
|
|
31
default_formatters/docstrip_formatter.py
Normal file
31
default_formatters/docstrip_formatter.py
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Dict, Optional, List
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
from PyTeX.formatter import Formatter
|
||||||
|
from PyTeX.utils import ensure_file_integrity
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
||||||
|
result = subprocess.Popen(['pdflatex', self.name + '.dtx'], cwd=str(input_path.parent),
|
||||||
|
stdout=subprocess.DEVNULL,
|
||||||
|
stderr=subprocess.DEVNULL
|
||||||
|
)
|
||||||
|
if not result:
|
||||||
|
pass
|
||||||
|
sty = input_path.with_suffix('.sty').read_text()
|
||||||
|
output_dir.mkdir(parents=True, exist_ok=True)
|
||||||
|
(output_dir / self.filename).write_text(sty)
|
||||||
|
return [self.filename]
|
Loading…
Reference in a new issue