Add Chapters 5-8: CLI Tools, FFI & PyO3, PyO3 House Style, Escaping the GIL#10
Merged
Conversation
Maps argparse/click to clap's derive API: the parser is a type, so typed arguments, ValueEnum choices, and subcommand enums make invalid invocations unrepresentable. Covers structured --json output via serde, doc comments as --help text, exit-code mapping, and in-process CLI testing with try_parse_from. Five "translate this Python" exercises. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Pure-Rust text-stats core with 20 inline tests; the PyO3 binding layer (pyfunction/pyclass/pymodule, error mapping to ValueError) sits behind an off-by-default 'python' feature so CI never needs a Python interpreter. Exercises practice C-ABI boundaries, conversion shapes, and exception-ready error types in pure Rust. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…g, zero-copy) Operationalizes the Rust-core-with-Python-reach style: pyo3 sits behind a default-off 'python' feature so cargo test stays pure Rust (the CI constraint is the lesson), one error enum maps exhaustively to typed Python exceptions, and zero-copy parsing shows what crosses the FFI line. 19 passing example tests; 5 exercises (19 tests) covering error design, exception mapping, borrow-don't-clone, and Pythonic API shape. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Maps Python's GIL/threading/multiprocessing model to Rust's compile-time concurrency: scoped threads, Send/Sync (with compile_fail doctests showing data races the compiler rejects), Arc<Mutex<T>>, mpsc channels, and rayon. PyO3 allow_threads example is gated behind a default-off `python` feature. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Writes the four roadmap chapters that complete the course through Chapter 8 — the heart of the Python ↔ Rust interop arc. One commit per chapter, each following the ch03/ch04 template (annotated
lib.rswith Python-comparison blocks + inline tests,exercises/crate withtodo!()stubs, chapter README):argparse/click→clapderive): typed args as parser-is-the-type-checker,ValueEnum, subcommand enums with exhaustive dispatch,--jsonstructured output, doc-comments-become---help, exit codes. 27 tests, 5 exercises (17 stub tests).ctypes→#[pyfunction]/#[pymodule]/#[pyclass]): raw C-ABI pain first (with a# Safetycontract), then PyO3 conversions,PyResulterror mapping, and the maturin/abi3 wheel workflow. 20 tests, 5 exercises.threading/multiprocessing→Send/Sync/rayon): scoped threads, twocompile_faildoctests proving the data races don't compile,Arc<Mutex>vs channels (mapped toqueue.Queue),par_iter, andpy.allow_threadsfor the FFI payoff. 15 tests + 2 doctests, 5 exercises.Design choice baked in (and taught explicitly in ch6/ch7): all PyO3 code sits behind a default-off
pythonfeature, so plaincargo test/clippyon CI needs no Python interpreter — exactly how real mixed crates ship. The gated code was verified to compile and pass clippy with--features pythonagainst Python 3.12 locally.Final commit moves chapters 5–8 from the README roadmap table to the shipped chapters table (9–10 remain planned).
Test plan
cargo fmt --all -- --check✅;cargo clippy --workspace --all-targets -- -D warnings✅;cargo test --workspaceexcluding-exercisescrates: 137 passed, 0 failed (+2compile_faildoctests) ✅chNN-exercisescrate fails withtodo!panics as designed; every chapter's exercises were proven solvable by the authors (solved, verified passing, reverted to stubs)./home/<user>/paths) clean on all new content; CI's secret-scan/forbidden-pattern jobs gate the rest.🤖 Generated with Claude Code