Back
+20 XP
Concept

Dependency Resolution & Lockfiles (PEP 508 & uv)

Unpinned dependencies cause deployment drift and production breakages. Modern tools use SAT/PubGrub solvers to resolve transitive dependencies, locking exact cryptographic hashes into deterministic lockfiles 🔒.

python
# PEP 508 Dependency Specification:
specs = [
    "httpx >= 0.24.0, < 1.0.0",
    "pydantic == 2.5.3",
    "uvloop; sys_platform != 'win32'"
]

for spec in specs:
    pkg, _, marker = spec.partition(";")
    print(f"Pkg: {pkg.strip():<26} Marker: {marker.strip() or 'None'} 🔒")

# 99. Dependency Resolution & Lockfiles (PEP 508 & uv) Unpinned dependencies cause deployment drift and production breakages. Modern tools use SAT/PubGrub solvers to resolve transitive dependencies, locking exact cryptographic hashes into deterministic lockfiles 🔒. ```python # PEP 508 Dependency Specification: specs = [ "httpx >= 0.24.0, < 1.0.0", "pydantic == 2.5.3", "uvloop; sys_platform != 'win32'" ] for spec in specs: pkg, _, marker = spec.partition(";") print(f"Pkg: {pkg.strip():<26} Marker: {marker.strip() or 'None'} 🔒") ``` Astral's `uv` tool resolves large dependency trees 10–100x faster than legacy `pip` by using a Rust-based PubGrub SAT solver with aggressive parallel metadata caching 🚀! --- ### Question Why must production applications commit lockfiles (`uv.lock`, `poetry.lock`) to git? 🧠 - [ ] a. To record exact resolved package versions and cryptographic hashes, guaranteeing bit-for-bit identical builds across all machines 🔒 - [ ] b. To speed up Git commit times by pre-compressing repository objects - [ ] c. To automatically bypass Linux sudo privilege restrictions during installation - [ ] d. Because Python's interpreter refuses to launch without a lockfile in the working directory --- ### Challenge Given `'fastapi >= 0.100.0; sys_platform == "linux"'`, extract the package requirement string before the semicolon and print it stripped. 🎯 <details> <summary>Solution</summary> ```python req = 'fastapi >= 0.100.0; sys_platform == "linux"' print(req.split(';')[0].strip()) ``` </details>

Checkpoint

Why must production applications commit lockfiles (`uv.lock`, `poetry.lock`) to git? 🧠

Practice

Given `'fastapi >= 0.100.0; sys_platform == "linux"'`, extract the package requirement string before the semicolon and print it stripped. 🎯

Terminal
01
Tap code blocks below to assemble
Available Blocks