Skip to content

Commit af1e8f5

Browse files
Merge pull request #124 from weeklydevchat/pyproject-uv-lock
Use best-practice pyproject.toml, and uv for managing dependencies
2 parents 625979d + 7244caa commit af1e8f5

13 files changed

Lines changed: 541 additions & 159 deletions

‎.dockerignore‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.venv
2+
__pycache__
3+
*.pyc
4+
.git*

‎.github/dependabot.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
version: 2
22
updates:
3-
- package-ecosystem: "pip"
3+
- package-ecosystem: "uv"
44
directory: "/"
55
schedule:
66
interval: "weekly"

‎.github/workflows/ci.yml‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,26 @@ jobs:
1414
runs-on: ubuntu-latest
1515
steps:
1616
- uses: actions/checkout@v6
17+
1718
- name: Configure Git Credentials
1819
run: |
1920
git config user.name github-actions[bot]
2021
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
21-
- uses: actions/setup-python@v6
22+
23+
- name: Install uv
24+
uses: astral-sh/setup-uv@v5
2225
with:
23-
python-version: 3.x
26+
python-version: "3.14"
27+
28+
- name: Install dependencies
29+
run: uv sync --frozen --no-dev
30+
2431
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
2532
- uses: actions/cache@v5
2633
with:
2734
key: mkdocs-material-${{ env.cache_id }}
2835
path: .cache
2936
restore-keys: |
3037
mkdocs-material-
31-
- run: pip install -r requirements.txt
32-
- run: mkdocs gh-deploy --force
38+
- name: Deploy to GitHub Pages
39+
run: uv run mkdocs gh-deploy --force

‎README.md‎

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,23 @@ This is a static site built with [MkDocs Material](https://squidfunk.github.io/m
3636

3737
1. Install dependencies:
3838
```bash
39-
pip install mkdocs-material
39+
uv sync
4040
```
4141

4242
2. Start the development server:
4343
```bash
44-
mkdocs serve
44+
uv run mkdocs serve
4545
```
4646

4747
3. Open your browser to [http://127.0.0.1:8000](http://127.0.0.1:8000)
4848

49+
50+
4. Run the image scripts if required:
51+
```bash
52+
uv run python scripts/optimize_image.py foo.png
53+
uv run scripts/optimize_all_images.sh
54+
```
55+
4956
### Local Development (Docker)
5057

5158
1. Start the development server:
@@ -125,7 +132,7 @@ These scripts will:
125132
After adding an image to a post, run the optimization script to convert it to WebP and resize it for the web:
126133

127134
```bash
128-
python3 scripts/optimize_image.py docs/posts/YYYY/MM/DD/your_image.png
135+
uv run python scripts/optimize_image.py docs/posts/YYYY/MM/DD/your_image.png
129136
```
130137

131138
This will create an optimized `.webp` file alongside the original. Update your post's markdown to reference the new `.webp` file, then delete the original if no longer needed.
@@ -141,19 +148,16 @@ This will create an optimized `.webp` file alongside the original. Update your p
141148

142149
```bash
143150
# Optimize a single image with defaults
144-
python3 scripts/optimize_image.py docs/posts/2026/04/14/photo.png
151+
uv run python scripts/optimize_image.py docs/posts/2026/04/14/photo.png
145152

146153
# Batch optimize multiple images
147-
python3 scripts/optimize_image.py docs/posts/2026/04/14/*.png docs/posts/2026/04/14/*.jpg
154+
uv run python scripts/optimize_image.py docs/posts/2026/04/14/*.png docs/posts/2026/04/14/*.jpg
148155

149156
# Custom quality and max width
150-
python3 scripts/optimize_image.py --quality 90 --max-width 1600 image.jpeg
157+
uv run python scripts/optimize_image.py --quality 90 --max-width 1600 image.jpeg
151158
```
152159

153-
> **Note:** This script requires [Pillow](https://pillow.readthedocs.io/). Install dev dependencies with:
154-
> ```bash
155-
> pip install -r requirements-dev.txt
156-
> ```
160+
157161

158162
### Categories and Tags
159163

@@ -163,15 +167,15 @@ To see all categories and tags currently in use, run:
163167

164168
**Bash (Linux/macOS)**:
165169
```bash
166-
python3 scripts/find_tags_categories.py
170+
uv run python scripts/find_tags_categories.py
167171
```
168172

169173
**PowerShell (Windows)**:
170174
```powershell
171-
python scripts/find_tags_categories.py
175+
uv run python scripts/find_tags_categories.py
172176
```
173177

174-
This script requires `pyyaml`, which is included in `requirements.txt`. It is also run automatically by the `create_post` scripts when scaffolding a new post.
178+
This script requires `pyyaml`, which is included in the dev dependencies. It is also run automatically by the `create_post` scripts when scaffolding a new post.
175179

176180
## Updating Sponsors
177181

@@ -182,12 +186,11 @@ Sponsor and donor entries live in [`data/sponsors.yml`](data/sponsors.yml), whic
182186
```
183187
.
184188
├── mkdocs.yml # Main configuration file
185-
├── requirements.txt # Python dependencies
189+
├── pyproject.toml # Python dependencies + uv config
190+
├── uv.lock # Locked dependency tree
186191
├── docker-compose.yml # Docker development environment
187192
├── create_post.sh # Bash script to create blog posts
188193
├── create_post.ps1 # PowerShell script to create blog posts
189-
├── requirements-dev.in # Dev-only dependency pins (e.g. Pillow)
190-
├── requirements-dev.txt # Compiled dev dependencies
191194
├── scripts/
192195
│ ├── find_tags_categories.py # List all existing tags and categories
193196
│ └── optimize_image.py # Optimize images for the web (PNG/JPEG → WebP)
@@ -225,15 +228,15 @@ mkdocs build # Build static site to site/ directory
225228
mkdocs build --clean # Clean build
226229

227230
# Optimize an image for the web
228-
python3 scripts/optimize_image.py docs/posts/YYYY/MM/DD/image.png
231+
uv run python scripts/optimize_image.py docs/posts/YYYY/MM/DD/image.png
229232

230233
# Help
231234
mkdocs -h # Show help
232235

233236
# Docker
234237
docker compose up app # Start development server (with hot reloading)
235238
docker compose down # Stop containers
236-
docker compose down -v # Stop containers and remove volumes (pip cache)
239+
docker compose down -v # Stop containers and remove volumes (uv cache)
237240
```
238241

239242
## Deployment

‎docker-compose.yml‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
services:
22
app:
3-
image: python:3.14-slim
4-
command: python -m mkdocs serve -a 0.0.0.0:8000 --watch-theme --livereload
5-
entrypoint: /app/docker-entrypoint.sh
3+
image: ghcr.io/astral-sh/uv:python3.14-trixie-slim
64
working_dir: /app
5+
entrypoint: /app/docker-entrypoint.sh
6+
command: uv run -- mkdocs serve -a 0.0.0.0:8000 --watch-theme --livereload
77
ports:
8-
- 8000:8000
8+
- "8000:8000"
99
volumes:
1010
- .:/app
11-
- pip-cache:/root/.cache/pip
11+
- uv-cache:/root/.cache/uv
12+
# Optional: protect .venv if you ever create one locally
13+
- /app/.venv
1214
environment:
1315
- PYTHONUNBUFFERED=1
16+
- UV_LINK_MODE=copy # helps with bind mounts
1417
stdin_open: true
1518
tty: true
1619

1720
volumes:
18-
pip-cache:
21+
uv-cache:

‎docker-entrypoint.sh‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
#!/bin/bash
1+
#!/bin/sh
22
set -e
33

4-
pip install -r requirements.txt
4+
uv sync --frozen --no-dev # or remove --no-dev if you want dev deps
5+
6+
# Optional: make sure mkdocs is in PATH
7+
export PATH="/app/.venv/bin:$PATH"
58

69
exec "$@"

‎pyproject.toml‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[project]
2+
name = "weeklydevchat-github-io"
3+
version = "0.1.0"
4+
requires-python = ">=3.14"
5+
dependencies = [
6+
"mkdocs-material>=9.7.0",
7+
"pygments~=2.20.0",
8+
"urllib3>=2.7.0",
9+
]
10+
11+
# Dependencies are managed from this `pyproject.toml` with `uv`, not `requirements*.txt`.
12+
# Install the project environment with `uv sync` and run tools/scripts with `uv run <command>`.
13+
[dependency-groups]
14+
dev = [
15+
"pillow>=12.2.0",
16+
"PyYAML>=6.0.1"
17+
18+
# Add dev-only tools here when needed; they will be installed by `uv sync`.
19+
]

‎requirements-dev.in‎

Lines changed: 0 additions & 7 deletions
This file was deleted.

‎requirements-dev.txt‎

Lines changed: 0 additions & 6 deletions
This file was deleted.

‎requirements.in‎

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)