aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Cleberg <hello@cleberg.net>2025-06-04 10:47:42 -0500
committerChristian Cleberg <hello@cleberg.net>2025-06-04 10:47:42 -0500
commit708ccec8b23ee1a89ae34943a4ff2368b2b5ba51 (patch)
tree57285f8181a35746831523dae90081e893574faf
parent3b0f036adc418cd5c587d7db6a11a20e8bdd5682 (diff)
downloadcleberg.net-708ccec8b23ee1a89ae34943a4ff2368b2b5ba51.tar.gz
cleberg.net-708ccec8b23ee1a89ae34943a4ff2368b2b5ba51.tar.bz2
cleberg.net-708ccec8b23ee1a89ae34943a4ff2368b2b5ba51.zip
feat(lint): added ruff.toml to automate linting and formatting
-rw-r--r--build.py39
-rw-r--r--ruff.toml14
-rw-r--r--utils/salary_visualization.py2
3 files changed, 50 insertions, 5 deletions
diff --git a/build.py b/build.py
index 60b9d27..59118fb 100644
--- a/build.py
+++ b/build.py
@@ -1,11 +1,36 @@
#!/usr/bin/env python3
+"""
+This script automates the process of building, testing, and deploying the website.
+It handles tasks such as:
+
+- Removing and recreating the build directory.
+- Minifying CSS assets.
+- Running the Emacs publishing script to generate site content.
+- Updating the index.html file with the latest blog posts.
+- Optionally deploying the built site to a remote server.
+- Starting a local development server for previewing changes.
+
+Usage:
+ Set the environment variable ENV to 'prod' for production builds.
+ Run the script to perform the build process accordingly.
+
+Dependencies:
+ - Python 3
+ - Emacs with the publish.el script
+ - minify tool for CSS minification
+ - rsync for deployment
+
+Author:
+ Christian Cleberg <hello@cleberg.net>
+"""
+
import os
import re
import shutil
import subprocess
import sys
-from pathlib import Path
from datetime import datetime
+from pathlib import Path
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"):
end_line_start = end_index
# Construct the new content
- new_content = content[:insert_start] + indented_snippet + content[end_line_start:]
+ new_content = (
+ content[:insert_start] + indented_snippet + content[end_line_start:]
+ )
# Write back to index.html
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):
f'\t\t<time datetime="{post["date_str"]}">{post["date_str"]}</time>'
)
lines.append('\t\t<div class="post-content">')
- lines.append(f'\t\t\t<a href="/blog/{post["slug"]}.html">{post["title"]}</a>')
+ lines.append(
+ f'\t\t\t<a href="/blog/{post["slug"]}.html">{post["title"]}</a>'
+ )
if post["tags"]:
lines.append('\t\t\t<div class="post-tags">')
for tag in post["tags"]:
@@ -245,7 +274,9 @@ def start_dev_server(build_dir):
os.chdir(build_dir)
# This will run until interrupted (Ctrl+C)
try:
- subprocess.run([sys.executable, "-m", "http.server", "8000"], check=True)
+ subprocess.run(
+ [sys.executable, "-m", "http.server", "8000"], check=True
+ )
except KeyboardInterrupt:
print("\nDevelopment server stopped.")
except subprocess.CalledProcessError as e:
diff --git a/ruff.toml b/ruff.toml
new file mode 100644
index 0000000..66b2fa6
--- /dev/null
+++ b/ruff.toml
@@ -0,0 +1,14 @@
+exclude = [".venv"]
+line-length = 80
+indent-width = 4
+respect-gitignore = true
+show-fixes = true
+
+[format]
+docstring-code-format = true
+docstring-code-line-length = 80
+indent-style = "space"
+quote-style = "double"
+
+[lint]
+ignore = ["PLR0912"] \ No newline at end of file
diff --git a/utils/salary_visualization.py b/utils/salary_visualization.py
index 65503fe..8da3704 100644
--- a/utils/salary_visualization.py
+++ b/utils/salary_visualization.py
@@ -6,9 +6,9 @@ plotly.
"""
import locale
-from pandas import read_csv as pd_read_csv
import pandas as pd
import plotly.graph_objs as go
+from pandas import read_csv as pd_read_csv
locale.setlocale(locale.LC_ALL, "en_US.UTF-8")