Skip to content

Commit

Permalink
Render source code using python functions instead of Jinja templates
Browse files Browse the repository at this point in the history
- Type checker can help out when updating the functions
- The output formatting is much more readable now
  • Loading branch information
virtuald committed Oct 27, 2024
1 parent a7dc982 commit 1f72c34
Show file tree
Hide file tree
Showing 21 changed files with 1,217 additions and 945 deletions.
1 change: 0 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
recursive-include robotpy_build/pybind11/include *.h
recursive-include robotpy_build/autowrap *.j2
recursive-include robotpy_build/include *.h
45 changes: 45 additions & 0 deletions robotpy_build/autowrap/buffer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import io
import contextlib
import inspect


class RenderBuffer:
def __init__(self) -> None:
self._buffer = io.StringIO()

self._indent = ""
self._indentlen = 0

def getvalue(self) -> str:
return self._buffer.getvalue()

def rel_indent(self, spaces: int):
self._indentlen += spaces
self._indent = " " * self._indentlen

@contextlib.contextmanager
def indent(self, spaces: int = 2):
self._indentlen += spaces
self._indent = " " * self._indentlen
try:
yield
finally:
self._indentlen -= spaces
self._indent = " " * self._indentlen

def writeln(self, s: str = ""):
if not s:
self._buffer.write("\n")
else:
for line in s.splitlines(False):
if line:
self._buffer.write(f"{self._indent}{line}\n")
else:
self._buffer.write("\n")

def write_trim(self, s: str):
for line in inspect.cleandoc(s).splitlines(False):
if line:
self._buffer.write(f"{self._indent}{line}\n")
else:
self._buffer.write("\n")
28 changes: 0 additions & 28 deletions robotpy_build/autowrap/cls_prologue.cpp.j2

This file was deleted.

30 changes: 0 additions & 30 deletions robotpy_build/autowrap/cls_rpy_include.hpp.j2

This file was deleted.

56 changes: 0 additions & 56 deletions robotpy_build/autowrap/cls_tmpl_impl.hpp.j2

This file was deleted.

23 changes: 0 additions & 23 deletions robotpy_build/autowrap/cls_tmpl_inst.cpp.j2

This file was deleted.

14 changes: 0 additions & 14 deletions robotpy_build/autowrap/cls_tmpl_inst.hpp.j2

This file was deleted.

Loading

0 comments on commit 1f72c34

Please sign in to comment.