Commit 45b8f4952d
45b8f4952dfa2ad7ce01a203ecca2e64deb6e53e
parent: 37ae034013
Unsigned
cmc <hello@cleberg.net> · 2025-06-04 15:47 UTC
feat(lint): added ruff.toml to automate linting and formatting
Layout: unified · split
build.py
+35 −4
| @@ -1,11 +1,36 @@ |
| 1 | 1 | #!/usr/bin/env python3 |
| 2 | """ |
| 3 | This script automates the process of building, testing, and deploying the website. |
| 4 | It handles tasks such as: |
| 5 | |
| 6 | - Removing and recreating the build directory. |
| 7 | - Minifying CSS assets. |
| 8 | - Running the Emacs publishing script to generate site content. |
| 9 | - Updating the index.html file with the latest blog posts. |
| 10 | - Optionally deploying the built site to a remote server. |
| 11 | - Starting a local development server for previewing changes. |
| 12 | |
| 13 | Usage: |
| 14 | Set the environment variable ENV to 'prod' for production builds. |
| 15 | Run the script to perform the build process accordingly. |
| 16 | |
| 17 | Dependencies: |
| 18 | - Python 3 |
| 19 | - Emacs with the publish.el script |
| 20 | - minify tool for CSS minification |
| 21 | - rsync for deployment |
| 22 | |
| 23 | Author: |
| 24 | Christian Cleberg <hello@cleberg.net> |
| 25 | """ |
| 26 | |
| 2 | 27 | import os |
| 3 | 28 | import re |
| 4 | 29 | import shutil |
| 5 | 30 | import subprocess |
| 6 | 31 | import sys |
| 7 | | from pathlib import Path |
| 8 | 32 | from datetime import datetime |
| 33 | from pathlib import Path |
| 9 | 34 | |
| 10 | 35 | |
| 11 | 36 | def update_index_html(html_snippet, template_path="./.build/index.html"): |
| @@ -60,7 +85,9 @@ def update_index_html(html_snippet, template_path="./.build/index.html"): |
| 60 | 85 | end_line_start = end_index |
| 61 | 86 | |
| 62 | 87 | # Construct the new content |
| 63 | | new_content = content[:insert_start] + indented_snippet + content[end_line_start:] |
| 88 | new_content = ( |
| 89 | content[:insert_start] + indented_snippet + content[end_line_start:] |
| 90 | ) |
| 64 | 91 | |
| 65 | 92 | # Write back to index.html |
| 66 | 93 | with open(template_path, "w", encoding="utf-8") as f: |
| @@ -161,7 +188,9 @@ def get_recent_posts_html(content_dir="./content/blog", num_posts=3): |
| 161 | 188 | f'\t\t<time datetime="{post["date_str"]}">{post["date_str"]}</time>' |
| 162 | 189 | ) |
| 163 | 190 | lines.append('\t\t<div class="post-content">') |
| 164 | | lines.append(f'\t\t\t<a href="/blog/{post["slug"]}.html">{post["title"]}</a>') |
| 191 | lines.append( |
| 192 | f'\t\t\t<a href="/blog/{post["slug"]}.html">{post["title"]}</a>' |
| 193 | ) |
| 165 | 194 | if post["tags"]: |
| 166 | 195 | lines.append('\t\t\t<div class="post-tags">') |
| 167 | 196 | for tag in post["tags"]: |
| @@ -245,7 +274,9 @@ def start_dev_server(build_dir): |
| 245 | 274 | os.chdir(build_dir) |
| 246 | 275 | # This will run until interrupted (Ctrl+C) |
| 247 | 276 | try: |
| 248 | | subprocess.run([sys.executable, "-m", "http.server", "8000"], check=True) |
| 277 | subprocess.run( |
| 278 | [sys.executable, "-m", "http.server", "8000"], check=True |
| 279 | ) |
| 249 | 280 | except KeyboardInterrupt: |
| 250 | 281 | print("\nDevelopment server stopped.") |
| 251 | 282 | except subprocess.CalledProcessError as e: |
ruff.toml
added
+14
| @@ -0,0 +1,14 @@ |
| 1 | exclude = [".venv"] |
| 2 | line-length = 80 |
| 3 | indent-width = 4 |
| 4 | respect-gitignore = true |
| 5 | show-fixes = true |
| 6 | |
| 7 | [format] |
| 8 | docstring-code-format = true |
| 9 | docstring-code-line-length = 80 |
| 10 | indent-style = "space" |
| 11 | quote-style = "double" |
| 12 | |
| 13 | [lint] |
| 14 | ignore = ["PLR0912"] |
| \ No newline at end of file |
utils/salary_visualization.py
+1 −1
| @@ -6,9 +6,9 @@ plotly. |
| 6 | 6 | """ |
| 7 | 7 | |
| 8 | 8 | import locale |
| 9 | | from pandas import read_csv as pd_read_csv |
| 10 | 9 | import pandas as pd |
| 11 | 10 | import plotly.graph_objs as go |
| 11 | from pandas import read_csv as pd_read_csv |
| 12 | 12 | |
| 13 | 13 | locale.setlocale(locale.LC_ALL, "en_US.UTF-8") |
| 14 | 14 | |