Skip to content

Commit ebe36e4

Browse files
committed
WIP, ENH: rich-click CLI
* related to gh-808 * adopt [`rich-click`](https://github.com/ewels/rich-click) for the pydarshan summary report CLI, with basic usage and heatmap option blocks * switch to `darshan_summary` as a console script that doesn't require prefixing with `python -m ..`; so new incantation looks like `darshan_summary --log_path treddy_runtime_heatmap_inactive_ranks.darshan` and reports the processing time in seconds automatically * there were two motivations for the above change: 1) simplify the command the user needs to remember 2) I almost always want to know how long the processing took, so report that time by default * this is just a skeleton, and doesn't actually hook in the HEATMAP options to actual changes in the report (yet); one other caveat is that the console script is less friendly for developers that use an "editable install" so you need to use `pip install .` instead of `pip install -e .`, which is a bit annoying, but probably lower priority than user experience concerns/improvements * some TODOs may include: - [ ] remove the old `argparse` CLI interface and hook the new `click`-based CLI interface into the testsuite somehow - [ ] actually implement the heatmap option effects (though this can probably be handled separately, other PRs dealing with that stuff already..) - [ ] discuss the initial set of options we want and how we want to group them into sections - [ ] decide if the extra dependencies are worth it for the CLI improvements (probably?)
1 parent 5934e41 commit ebe36e4

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import os
2+
import sys
3+
import time
4+
5+
if sys.version_info >= (3, 7):
6+
import importlib.resources as importlib_resources
7+
else:
8+
import importlib_resources
9+
10+
import darshan
11+
from darshan.cli.summary import ReportData
12+
13+
import rich_click as click
14+
from mako.template import Template
15+
16+
click.rich_click.OPTION_GROUPS = {
17+
"darshan_summary": [
18+
{
19+
"name": "Basic usage",
20+
"options": ["--log_path", "--output", "--help"],
21+
},
22+
{
23+
"name": "Heatmap Options",
24+
"options": ["--split-heatmaps", "--force-dxt"],
25+
},
26+
],
27+
}
28+
29+
30+
@click.command()
31+
@click.option('--log_path', help='Path to darshan log file.', required=True)
32+
@click.option('--output', help='Specify output filename.')
33+
# TODO: actually implement heatmap options in summary report
34+
@click.option('--split-heatmaps',
35+
is_flag=True,
36+
show_default=True,
37+
default=False,
38+
help='Separate heatmaps for read and write IO activity.')
39+
@click.option('--force-dxt',
40+
is_flag=True,
41+
show_default=True,
42+
default=False,
43+
help='Force plotting of DXT heatmaps even when large.')
44+
def summary_report(log_path,
45+
output,
46+
split_heatmaps,
47+
force_dxt):
48+
start = time.perf_counter()
49+
if output is None:
50+
# if no output is provided, use the log file
51+
# name to create the output filename
52+
log_filename = os.path.splitext(os.path.basename(log_path))[0]
53+
report_filename = f"{log_filename}_report.html"
54+
else:
55+
report_filename = output
56+
57+
# collect the report data to feed into the template
58+
report_data = ReportData(log_path=log_path)
59+
60+
with importlib_resources.path(darshan.cli, "base.html") as base_path:
61+
# load a template object using the base template
62+
template = Template(filename=str(base_path))
63+
# render the base template
64+
stream = template.render(report_data=report_data)
65+
with open(report_filename, "w") as f:
66+
# print a message so users know where to look for their report
67+
save_path = os.path.join(os.getcwd(), report_filename)
68+
click.echo(
69+
f"Report generated successfully. \n"
70+
f"Saving report at location: {save_path}"
71+
)
72+
# save the rendered html
73+
f.write(stream)
74+
end = time.perf_counter()
75+
total_time_sec = end - start
76+
click.echo(f"Report generation time (s): {total_time_sec:.2f}")

darshan-util/pydarshan/setup.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,8 @@
8686
"examples/example_logs/*",
8787
"examples/darshan-graph/*",
8888
"tests/input/*"]},
89+
entry_points={"console_scripts": [
90+
"darshan_summary = darshan.cli.darshan_summary:summary_report",
91+
],
92+
},
8993
)

0 commit comments

Comments
 (0)