66
77
88class Validate :
9- """ Static class containing methods for validating various fields """
9+ """Static class containing methods for validating various fields"""
1010
1111 @staticmethod
1212 def filepath (path : str ) -> bool :
13- filepath_re = re .compile (
14- r"[a-zA-Z0-9\/\._\-]+"
15- )
13+ filepath_re = re .compile (r"[a-zA-Z0-9\/\._\-]+" )
1614 return filepath_re .match (path ) is not None
1715
1816 @staticmethod
19- # TODO use config
17+ # TODO use config
2018 def timestamp (t : str ) -> bool :
2119 timestamp_re = re .compile (
2220 # YYYYMMDD_HHMMSS
@@ -27,8 +25,8 @@ def timestamp(t: str) -> bool:
2725 @staticmethod
2826 def sanitize_stat (stat : str ) -> float :
2927 """
30- Sanitize statistics found in compute-benchmark output csv files. Returns float if sanitized, None if not sanitizable
31- """
28+ Sanitize statistics found in compute-benchmark output csv files. Returns float if sanitized, None if not sanitizable
29+ """
3230 # Get rid of %
3331 if stat [- 1 ] == "%" :
3432 stat = stat [:- 1 ]
@@ -47,6 +45,7 @@ class SanitizedConfig:
4745 Configuration option names follow <section name>_<option name> from config
4846 file.
4947 """
48+
5049 loaded : bool = False
5150 # PERF_RES_PATH: str = None
5251 # ARTIFACT_OUTPUT_CACHE: str = None
@@ -69,20 +68,23 @@ class Configuration:
6968
7069 def __init__ (self , devops_path : str ):
7170 """
72- Initialize this configuration handler by finding configuration files
71+ Initialize this configuration handler by finding configuration files
7372
7473 @param devops_path Path to /devops folder in intel/llvm
7574 """
7675 self .config_path = f"{ devops_path } /benchmarking/config.ini"
7776 self .constants_path = f"{ devops_path } /benchmarking/constants.ini"
7877
7978 if not os .path .isfile (self .config_path ):
80- print (f"config.ini not found in { devops_path } /benchmarking." ,
81- file = sys .stderr )
79+ print (
80+ f"config.ini not found in { devops_path } /benchmarking." , file = sys .stderr
81+ )
8282 exit (1 )
8383 if not os .path .isfile (self .constants_path ):
84- print (f"constants.ini not found in { devops_path } /benchmarking." ,
85- file = sys .stderr )
84+ print (
85+ f"constants.ini not found in { devops_path } /benchmarking." ,
86+ file = sys .stderr ,
87+ )
8688 exit (1 )
8789
8890 def __sanitize (self , value : str , field : str ) -> str :
@@ -91,11 +93,10 @@ def __sanitize(self, value: str, field: str) -> str:
9193 files.
9294 """
9395 _alnum = list (string .ascii_letters + string .digits )
94- allowlist = _alnum + ['_' , '-' , '.' , ',' , ':' , '/' , '%' ]
96+ allowlist = _alnum + ["_" , "-" , "." , "," , ":" , "/" , "%" ]
9597
9698 for illegal_ch in filter (lambda ch : ch not in allowlist , value ):
97- print (f"Illegal character '{ illegal_ch } ' in { field } " ,
98- file = sys .stderr )
99+ print (f"Illegal character '{ illegal_ch } ' in { field } " , file = sys .stderr )
99100 exit (1 )
100101
101102 return value
@@ -114,10 +115,10 @@ def export_var_cmd(sec: str, opt: str) -> str:
114115 var_name = f"SANITIZED_{ sec .upper ()} _{ opt .upper ()} "
115116 var_val = f"{ self .__sanitize (config [sec ][opt ], sec + '.' + opt )} "
116117 return f"{ var_name } ={ var_val } "
117-
118- export_cmds = [ export_var_cmd (sec , opt ) for sec , opt in export_opts ]
118+
119+ export_cmds = [export_var_cmd (sec , opt ) for sec , opt in export_opts ]
119120 return "export " + " " .join (export_cmds )
120-
121+
121122 def export_shell_configs (self ) -> str :
122123 """
123124 Return shell command exporting environment variables representing
@@ -175,30 +176,30 @@ def export_python_globals(self):
175176 # python objects:
176177
177178 # metrics.recorded
178- m_rec_str = \
179- self .__sanitize (all_opts ["metrics" ]["recorded" ], "metrics.recorded" )
179+ m_rec_str = self .__sanitize (all_opts ["metrics" ]["recorded" ], "metrics.recorded" )
180180 SanitizedConfig .METRICS_RECORDED = m_rec_str .split ("," )
181181
182182 # metrics.tolerances
183- m_tol_str = \
184- self .__sanitize (all_opts ["metrics" ]["tolerances" ],
185- "metrics.tolerances" )
186- metric_tolerances = \
187- dict ([ pair_str .split (":" ) for pair_str in m_tol_str .split ("," ) ])
183+ m_tol_str = self .__sanitize (
184+ all_opts ["metrics" ]["tolerances" ], "metrics.tolerances"
185+ )
186+ metric_tolerances = dict (
187+ [pair_str .split (":" ) for pair_str in m_tol_str .split ("," )]
188+ )
188189
189190 for metric , tolerance_str in metric_tolerances .items ():
190191 if metric not in SanitizedConfig .METRICS_RECORDED :
191- print (f"Metric compared against { metric } is not being recorded." ,
192- file = sys .stderr )
192+ print (
193+ f"Metric compared against { metric } is not being recorded." ,
194+ file = sys .stderr ,
195+ )
193196 exit (1 )
194197 try :
195198 metric_tolerances [metric ] = float (tolerance_str )
196199 except ValueError :
197- print (f"Could not convert '{ tolerance_str } ' to float." ,
198- file = sys .stderr )
200+ print (f"Could not convert '{ tolerance_str } ' to float." , file = sys .stderr )
199201 exit (1 )
200202
201203 SanitizedConfig .METRICS_TOLERANCES = metric_tolerances
202204
203205 SanitizedConfig .loaded = True
204-
0 commit comments