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#!/usr/bin/env python3 1#!/usr/bin/env python3
2"""
3This script automates the process of building, testing, and deploying the website.
4It 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
13Usage:
14 Set the environment variable ENV to 'prod' for production builds.
15 Run the script to perform the build process accordingly.
16
17Dependencies:
18 - Python 3
19 - Emacs with the publish.el script
20 - minify tool for CSS minification
21 - rsync for deployment
22
23Author:
24 Christian Cleberg <hello@cleberg.net>
25"""
26
2import os 27import os
3import re 28import re
4import shutil 29import shutil
5import subprocess 30import subprocess
6import sys 31import sys
7from pathlib import Path
8from datetime import datetime 32from datetime import datetime
33from pathlib import Path
9 34
10 35
11def update_index_html(html_snippet, template_path="./.build/index.html"): 36def 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 end_line_start = end_index 85 end_line_start = end_index
61 86
62 # Construct the new content 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 # Write back to index.html 92 # Write back to index.html
66 with open(template_path, "w", encoding="utf-8") as f: 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 f'\t\t<time datetime="{post["date_str"]}">{post["date_str"]}</time>' 188 f'\t\t<time datetime="{post["date_str"]}">{post["date_str"]}</time>'
162 ) 189 )
163 lines.append('\t\t<div class="post-content">') 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 if post["tags"]: 194 if post["tags"]:
166 lines.append('\t\t\t<div class="post-tags">') 195 lines.append('\t\t\t<div class="post-tags">')
167 for tag in post["tags"]: 196 for tag in post["tags"]:
@@ -245,7 +274,9 @@ def start_dev_server(build_dir):
245 os.chdir(build_dir) 274 os.chdir(build_dir)
246 # This will run until interrupted (Ctrl+C) 275 # This will run until interrupted (Ctrl+C)
247 try: 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 except KeyboardInterrupt: 280 except KeyboardInterrupt:
250 print("\nDevelopment server stopped.") 281 print("\nDevelopment server stopped.")
251 except subprocess.CalledProcessError as e: 282 except subprocess.CalledProcessError as e:
ruff.toml added +14
@@ -0,0 +1,14 @@
1exclude = [".venv"]
2line-length = 80
3indent-width = 4
4respect-gitignore = true
5show-fixes = true
6
7[format]
8docstring-code-format = true
9docstring-code-line-length = 80
10indent-style = "space"
11quote-style = "double"
12
13[lint]
14ignore = ["PLR0912"]\ No newline at end of file
utils/salary_visualization.py +1 −1
@@ -6,9 +6,9 @@ plotly.
6""" 6"""
7 7
8import locale 8import locale
9from pandas import read_csv as pd_read_csv
10import pandas as pd 9import pandas as pd
11import plotly.graph_objs as go 10import plotly.graph_objs as go
11from pandas import read_csv as pd_read_csv
12 12
13locale.setlocale(locale.LC_ALL, "en_US.UTF-8") 13locale.setlocale(locale.LC_ALL, "en_US.UTF-8")
14 14