Skip to content

Commit e864396

Browse files
committed
Add config print
1 parent 664bf9e commit e864396

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

dpbench/console/_namespace.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class Namespace(argparse.Namespace):
2929
timeout: float
3030
precision: Union[str, None]
3131
program: str
32+
color: str
3233
comparisons: list[str]
3334

3435

dpbench/console/config.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# SPDX-FileCopyrightText: 2022 - 2023 Intel Corporation
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
"""Report subcommand package."""
6+
7+
import argparse
8+
9+
from ._namespace import Namespace
10+
11+
12+
def add_config_arguments(parser: argparse.ArgumentParser):
13+
"""Add arguments for the config subcommand.
14+
15+
Args:
16+
parser: argument parser where arguments will be populated.
17+
"""
18+
parser.add_argument(
19+
"--color",
20+
action=argparse.BooleanOptionalAction,
21+
default=True,
22+
help="Set if print with color.",
23+
)
24+
pass
25+
26+
27+
def execute_config(args: Namespace):
28+
"""Execute config sub command.
29+
30+
Print loaded configuration in pretty format
31+
32+
Args:
33+
args: object with all input arguments.
34+
conn: database connection.
35+
"""
36+
import dpbench.config as cfg
37+
38+
cfg.GLOBAL = cfg.read_configs(
39+
benchmarks=args.benchmarks,
40+
implementations=args.implementations,
41+
with_npbench=True,
42+
with_polybench=True,
43+
)
44+
45+
if args.color:
46+
from pprint import pformat
47+
48+
from pygments import highlight
49+
from pygments.formatters import Terminal256Formatter
50+
from pygments.lexers import PythonLexer
51+
52+
print(
53+
highlight(
54+
pformat(cfg.GLOBAL), PythonLexer(), Terminal256Formatter()
55+
),
56+
end="",
57+
)
58+
else:
59+
from pprint import pprint
60+
61+
pprint(cfg.GLOBAL)

dpbench/console/entry.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from importlib.metadata import version
99

1010
from ._namespace import CommaSeparateStringAction, Namespace
11+
from .config import add_config_arguments, execute_config
1112
from .report import add_report_arguments, execute_report
1213
from .run import add_run_arguments, execute_run
1314

@@ -85,6 +86,13 @@ def parse_args() -> Namespace:
8586

8687
add_report_arguments(report_parser)
8788

89+
config_parser = subparsers.add_parser(
90+
"config",
91+
description="Subcommand to print config.",
92+
)
93+
94+
add_config_arguments(config_parser)
95+
8896
return parser.parse_args(namespace=Namespace())
8997

9098

@@ -110,6 +118,8 @@ def main():
110118
execute_run(args, conn)
111119
elif args.program == "report":
112120
execute_report(args, conn)
121+
elif args.program == "config":
122+
execute_config(args)
113123

114124

115125
if __name__ == "__main__":

0 commit comments

Comments
 (0)