From 2ebd0cfab9f7c00d4ed8bc10535df467a3ecf57c Mon Sep 17 00:00:00 2001 From: Jacques Heunis Date: Fri, 29 Jul 2022 13:44:46 +0100 Subject: [PATCH] Fix compile process for python3 on Windows As it stands python3 will fail to read in the input xhtml files because they contain bytes that are not valid using the default codepage on Windows (in English at least). Loading those files as utf-8 explicitly resolves this issue and is correct as long as all the xhtml files are utf-8 encoded. --- compile.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/compile.py b/compile.py index 5484387b..43281a95 100644 --- a/compile.py +++ b/compile.py @@ -5,6 +5,7 @@ import argparse import re import zipfile +import codecs import opengl import glsl @@ -824,9 +825,8 @@ def spew_category(name, commands, current_command, api): if command_file == False: raise IOError("Couldn't find page for command " + command + " (" + version + ")") - fp = open(command_file) - command_html = fp.read() - fp.close() + with codecs.open(command_file, mode="r", encoding="utf-8") as fp: + command_html = fp.read() if args.buildmode == 'full': command_html = command_html @@ -942,12 +942,12 @@ def replace_alias(matchobj): output_html = header_for_command + command_html + footer_for_command - output = open(output_dir + version_dir + "/" + command, "w") - output_string = output_html - if args.buildmode == 'full': - output_string = htmlmin.minify(output_html, remove_comments=True, reduce_boolean_attributes=True, remove_optional_attribute_quotes=False).encode('ascii', 'xmlcharrefreplace').decode('ascii') - output.write(output_string) - output.close() + output_path = output_dir + version_dir + "/" + command + with codecs.open(output_path, mode="w", encoding="utf-8") as output: + output_string = output_html + if args.buildmode == 'full': + output_string = htmlmin.minify(output_html, remove_comments=True, reduce_boolean_attributes=True, remove_optional_attribute_quotes=False).encode('ascii', 'xmlcharrefreplace').decode('ascii') + output.write(output_string) written += 1