Unit 8 of 8 · about 4 hours · implement

Dependency locks, run manifests and quality gates

A result that needs your laptop to reproduce is a rumor. Locks plus manifests plus gates make the same code produce the same result on another machine.

You'll be able to

  • Lock an application with uv lock and reproduce the environment with uv sync --locked.
  • Record code, configuration, data identity, seeds and output checksums in a run manifest.
  • Wire format, lint, typecheck, test, build and clean-install gates with pre-commit and CI.

Covers

Dependency locks, clean environments and repeatable buildsData identity, configuration, seeds, manifests and checksumsType, lint, test, build and installation gates
1

Read

In this order, only the parts listed

0 of 3 done

  1. Packaging and shipping codeThe Missing Semester of Your CS Education

    Dependencies and Environments with venv and uv; Artifacts and Packaging with pyproject.toml and uv build; Releases and Versioning with pins versus ranges; Reproducibility with uv lock, lockfile contents, hermetic Nix and Bazel, Dependabot and rollback; Configuration

  2. Code Quality: gates and automationThe Missing Semester of Your CS Education

    Formatting; Linting; Pre-commit hooks; Continuous integration with matrices and badges; Command runners

  3. Versions, environments and packaging recipesStas' Python Cookbook - debugging and testing

    Versions and Dependencies: Querying installed package versions and Virtual environments; Packaging and Requirements: Modern packaging with pyproject.toml

2

Focus on

  • Applications pin, libraries range. uv.lock records exact versions with hashes, and CI enforces it with uv sync --locked.
  • A manifest names everything the run needs: commit sha, config, data checksum, seed, environment lock and output hash. Diff the manifest, not memories.
  • Gates run in order of cost: format, lint, typecheck, fast tests, build, clean-environment install. Pre-commit runs the cheap ones locally; CI runs all of them.
  • Hermetic builds pin the toolchain too, for bit-identical artifacts. Reach for Nix or Bazel only when lockfiles plus containers still diverge.
Common mistakes · 3
  • Committing the venv or syncing without --locked in CI. Plain uv sync quietly re-locks when pyproject.toml changed, so CI tests versions nobody committed; --locked fails on the stale lock.
  • Pinning == in a reusable library. Your pin becomes every downstream conflict, so range the library and pin the app.
  • CI that tests the working tree but never installs the built wheel. Packaging bugs ship green, so add a clean-install smoke step.
3

Try it yourself

Closed-book, before checking anything

Run uv init plus uv lock on a fresh package and get a uv.lock opening with version = 1 and revision = 3 (uv 0.11.32). Add a dependency to pyproject.toml without relocking and compare uv sync --locked, which errors, with plain uv sync, which rewrites the lock. Create a venv, diff printenv before and after, and see VIRTUAL_ENV and VIRTUAL_ENV_PROMPT appear with python resolving inside the venv.
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 1.uv.lock exists but CI runs uv sync without --locked. What breaks?Answer

    Nothing while pyproject.toml and uv.lock agree: uv installs the locked versions. When someone edits pyproject.toml without relocking, plain uv sync re-resolves and rewrites the lock in CI, while --locked exits with an error. Verified with uv 0.11.32.

  2. 2.Why does the lecture recommend ranges for libraries and pins for apps?Answer

    Libraries compose with other dependencies, so strict pins conflict. Apps are final consumers, so exact pins give every run identical inputs.

  3. 3.A manifest lists code sha, config, data checksum, seed, lockfile hash and output hash. Identical code gives a different output: where do you look?Answer

    The config, data, seed and environment entries. The manifest turns same code with different results into a named diff.

  4. 4.Pre-commit passes but CI fails on lint. What usually differs?Answer

    Versions or scope: hooks pinned differently from CI, or CI checks files the hooks skip. Pin the same tool versions in both.

5

Practice

You're done when

A clean checkout runs one command to a green gate, uv sync --locked reproduces the environment per the lock hashes, and the run manifest explains any output change.

Only when you can do this without notes.

Leads to

Notes

Resources · 2 for this unit, 5 more in the section
  • The Missing Semester of Your CS EducationMIT · primary

    Complete the 2026 lectures on the shell, command-line environment, development tools, debugging and profiling, Git, packaging and shipping code, and code quality. Apply every exercise to the same stage project.

  • Stas' Python Cookbook - debugging and testingStas Bekman · support

    Use Part III and the packaging sections for debugger, traceback, pytest, logging, profiling and clean-environment recipes.

Also in this section

  • pytest documentationpytest · required

    Use Get Started, fixtures, parametrization, monkeypatch, caplog and temporary paths to build behavior and failure-path tests without order dependence.

  • Hypothesis documentationHypothesis · required

    Follow the Quick start and property-based testing guides, then generate operation histories and retain the minimized example for one real defect.

  • The Art of DebuggingStas Bekman · support

    Use the Unix, Python and compiled-code sections during a real seeded defect. Follow the evidence and tiny-reproducer workflow rather than reading the unfinished book front to back.

  • Pro GitGit project · support

    Use Chapters 2-3 and the sections on debugging, internals and recovery while constructing a history for bisect and recovering a deliberately displaced commit.

  • AlgoMaster Python - mockingAlgoMaster · support

    Use the Mocking lesson for unittest.mock: Mock versus MagicMock, patch targets, autospec and the over-mocking trap. The pytest docs remain the reference for fixtures and monkeypatch.