scripts: codemap[d3].py: Added -e/--error-on-recursion

Might as well, since we already need to find this to calculate stack
info.

I've been considering adding -z/--depth to these scripts as well, but
that would require quite a bit more work. It's probably not worth the
added complexity/headache. Depth termination would need to happen on the
javascript side, and we'd still need cycle detection anyways.

But an error code is easy to add.
This commit is contained in:
Christopher Haster
2025-03-17 13:08:50 -05:00
parent 460d8870ec
commit 50e22ac690
2 changed files with 16 additions and 0 deletions

View File

@@ -1247,6 +1247,10 @@ def main_(f, paths, *,
line = canvas.draw(row)
f.writeln(line)
if (args.get('error_on_recursion')
and mt.isinf(totals.get('stack', 0))):
sys.exit(2)
def main(paths, *,
height=None,
@@ -1496,6 +1500,10 @@ if __name__ == "__main__":
'--no-label',
action='store_true',
help="Don't render any labels.")
parser.add_argument(
'-e', '--error-on-recursion',
action='store_true',
help="Error if any functions are recursive.")
parser.add_argument(
'--code-path',
type=lambda x: x.split(),

View File

@@ -1990,6 +1990,10 @@ def main(paths, output, *,
totals.get('stack', 0)),
totals.get('ctx', 0)))
if (args.get('error_on_recursion')
and mt.isinf(totals.get('stack', 0))):
sys.exit(2)
if __name__ == "__main__":
import argparse
@@ -2218,6 +2222,10 @@ if __name__ == "__main__":
'--background',
help="Background color to use. Note #00000000 can make the "
"background transparent.")
parser.add_argument(
'-e', '--error-on-recursion',
action='store_true',
help="Error if any functions are recursive.")
parser.add_argument(
'--code-path',
type=lambda x: x.split(),