2424
2525
2626import argparse
27+ import io
2728import os
2829import sys
30+ from pathlib import Path
31+
32+ from ruamel .yaml import YAML
2933
3034
3135class FormatSource (argparse .Action ):
@@ -64,6 +68,23 @@ def __call__(self, parser, namespace, values, option_string=None):
6468 exit (0 )
6569
6670
71+ class FormatYAML (argparse .Action ):
72+ def __call__ (self , parser , namespace , values , option_string = None ):
73+ yaml = YAML ()
74+ yaml .preserve_quotes = True
75+ yaml .width = 120
76+ yaml .indent (mapping = 2 , sequence = 4 , offset = 2 )
77+ counter_defs = (
78+ Path (os .path .dirname (__file__ ))
79+ / "../../source/share/rocprofiler-sdk/counter_defs.yaml"
80+ ).resolve ()
81+ data = yaml .load (counter_defs .read_text ())
82+ stream = io .StringIO ()
83+ yaml .dump (data , stream )
84+ counter_defs .write_text (stream .getvalue ())
85+ exit (0 )
86+
87+
6788class FormatAll (argparse .Action ):
6889 def __call__ (self , parser , namespace , values , option_string = None ):
6990 os .system (
@@ -87,6 +108,7 @@ def __call__(self, parser, namespace, values, option_string=None):
87108 + "/../../external/*\" | egrep 'CMakeLists.txt|\.cmake$')"
88109 )
89110 os .system ("black " + os .path .dirname (__file__ ) + "/../.." )
111+ FormatYAML .__call__ (FormatYAML , parser , namespace , values , option_string )
90112 exit (0 )
91113
92114
@@ -118,6 +140,9 @@ def __call__(self, parser, namespace, values, option_string=None):
118140 "-p" , "--python" , nargs = 0 , help = "format python files" , action = FormatPython
119141)
120142parser .add_argument (
121- "-a" , "--all" , nargs = 0 , help = "format cmake, source and python files" , action = FormatAll
143+ "-cd" , "--counter-defs" , nargs = 0 , help = "format counter_defs.yaml" , action = FormatYAML
144+ )
145+ parser .add_argument (
146+ "-a" , "--all" , nargs = 0 , help = "format cmake, source, python, and yaml files" , action = FormatAll
122147)
123148parser .parse_args ()
0 commit comments