astral-sh/uv
Project workflow
The "project" workflow is uv's pyproject.toml-centric path: uv init, uv add, uv remove, uv sync, uv run, uv lock, uv version. These commands all share a common
shape:
- Discover the workspace.
- Load
pyproject.tomland anyuv.toml. - Optionally re-resolve into
uv.lock(Dependency resolution). - Optionally re-install (crates/uv-installer).
- Optionally mutate
pyproject.toml(crates/uv-workspacepyproject_mut.rs). - Optionally spawn the user's process (
uv run).
uv init
flowchart LR
user[uv init my-pkg] --> py[Pick Python via uv-python]
py --> tpl[Materialize template files]
tpl --> readme[README, src/my_pkg/__init__.py]
tpl --> py_proj[Write pyproject.toml]
tpl --> git[git init + initial .gitignore]Key files:
crates/uv/src/commands/init.rs— the orchestrator.crates/uv-workspace/src/pyproject.rs— thePyProjectTomldefaults.- The template strings live alongside
init.rs.
uv add / uv remove
uv add ruff is more involved than it looks:
- Parse the requirement string with
uv-pep508. - Resolve to find the actual version range it'll lock (so the inserted spec has correct bounds).
- Insert via
PyProjectTomlMut— preserving formatting, comments, and existing ordering. - Re-lock and re-sync if the working venv exists.
The insertion logic is the bulk of crates/uv-workspace/src/pyproject_mut.rs (~78 KB).
Tests for it are in crates/uv/tests/it/edit.rs.
uv sync
uv sync is the workhorse: ensure the venv matches the lockfile.
- Read
uv.lock. - Filter to the packages enabled by current extras / groups.
- Diff against the venv via
uv-installer'sPlan. - Apply the plan: download, unpack, install.
Edge cases:
--locked— refuse to write a new lock; fail if the current one is stale.--frozen— don't lock; install from the existing lockfile as-is.--inexact— don't remove pre-existing extra packages.--all-extras/--extra X/--no-default-groups/--group dev.
uv run
uv run pytest:
- Sync the project (unless
--no-sync). - Resolve any extra
--withdependencies into an overlay environment. - Find the executable: in the venv's
bin/, then PATH within the venv. - Spawn it with the venv's environment.
crates/uv/src/commands/project/run.rs is the orchestrator.
See also
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.