]> gitweb.michael.orlitzky.com - mjotex.git/commitdiff
GNUmakefile: strip comments from sage listings
authorMichael Orlitzky <michael@orlitzky.com>
Mon, 26 Jan 2026 19:46:01 +0000 (14:46 -0500)
committerMichael Orlitzky <michael@orlitzky.com>
Mon, 26 Jan 2026 19:48:58 +0000 (14:48 -0500)
This is helpful if you want to put a comment at the beginning
explaining What the listing does.

GNUmakefile

index 8f7e8200062481eea04f4388fb57541877225bfb..4d21cd466fcf3619b806572e0ae4fe8d378b8b39 100644 (file)
@@ -185,9 +185,15 @@ $(BUILDDIR)/$(PN).log: $(SRCS)
 
 # How do we convert a raw listing into something testable by sage? We
 # append/prepend triple quotes to make the whole thing into a doctest,
-# and then we replace any blank lines by "<BLANKLINE>".
+# strip all comment lines (only outside of a sage: prompt), and then
+# we replace any blank lines by "<BLANKLINE>".
 sage_listings/%.py: sage_listings/%.listing
-       echo '"""' > $@ && cat $< >> $@ && echo '"""' >> $@ && sed -i 's/^[[:space:]]*$$/<BLANKLINE>/' $@
+       echo '"""' > $@
+       cat $< >> $@
+       echo '"""' >> $@
+       sed -e '/^[[:space:]]*#/d' \
+           -e 's/^[[:space:]]*$$/<BLANKLINE>/' \
+           -i $@
 
 # Ensure that there are no overfull or underfull boxes in the output
 # document by parsing the log for said warnings.