From dee9180df32eae679c1ebb155fd471e7b25ae20a Mon Sep 17 00:00:00 2001 From: TheHedgeify Date: Tue, 21 Apr 2026 12:33:48 +0200 Subject: [PATCH 1/2] wrap yaml into main to avoid it auto-running on validate through the import --- yaml_to_html.py | 113 +++++++++++++++++++++++++++--------------------- 1 file changed, 64 insertions(+), 49 deletions(-) diff --git a/yaml_to_html.py b/yaml_to_html.py index a9a219f..eb47125 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 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) From 5fe6a4e6e069eda8dbd0200eabd0d5191e439782 Mon Sep 17 00:00:00 2001 From: Vanessa <3634850+CIGbalance@users.noreply.github.com> Date: Tue, 21 Apr 2026 12:37:31 +0200 Subject: [PATCH 2/2] Update yaml_to_html.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- yaml_to_html.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yaml_to_html.py b/yaml_to_html.py index eb47125..164bd1c 100755 --- a/yaml_to_html.py +++ b/yaml_to_html.py @@ -89,6 +89,6 @@ def repl(m): # 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) + for path in [html_header, html_table, html_scripts, html_footer]: + with open(path, "rb") as src: + shutil.copyfileobj(src, output_file)