Skip to content

Commit f90e0ed

Browse files
committed
Commit to solve suggestions from latest pull request on main branch.
1 parent 21de1e8 commit f90e0ed

File tree

5 files changed

+114
-74
lines changed

5 files changed

+114
-74
lines changed

RunTests.py

+33-27
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def check_reference_file(common_funcs, test_webpage, test_variables, debug):
100100
common_funcs.add_entry(test_webpage, "#FF00FF", "", "Reference file does not exist")
101101
ret = 1
102102
if debug:
103-
print(f"Return value after check_reference_file: {ret}")
103+
common_funcs.logger.info(f"Return value after check_reference_file: {ret}")
104104
return ret
105105

106106
def run_wcsim(variables, common_funcs, test_webpage, debug):
@@ -121,13 +121,13 @@ def run_wcsim(variables, common_funcs, test_webpage, debug):
121121
subprocess.CalledProcessError: If the subprocess call to run WCSim fails.
122122
'''
123123
try:
124-
wcsim_exit = subprocess.run(["/usr/bin/time", "-p", "--output=timetest", f"{common_funcs.ValidationPath}/{variables['ScriptName']}", f"{common_funcs.ValidationPath}/Generate/macReference/{variables['WCSimMacName']}", f"{variables['FileTag']}.root"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, check=True)
124+
wcsim_exit = common_funcs.run_command(["/usr/bin/time", "-p", "--output=timetest", f"{common_funcs.ValidationPath}/{variables['ScriptName']}", f"{common_funcs.ValidationPath}/Generate/macReference/{variables['WCSimMacName']}", f"{variables['FileTag']}.root"])
125125

126126
# Write the command and its output to a log file
127127
with open('wcsim_run.out', 'w') as logfile:
128128
logfile.write(wcsim_exit.stdout.decode())
129129

130-
print(wcsim_exit.stdout.decode())
130+
common_funcs.logger.info(wcsim_exit.stdout.decode())
131131

132132
# Parse the timing information
133133
with open("timetest", "r") as timetest_file:
@@ -138,7 +138,7 @@ def run_wcsim(variables, common_funcs, test_webpage, debug):
138138

139139
common_funcs.add_entry(test_webpage, "#00FF00", "", time)
140140
if debug:
141-
print(f"Return value after wcsim_exit: 0")
141+
common_funcs.logger.info(f"Return value after wcsim_exit: 0")
142142
return 0
143143

144144
except subprocess.CalledProcessError as e:
@@ -181,7 +181,7 @@ def compare_root_files(common_funcs, test_webpage, test_dir, variables, test_num
181181
if not os.path.isdir(f"{test_dir}/{isubjob}"):
182182
os.mkdir(f"{test_dir}/{isubjob}")
183183
compare_exit_status = os.system(f"{common_funcs.ValidationPath}/Compare/compareroot {common_funcs.ValidationPath}/Webpage/{common_funcs.GIT_COMMIT}/{test_num}/{isubjob} {root_filename} {common_funcs.ValidationPath}/Compare/Reference/{root_filename}")
184-
print('compare_exit_status', compare_exit_status, type(compare_exit_status))
184+
common_funcs.logger.info('compare_exit_status', compare_exit_status, type(compare_exit_status))
185185
if compare_exit_status != 0:
186186
common_funcs.add_entry(test_webpage, "#FF0000", link, f"Failed {pmttype} plot comparisons")
187187
ret = 1
@@ -190,13 +190,13 @@ def compare_root_files(common_funcs, test_webpage, test_dir, variables, test_num
190190
else:
191191
common_funcs.add_entry(test_webpage, "#000000", "", f"No {pmttype} in geometry")
192192

193-
print('wcsim_has_output, ret after loop over diffing root files', wcsim_has_output, ret)
193+
common_funcs.logger.info('wcsim_has_output, ret after loop over diffing root files', wcsim_has_output, ret)
194194
if wcsim_has_output == 0:
195195
ret = 1
196196
except Exception as e:
197197
raise Exception(f"Unxpected error occured when comparing the root files: {e}")
198198
if debug:
199-
print(f"Return value after compare_root_files: {ret}")
199+
common_funcs.logger.info(f"Return value after compare_root_files: {ret}")
200200
return ret
201201

202202
def compare_geofile(common_funcs, test_webpage, variables, test_num, debug):
@@ -228,7 +228,7 @@ def compare_geofile(common_funcs, test_webpage, variables, test_num, debug):
228228
except Exception as e:
229229
raise Exception(f"Unexpected error occured when comparing the geometry files: {e}")
230230
if debug:
231-
print(f"Return value after compare_geofile: {ret}")
231+
common_funcs.logger.info(f"Return value after compare_geofile: {ret}")
232232
return ret
233233

234234
def compare_badfile(common_funcs, test_webpage, variables, test_num, debug):
@@ -280,7 +280,7 @@ def compare_badfile(common_funcs, test_webpage, variables, test_num, debug):
280280
except Exception as e:
281281
raise Exception(f"Unexpected error when comparing bad files: {e}")
282282
if debug:
283-
print(f"Return value after compare_badfile: {ret}")
283+
common_funcs.logger.info(f"Return value after compare_badfile: {ret}")
284284
return ret
285285

286286
def check_impossible_geometry(common_funcs, test_webpage, variables, test_num, debug):
@@ -322,9 +322,9 @@ def check_impossible_geometry(common_funcs, test_webpage, variables, test_num, d
322322

323323
if os.path.getsize(impossiblefilename) > 0:
324324
common_funcs.add_entry(test_webpage, "#FF0000", f"<a href='{impossiblefilename}'>", "Geometry warnings exist")
325-
print("Geometry warnings exist:")
325+
common_funcs.logger.info("Geometry warnings exist:")
326326
with open(impossiblefilename, "r") as impossible_file:
327-
print(impossible_file.read())
327+
common_funcs.logger.info(impossible_file.read())
328328
os.system(f"mv {impossiblefilename} {common_funcs.ValidationPath}/Webpage/{common_funcs.GIT_COMMIT}/{test_num}/")
329329
ret = 1
330330
else:
@@ -334,7 +334,7 @@ def check_impossible_geometry(common_funcs, test_webpage, variables, test_num, d
334334
except Exception as e:
335335
raise Exception(f"Unexpected error occurred when checking impossible geometry: {e}")
336336
if debug:
337-
print(f"Return value after check_impossible_geometry: {ret}")
337+
common_funcs.logger.info(f"Return value after check_impossible_geometry: {ret}")
338338
return ret
339339

340340
def main():
@@ -348,12 +348,27 @@ def main():
348348
logger = common_funcs.logger
349349
test_dir = f"{common_funcs.ValidationPath}/Webpage/{common_funcs.GIT_COMMIT}/{args.test_num}"
350350

351+
#Check if the test number is correct, kill if not.
352+
353+
with open(os.path.join(common_funcs.ValidationPath, 'tests.json'), 'r') as json_file:
354+
data = json.load(json_file)
355+
356+
values = data[f'Test{args.test_num}']
357+
test_name = values['name']
358+
test_type = values['test']
359+
test_variables = {key: value for key, value in values.items() if key not in ['name', 'test']}
360+
361+
362+
363+
common_funcs.logger.info(f"Running test {args.test_num} with name: {test_name} of type: {test_type} with variables: {test_variables}")
364+
365+
351366
# Checkout validation repository
352367
common_funcs.checkout_validation_webpage_branch()
353368

354369
# build the comparison script
355370
try:
356-
subprocess.run(["make"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, check=True)
371+
common_funcs.run_command("make")
357372
except subprocess.CalledProcessError as e:
358373
raise subprocess.CalledProcessError(f"Failed to build the comparison script. Return code: {e.returncode}.\nOutput: {e.output.decode()}")
359374

@@ -372,16 +387,6 @@ def main():
372387
footer_content = create_test_webpage_footer(common_funcs.ValidationPath)
373388
test_webpage = create_test_webpage(test_dir, header_content, GIT_COMMIT_MESSAGE, common_funcs.GIT_COMMIT, common_funcs.GIT_PULL_REQUEST_LINK)
374389

375-
with open(os.path.join(common_funcs.ValidationPath, 'tests.json'), 'r') as json_file:
376-
data = json.load(json_file)
377-
378-
values = data[f'Test{args.test_num}']
379-
test_name = values['name']
380-
test_type = values['test']
381-
test_variables = {key: value for key, value in values.items() if key not in ['name', 'test']}
382-
383-
print(f"Running test {args.test_num} with name: {test_name} of type: {test_type} with variables: {test_variables}")
384-
385390
with open(test_webpage, 'a') as webpage:
386391
webpage.write(f"\n<h3>{test_name}</h3>\n")
387392

@@ -411,12 +416,12 @@ def main():
411416
# Add the footer and...
412417
# Add color code at the bottom for the list of jobs page
413418
if ret == 0:
414-
print("Finishing writing webpage file. Nothing failed!")
419+
common_funcs.logger.info("Finishing writing webpage file. Nothing failed!")
415420
with open(test_webpage, "a") as webpage_file:
416421
webpage_file.write(footer_content)
417422
webpage_file.write("#00FF00\n")
418423
else:
419-
print("Finishing writing webpage file. Something failed!")
424+
common_funcs.logger.info("Finishing writing webpage file. Something failed!")
420425
with open(test_webpage, "a") as webpage_file:
421426
webpage_file.write(footer_content)
422427
webpage_file.write("#FF0000\n")
@@ -427,13 +432,14 @@ def main():
427432
sys.exit(-1)
428433

429434
except FileNotFoundError as e:
430-
logger.error(f"File not found error in RunTests: {e}")
435+
logger.error(f"File not found error in RunTests: {type(e).__name__}: {e}")
431436
sys.exit(1)
432437
except subprocess.CalledProcessError as e:
438+
#Maybe this needs changing?
433439
logger.error(f"Error running subprocess in RunTests: Return code {e.returncode}, Output: {e.output.decode()}")
434440
sys.exit(1)
435441
except Exception as e:
436-
logger.error(f"An unexpected error occurred in RunTests: {e}")
442+
logger.error(f"An unexpected error occurred in RunTests: {type(e).__name__}: {e}")
437443
sys.exit(1)
438444

439445
if __name__ == "__main__":

SetupWebpages.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
from common import CommonWebPageFuncs
66

77
#Putting some things in functions so that the main code doesn't look a mess :)
8-
def update_file(old_path, new_path, content):
8+
def prepend_to_file(old_path, new_path, content):
99
with open(new_path, "w") as f_new:
1010
f_new.write(content)
1111
with open(old_path, "r") as f:
1212
f_new.write(f.read())
1313
os.rename(new_path, old_path)
1414

15-
def build_webpage(header_path, body_path, footer_path, index_path):
15+
def create_main_webpage(header_path, body_path, footer_path, index_path):
1616
with open(index_path, "w") as f_index:
1717
with open(header_path, "r") as f_header:
1818
f_index.write(f_header.read())
@@ -67,17 +67,17 @@ def main():
6767

6868
# Update folderlist
6969
new_folderlist_path = f"{folderlist_path}.new"
70-
update_file(folderlist_path, new_folderlist_path, f"{cw.GIT_COMMIT} \n")
70+
prepend_to_file(folderlist_path, new_folderlist_path, f"{cw.GIT_COMMIT} \n")
7171

7272
# Update body
7373
git_commit_message = f" Pull Request #{cw.GIT_PULL_REQUEST}: {cw.GIT_PULL_REQUEST_TITLE}" if cw.GIT_PULL_REQUEST != "false" else ""
74-
git_pull_request_link = f"<a href=https://github.com/WCSim/WCSim/pull/{cw.GIT_PULL_REQUEST}>"
74+
git_pull_request_link = f"<a href=https://{cw.SOFTWARE_GIT_WEB_PATH}/pull/{cw.GIT_PULL_REQUEST}>"
7575
git_pull_request_link_close = "</a>" if not cw.GIT_PULL_REQUEST.isdigit() else ""
7676
new_body_path = f"{body_path}.new"
77-
update_file(body_path, new_body_path, f"\n<tr> <td><a href='{cw.GIT_COMMIT}/index.html'>{cw.GIT_COMMIT}</td> <td>{git_pull_request_link}{git_commit_message}{git_pull_request_link_close}</td> </tr>\n")
77+
prepend_to_file(body_path, new_body_path, f"\n<tr> <td><a href='{cw.GIT_COMMIT}/index.html'>{cw.GIT_COMMIT}</td> <td>{git_pull_request_link}{git_commit_message}{git_pull_request_link_close}</td> </tr>\n")
7878

7979
# Build webpage
80-
build_webpage(header_path, body_path, footer_path, os.path.join(validation_path, "Webpage", "index.html"))
80+
create_main_webpage(header_path, body_path, footer_path, os.path.join(validation_path, "Webpage", "index.html"))
8181

8282
# Make the test webpage
8383
commit_dir = os.path.join(validation_path, "Webpage", cw.GIT_COMMIT)

build.py

+8-21
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,18 @@
22

33
import os
44
import argparse
5-
import subprocess
6-
import sys
7-
8-
def run_command(command):
9-
try:
10-
subprocess.run(command, shell=True, check=True)
11-
except subprocess.CalledProcessError as e:
12-
print(f"Unexpected error in build: Command '{e.cmd}' returned non-zero exit status {e.returncode}")
13-
sys.exit(1)
14-
15-
def create_directory(directory):
16-
try:
17-
os.makedirs(directory, exist_ok=True)
18-
except OSError as e:
19-
print(f"Unexpected error in build: Failed to create directory '{directory}': {e}")
20-
exit(1)
5+
from common import CommonWebPageFuncs
216

227
def main(option):
8+
9+
cw = CommonWebPageFuncs()
2310
extra_options = ""
2411

2512
if option == 1:
2613
extra_options = "WCSim_Geometry_Overlaps_CHECK=ON"
2714

28-
create_directory("build")
29-
create_directory("install")
15+
cw.create_directory("build")
16+
cw.create_directory("install")
3017
os.chdir("build")
3118

3219
cmake_command = f"cmake -DWCSim_DEBUG_COMPILE_FLAG=ON {extra_options} -DCMAKE_INSTALL_PREFIX=../install/ ../src/"
@@ -35,9 +22,9 @@ def main(option):
3522
make_command += " -j`nproc`"
3623
make_install_command = "make install"
3724

38-
run_command(cmake_command)
39-
run_command(make_command)
40-
run_command(make_install_command)
25+
cw.run_command(cmake_command)
26+
cw.run_command(make_command)
27+
cw.run_command(make_install_command)
4128

4229
if __name__ == "__main__":
4330
parser = argparse.ArgumentParser(description="Build and install script")

0 commit comments

Comments
 (0)