-
Notifications
You must be signed in to change notification settings - Fork 4
wrap yaml into main to avoid it auto-running on validate through the import #163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
dee9180
5fe6a4e
5610936
153f394
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -16,11 +16,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'<a href="{href}">{url}</a>' | ||||||
|
|
||||||
| return URL_RE.sub(repl, value) | ||||||
|
|
||||||
|
|
||||||
| yaml_file = "problems.yaml" | ||||||
|
|
||||||
| html_dir = "docs/" | ||||||
|
|
@@ -31,9 +34,6 @@ def repl(m): | |||||
| html_index = f"{html_dir}index.html" | ||||||
| html_table_template = f"{html_dir}table_template.html" | ||||||
|
|
||||||
| # Load data | ||||||
| with open(yaml_file) as yaml_input: | ||||||
| data = pd.json_normalize(yaml.safe_load(yaml_input)) | ||||||
|
|
||||||
| # Choose desired columns | ||||||
| all_columns = False | ||||||
|
|
@@ -51,55 +51,61 @@ def repl(m): | |||||
| "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('</table>') | ||||||
| final_table = table[:idx] + "<tfoot><tr>" + " ".join(["<th>"+ i +"</th>" for i in data.columns])+"</tr> </tfoot>" + table[idx:] | ||||||
|
|
||||||
| default_hidden_columns = {"textual description", "reference", "implementation"} | ||||||
|
|
||||||
| column_toggles = "".join( | ||||||
| [ | ||||||
| ( | ||||||
| f'<label class="column-chip">' | ||||||
| f'<input class="col-toggle" type="checkbox" data-column="{i}"' | ||||||
| f'{" checked" if col not in default_hidden_columns else ""}>' | ||||||
| f'<span>{escape(col)}</span>' | ||||||
| f'</label>' | ||||||
| ) | ||||||
| for i, col in enumerate(data.columns) | ||||||
| ] | ||||||
| ) | ||||||
|
|
||||||
| with open(html_table_template, encoding="utf-8") as template_file: | ||||||
| table_template = template_file.read() | ||||||
|
|
||||||
| table_markup = ( | ||||||
| table_template | ||||||
| .replace("__COLUMN_TOGGLES__", column_toggles) | ||||||
| .replace("__TABLE__", final_table) | ||||||
| ) | ||||||
|
|
||||||
| # Write table to file | ||||||
| with open(html_table, "w", encoding="utf-8") as table_file: | ||||||
| table_file.write(table_markup) | ||||||
|
|
||||||
| # Merge table and scripts into HTML page | ||||||
| with open(html_index, "wb") as output_file: | ||||||
| for part_path in [html_header, html_table, html_scripts, html_footer]: | ||||||
| with open(part_path, "rb") as part_file: | ||||||
| shutil.copyfileobj(part_file, output_file) | ||||||
| if __name__ == "__main__": | ||||||
| # Load data | ||||||
| with open(yaml_file) as yaml_input: | ||||||
| data = pd.json_normalize(yaml.safe_load(yaml_input)) | ||||||
|
|
||||||
|
|
||||||
|
Comment on lines
+58
to
+59
|
||||||
Copilot
AI
Apr 22, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Within this block, if all_columns is False: is a non-idiomatic boolean check and reduces readability. Prefer if not all_columns: (or just if all_columns: where appropriate) for consistency with typical Python style.
| if all_columns is False: | |
| if not all_columns: |
Uh oh!
There was an error while loading. Please reload this page.