Skip to content

Commit 80792d8

Browse files
committed
better verbosity
1 parent 9525f6a commit 80792d8

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

Makefile

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
RUN = uv run
44
PACKAGE_DIRS = _plotly_utils plotly
55
CODE_DIRS = ${PACKAGE_DIRS} scripts
6-
EXAMPLE_SRC = doc/python/cone-plot.md doc/python/strip-charts.md
76
# EXAMPLE_SRC = $(wildcard doc/python/*.md)
7+
EXAMPLE_SRC = doc/python/cone-plot.md doc/python/strip-charts.md
8+
EXAMPLE_DST = $(patsubst doc/python/%.md,pages/examples/%.md,${EXAMPLE_SRC})
89

910
## commands: show available commands
1011
commands:
@@ -23,9 +24,15 @@ docs-lint:
2324
docs-tmp:
2425
MKDOCS_TEMP_DIR=./docs_tmp ${RUN} mkdocs build
2526

26-
## examples: generate Markdown from doc/python
27-
examples:
28-
${RUN} bin/run_markdown.py --outdir pages/examples --inline --verbose ${EXAMPLE_SRC}
27+
## examples-batch: generate Markdown for all doc/python
28+
examples-batch:
29+
${RUN} bin/run_markdown.py --outdir pages/examples --inline --verbose 1 ${EXAMPLE_SRC}
30+
31+
## examples: generate Markdown for individual doc/python
32+
examples: ${EXAMPLE_DST}
33+
34+
pages/examples/%.md: doc/python/%.md
35+
${RUN} bin/run_markdown.py --outdir pages/examples --inline --verbose 2 $<
2936

3037
## format: reformat code
3138
format:

bin/run_markdown.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
def main():
1717
args = _parse_args()
18-
for filename in args.input:
18+
for filename in args.inputs:
1919
_do_file(args, Path(filename))
2020

2121

@@ -43,27 +43,27 @@ def _do_file(args, input_file):
4343
sys.exit(1)
4444

4545
# Parse markdown and extract code blocks
46-
_report(args.verbose, f"Processing {input_file}...")
46+
_report(args.verbose > 0, f"Processing {input_file}...")
4747
code_blocks = _parse_md(content)
48-
_report(args.verbose, f"- Found {len(code_blocks)} code blocks")
48+
_report(args.verbose > 1, f"- Found {len(code_blocks)} code blocks")
4949

5050
# Execute code blocks and collect results
5151
execution_results = []
5252
figure_counter = 0
5353
for i, block in enumerate(code_blocks):
54-
_report(args.verbose, f"- Executing block {i + 1}/{len(code_blocks)}")
54+
_report(args.verbose > 1, f"- Executing block {i + 1}/{len(code_blocks)}")
5555
figure_counter, result = _run_code(block["code"], args.outdir, stem, figure_counter)
5656
execution_results.append(result)
57-
_report(result["error"], f" - Warning: block {i + 1} had an error")
58-
_report(result["images"], f" - Generated {len(result['images'])} image(s)")
57+
_report(args.verbose > 0 and bool(result["error"]), f" - Warning: block {i + 1} had an error")
58+
_report(args.verbose > 1 and bool(result["images"]), f" - Generated {len(result['images'])} image(s)")
5959

6060
# Generate and save output
6161
content = _generate_markdown(args, content, code_blocks, execution_results, args.outdir)
6262
try:
6363
with open(output_file, "w", encoding="utf-8") as f:
6464
f.write(content)
65-
_report(args.verbose, f"- Output written to {output_file}")
66-
_report(any(result["images"] for result in execution_results), f"- Images saved to {args.outdir}")
65+
_report(args.verbose > 1, f"- Output written to {output_file}")
66+
_report(args.verbose > 1 and any(result["images"] for result in execution_results), f"- Images saved to {args.outdir}")
6767
except Exception as e:
6868
print(f"Error writing output file: {e}", file=sys.stderr)
6969
sys.exit(1)
@@ -149,10 +149,10 @@ def _generate_markdown(args, content, code_blocks, execution_results, output_dir
149149
def _parse_args():
150150
"""Parse command-line arguments."""
151151
parser = argparse.ArgumentParser(description="Process Markdown files with code blocks")
152-
parser.add_argument("input", nargs="+", help="Input .md file")
152+
parser.add_argument("inputs", nargs="+", help="Input .md files")
153153
parser.add_argument("--inline", action="store_true", help="Inline HTML in .md")
154154
parser.add_argument("--outdir", type=Path, help="Output directory")
155-
parser.add_argument("--verbose", action="store_true", help="Report progress")
155+
parser.add_argument("--verbose", type=int, default=0, help="Integer verbosity level")
156156
return parser.parse_args()
157157

158158

0 commit comments

Comments
 (0)