22import json
33import re
44import difflib
5+ import logging
56import os
67import subprocess
8+ from .modeldb import ModelDB
79from pygments import highlight
810from pygments .lexers import DiffLexer
911from pygments .formatters import HtmlFormatter
1012
13+ mdb = ModelDB ()
1114
12- def curate_run_data (run_data ):
15+ def curate_run_data (run_data , model = None ):
1316 curated_data = run_data
1417
1518 regex_dict = {
@@ -19,10 +22,22 @@ def curate_run_data(run_data):
1922 # nrniv: unable to open font "*helvetica-medium-r-normal*--14*", using "fixed" <-> special: unableto open font "*helvetica-medium-r-normal*--14*", using "fixed"
2023 "^nrniv:" : "%neuron-executable%:" ,
2124 "^special:" : "%neuron-executable%:" ,
25+ "(Mon|Tue|Wed|Thu|Fri|Sat|Sun) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \d+ \d+:\d+:\d+ [A-Z]+ \d+" : "%date_command%" ,
26+ "total run time [0-9\.]+" : "total run time %run_time%" ,
2227 }
2328
29+ for model_specific_substitution in mdb .run_instr .get (model , {}).get ("curate_patterns" , []):
30+ regex_dict [model_specific_substitution ["pattern" ]] = model_specific_substitution ["repl" ]
31+
2432 for regex_key , regex_value in regex_dict .items ():
25- curated_data = [re .sub (regex_key , regex_value , line ) for line in curated_data ]
33+ updated_data = []
34+ for line in curated_data :
35+ new_line , number_of_subs = re .subn (regex_key , regex_value , line )
36+ if number_of_subs :
37+ logging .debug ("{} matched {} time(s)" .format (regex_key , number_of_subs ))
38+ logging .debug ("{} -> {}" .format (line , new_line ))
39+ updated_data .append (new_line )
40+ curated_data = updated_data
2641
2742 return curated_data
2843
@@ -41,8 +56,8 @@ def diff_reports(report1_json, report2_json):
4156 for k in data_a .keys ():
4257 if int (k ) == 0 :
4358 continue # skip info key
44- curated_a = curate_run_data (data_a [k ]["nrn_run" ])
45- curated_b = curate_run_data (data_b [k ]["nrn_run" ])
59+ curated_a = curate_run_data (data_a [k ]["nrn_run" ], model = int ( k ) )
60+ curated_b = curate_run_data (data_b [k ]["nrn_run" ], model = int ( k ) )
4661 if curated_a != curated_b :
4762 diff_dict [k ] = hd .make_table (curated_a , curated_b , context = True ).replace ("\n " , " " )
4863 if "do_not_run" not in data_a [k ]:
0 commit comments