Source code for schrodinger.application.jaguar.check_headers

[docs]def format(str): str = str.replace(" ", "") str = str.replace("\t", "") str = str.replace("\n", "") return str
[docs]def unwrap_lines(lines): """ The header files are generated with line wrapping, but here we assume that only the comment fields (demarked by */ ... /*) are in practice wrapped. This function then concatenates separate lines belonging to the same comment into a single line. """ lines_unwrap = [] flag = 0 long_line = "" for line in lines: if "/*" in line: if "*/" in line: # comment line ends in a single line lines_unwrap.append(format(line)) flag = 0 else: # comment line continues onto additional lines flag = 1 long_line = line else: if flag == 0: # assume this is a complete line (no comment to wrap) lines_unwrap.append(format(line)) else: # expecting update from wrapped line long_line = long_line + line if "*/" in line: lines_unwrap.append(format(long_line)) long_line = "" flag = 0 return lines_unwrap
[docs]def strip_lines(lines): lines_strip = [] for line in lines: if line: lines_strip.append(line) return lines_strip
#-----------------------------------------------------------------------------
[docs]def main(): """ Check auto-generated header files against reference files with a .ref subscript """ for header in [ "mmjag_keywords.h", "mmjag_default.h", "mmjag_mopac_keywords.h", "mmjag_mopac_default.h" ]: print("Checking header: ", header) # Auto-generated header file new_header = header new_file = open(new_header, "r") # Reference header file ref_header = header + ".ref" ref_file = open(ref_header, "r") new_lines = new_file.readlines() ref_lines = ref_file.readlines() print(("%s %d lines.") % (ref_header, len(ref_lines))) print(("%s %d lines.") % (new_header, len(new_lines))) print("Unwrapping and removing blank lines...") # Unwrap wrapped lines ref_unwrapped = unwrap_lines(ref_lines) new_unwrapped = unwrap_lines(new_lines) # Remove blank lines ref_unwrapped = strip_lines(ref_unwrapped) new_unwrapped = strip_lines(new_unwrapped) print(("%s %d lines.") % (ref_header, len(ref_unwrapped))) print(("%s %d lines.") % (new_header, len(new_unwrapped))) print("Searching for differences...\n") for i, new_line in enumerate(new_unwrapped): try: ref_line = ref_unwrapped[i] except IndexError: print("Headers have different lengths") raise if new_line != ref_line: print(new_line) print(ref_line) raise ValueError( "Headers differ beyond whitespace and wrapping") print("All checks OK!")