diff --git a/about.py b/about.py index ee6de309d963d567cb15ab6bb6a24675a3fab612..2545e3cdbdb7033824ab0809d40b2123feaa6e93 100644 --- a/about.py +++ b/about.py @@ -10,7 +10,9 @@ Created 16-08-2017 by Josh Borrow (joshua.borrow@durham.ac.uk) """ -import os +#Disable errors associated with un-overwritten methods in HTMLParser. +#pylint: disable=W0223 + from html.parser import HTMLParser import pypandoc @@ -19,8 +21,8 @@ import yaml def open_meta(filename="about_meta.yaml", data_dir="../data"): """ Read the meta file and return the associated data """ - with open(f"{data_dir}/{filename}", "r") as f: - return yaml.load(f) + with open(f"{data_dir}/{filename}", "r") as handle: + return yaml.load(handle) def compile_markdown(data, data_dir="../data"): @@ -29,8 +31,8 @@ def compile_markdown(data, data_dir="../data"): output_text = "" for item in data["files"]: - with open(f"{data_dir}/{item['name']}", "r") as f: - input_text = f.read() + with open(f"{data_dir}/{item['name']}", "r") as handle: + input_text = handle.read() compiled_text = pypandoc.convert_text(input_text, 'html', format='md') @@ -39,6 +41,7 @@ def compile_markdown(data, data_dir="../data"): class Parser(HTMLParser): + """ Custom HTML Parser that builds the headings tree """ def __init__(self): super(Parser, self).__init__() @@ -58,7 +61,7 @@ class Parser(HTMLParser): self.headings.append([tag, this_id]) self.waiting_for_data = True - + def handle_endtag(self, tag): pass @@ -117,18 +120,18 @@ def compile_to_yaml(in_filename="about_meta.yaml", out_filename="about.yaml", da "sidebar": sidebar } - with open(f"{data_dir}/{out_filename}", "w") as f: - yaml.dump(output_data, f) + with open(f"{data_dir}/{out_filename}", "w") as handle: + yaml.dump(output_data, handle) return output_data if __name__ == "__main__": print("Running this script directly will only compile the markdown in data.") print("If you wish to continue, please enter Y, if not, please enter N.") - - choice = input() - if choice in ['y', 'Y']: + CHOICE = input() + + if CHOICE in ['y', 'Y']: compile_to_yaml() else: exit(0) diff --git a/compiler.py b/compiler.py index ffc31606588a2e85b29212ab283cabb43f686a59..f5d4cc928eaec747dcb631dc412ca81200c20476 100644 --- a/compiler.py +++ b/compiler.py @@ -1,6 +1,6 @@ """ Short compilation script from the website (essentially just stitches together a bunch of jinja templates) - + Created 16-08-2017 by Josh Borrow (joshua.borrow@durham.ac.uk) """ @@ -37,8 +37,8 @@ def get_associated_data(template_names, data_dir="../data"): filename = f"{data_dir}/{stub}.yaml" try: - with open(filename, "r") as f: - data.append(yaml.load(f)) + with open(filename, "r") as handle: + data.append(yaml.load(handle)) except FileNotFoundError: data.append({}) @@ -85,8 +85,8 @@ def global_variables(active, data_dir="../data"): Active is the name of the current page's template and is used in the production of the processed navbar. """ - with open("{}/global.yaml".format(data_dir), "r") as f: - raw = yaml.load(f) # We need to process the navbar. + with open("{}/global.yaml".format(data_dir), "r") as handle: + raw = yaml.load(handle) # We need to process the navbar. return process_navbar(raw, active) @@ -102,8 +102,8 @@ def render(render_pages, data_dir, template_dir, output_dir): os.makedirs(output_dir) for page, data in zip(render_pages, output): - with open("{}/{}".format(output_dir, page), "w") as f: - f.write(data) + with open("{}/{}".format(output_dir, page), "w") as handle: + handle.write(data) return