@@ -1571,7 +1571,8 @@ def run_python_unittests(python_binary, args=None, paths=None, exclude=None, env
15711571 reportfile = None
15721572 t0 = time .time ()
15731573 if report :
1574- reportfile = os .path .abspath (tempfile .mktemp (prefix = "test-report-" , suffix = ".json" ))
1574+ with tempfile .NamedTemporaryFile (prefix = "test-report-" , suffix = ".json" , delete = False ) as report_tmp :
1575+ reportfile = os .path .abspath (report_tmp .name )
15751576 args += ["--mx-report" , reportfile ]
15761577
15771578 if paths is not None :
@@ -2582,8 +2583,8 @@ def python_checkcopyrights(args):
25822583 files = args [i + 1 :]
25832584 args = args [:i ]
25842585 # we wan't to ignore lib-python/3, because that's just crazy
2585- listfilename = tempfile .mktemp ()
2586- with open ( listfilename , "w" ) as listfile :
2586+ with tempfile .NamedTemporaryFile ( "w" , delete = False ) as listfile :
2587+ listfilename = listfile . name
25872588 if files is None :
25882589 mx .run (["git" , "ls-tree" , "-r" , "HEAD" , "--name-only" ], out = listfile )
25892590 else :
@@ -3299,15 +3300,26 @@ def run_mx(args, *splat, **kwargs):
32993300 return mx .run_mx (args , * splat , ** kwargs )
33003301
33013302
3303+ def _parse_host_inlining_fields (fields ):
3304+ parts = fields .split (":" )
3305+ if len (parts ) > 3 :
3306+ raise ValueError ("fields must be an integer index or slice" )
3307+ result = int (fields ) if len (parts ) == 1 else slice (* (int (part ) if part .strip () else None for part in parts ))
3308+ if isinstance (result , slice ) and result .step == 0 :
3309+ raise ValueError ("fields must be an integer index or slice" )
3310+ return result
3311+
3312+
33023313def host_inlining_log_extract_method (args_in ):
33033314 parser = ArgumentParser (description = "Extracts single method from host inlining log file. "
33043315 "Result, when saved to file, can be visualized with: java scripts/HostInliningVisualizer.java filename" )
33053316 parser .add_argument ("filename" , help = "file with host inlining log" )
33063317 parser .add_argument ("method" , help = "name of a method to extract" )
3307- parser .add_argument ("-f" , "--fields" ,
3318+ parser .add_argument ("-f" , "--fields" , type = _parse_host_inlining_fields ,
33083319 help = "fields to select from the list with details, use Python subscript syntax, "
33093320 "default: '-1:' (i.e., the last field: reason for the [non-]inlining decision)" , default = "-1:" )
33103321 args = parser .parse_args (args_in )
3322+ fields = args .fields
33113323
33123324 start = 'Context: HostedMethod<' + args .method + ' '
33133325 result = []
@@ -3326,7 +3338,8 @@ def host_inlining_log_extract_method(args_in):
33263338 match = re .search (r'\[inlined.*\]' , line )
33273339 if match :
33283340 details = match .group ().split (',' )
3329- details = ', ' .join (eval (f"details[{ args .fields } ]" )) #pylint: disable=eval-used
3341+ selected_details = details [fields ]
3342+ details = ', ' .join ([selected_details ] if isinstance (fields , int ) else selected_details )
33303343 line = line [:match .start ()].rstrip () + f' [{ details } ]'
33313344 for x in remove :
33323345 line = line .replace (x , '' )
0 commit comments