diff --git a/yaml_to_html.py b/yaml_to_html.py
index a9a219f..164bd1c 100755
--- a/yaml_to_html.py
+++ b/yaml_to_html.py
@@ -15,11 +15,14 @@ def linkify_cell(value):
def repl(m):
url = m.group(1)
- href = url if url.lower().startswith(("http://", "https://")) else f"https://{url}"
+ href = (
+ url if url.lower().startswith(("http://", "https://")) else f"https://{url}"
+ )
return f'{url}'
return URL_RE.sub(repl, value)
+
yaml_file = "problems.yaml"
html_dir = "docs/"
@@ -29,51 +32,63 @@ def repl(m):
html_footer = f"{html_dir}footer.html"
html_index = f"{html_dir}index.html"
-# Load data
-with open(yaml_file) as in_file:
- data = pd.json_normalize(yaml.safe_load(in_file))
-
-# Choose desired columns
-all_columns = False
-default_columns = ["name",
- "textual description",
- "suite/generator/single",
- "objectives",
- "dimensionality",
- "variable type",
- "constraints",
- "dynamic",
- "noise",
- "multi-fidelity",
- "source (real-world/artificial)",
- "reference",
- "implementation"]
-
-if all_columns is False:
- columns = default_columns
- data = data[columns]
-
-data = data.map(linkify_cell)
-
-# Generate plain table
-table = data.to_html(render_links=False,
- escape=False, # Don't escape HTML in cells (to allow links)
- index=False,
- table_id="problems",
- classes=["display compact", "display", "styled-table"], # Set display style
- border=0,
- na_rep="") # Leave NaN cells empty
-
-# Add footer to facilitate individual column search
-idx = table.index('')
-final_table = table[:idx] + "
" + " ".join(["| "+ i +" | " for i in data.columns])+"
" + table[idx:]
-
-# Write table to file
-with open(html_table, "w") as table_file:
- table_file.write(final_table)
-
-# Merge table and scripts into HTML page
-with open(html_index, "wb") as output_file:
- for in_file in [html_header, html_table, html_scripts, html_footer]:
- with open(in_file, "rb") as in_file:
- shutil.copyfileobj(in_file, output_file)
+default_columns = [
+ "name",
+ "textual description",
+ "suite/generator/single",
+ "objectives",
+ "dimensionality",
+ "variable type",
+ "constraints",
+ "dynamic",
+ "noise",
+ "multi-fidelity",
+ "source (real-world/artificial)",
+ "reference",
+ "implementation",
+]
+
+if __name__ == "__main__":
+ # Load data
+ with open(yaml_file) as in_file:
+ data = pd.json_normalize(yaml.safe_load(in_file))
+
+ # Choose desired columns
+ all_columns = False
+
+ if all_columns is False:
+ columns = default_columns
+ data = data[columns]
+
+ data = data.map(linkify_cell)
+
+ # Generate plain table
+ table = data.to_html(
+ render_links=False,
+ escape=False, # Don't escape HTML in cells (to allow links)
+ index=False,
+ table_id="problems",
+ classes=["display compact", "display", "styled-table"], # Set display style
+ border=0,
+ na_rep="",
+ ) # Leave NaN cells empty
+
+ # Add footer to facilitate individual column search
+ idx = table.index("")
+ final_table = (
+ table[:idx]
+ + ""
+ + " ".join(["| " + i + " | " for i in data.columns])
+ + "
"
+ + table[idx:]
+ )
+
+ # Write table to file
+ with open(html_table, "w") as table_file:
+ table_file.write(final_table)
+
+ # Merge table and scripts into HTML page
+ with open(html_index, "wb") as output_file:
+ for path in [html_header, html_table, html_scripts, html_footer]:
+ with open(path, "rb") as src:
+ shutil.copyfileobj(src, output_file)