Lab 1 — Reproducible Python environment¶
Goal. Set up a project with uv + pyproject.toml + lockfile + pre-commit hooks. Add a Dockerfile that reproduces the same environment.
What you ship. Public GitHub repo with the artifacts. CI passing on a single push. README that a stranger can follow in five minutes.
Setup¶
Install the dependencies (one-time).
In [ ]:
# !pip install uv
In [ ]:
import subprocess, pathlib
What you build outside this notebook¶
Most of this lab happens at the shell. The notebook is a structured walkthrough with shell commands you run yourself (uncomment and run as you go).
In [ ]:
# Working directory for the lab
LAB = pathlib.Path('mlops-lab01')
LAB.mkdir(exist_ok=True)
print('working in:', LAB.resolve())
Exercise 1 — Initialize the project¶
In [ ]:
# !uv init mlops-lab01
# !cd mlops-lab01 && uv add numpy pandas scikit-learn
# !cd mlops-lab01 && uv add --dev pytest ruff mypy pre-commit
#
# Verify pyproject.toml and uv.lock both exist.
Exercise 2 — Add pre-commit hooks¶
In [ ]:
# YOUR TURN
# Create .pre-commit-config.yaml with ruff and mypy hooks. Run pre-commit install.
Exercise 3 — Containerize with the same dependencies¶
In [ ]:
# YOUR TURN
# Write a multi-stage Dockerfile that copies the lockfile and produces a slim
# runtime image. Verify identical behavior on host and container.
Exercise 4 — CI passing on a single push¶
In [ ]:
# YOUR TURN
# Add .github/workflows/ci.yml that runs ruff + mypy + pytest on push.
# Push to GitHub. Confirm green.
Done?¶
Submit per the cohort schedule. Peer review pairing announced the following Monday.