Skip to content

Split command implementations and shared support out of uv - #2291

Draft
zaniebot wants to merge 20 commits into
mainfrom
zb/split-uv-crate
Draft

zaniebot wants to merge 20 commits into
mainfrom
zb/split-uv-crate

Conversation

@zaniebot

@zaniebot zaniebot commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator

Command implementations and shared project workflows are concentrated in uv. Move every command family into a dedicated *-command crate and give shared operations, project logic, CLI settings, output, and process helpers separate owners. uv retains initialization, dispatch, logging, and the central error-hint registry.

Selected dependencies:

uv (initialization and dispatch)
|
+-- uv-*-command (25 command crates)
|   |
|   +-- uv-project ----------> uv-operations
|   `-- uv-operations              |
|                                 `-- existing domain crates
+-- uv-cli-settings ---------> uv-cli-arguments
`-- uv-cli-arguments              (formerly uv-cli)

Shared command support:
  uv-cli-types       exit status and command-selection types
  uv-cli-output      terminal output and progress reporters
  uv-cli-report      installation reports
  uv-cli-error       command error classification
  uv-child-process   process execution and environment files

Command crates:
  uv-pip-command          uv pip ...
  uv-lock-command         uv lock
  uv-sync-command         uv sync
  uv-add-command          uv add
  uv-remove-command       uv remove
  uv-run-command          uv run
  uv-init-command         uv init
  uv-export-command       uv export
  uv-tree-command         uv tree
  uv-format-command       uv format
  uv-check-command        uv check
  uv-upgrade-command      uv upgrade
  uv-version-command      uv version
  uv-audit-command        uv audit
  uv-workspace-command    uv workspace ...
  uv-python-command       uv python ...
  uv-tool-command         uv tool ... and uvx
  uv-auth-command         uv auth ...
  uv-cache-command        uv cache ...
  uv-build-command        uv build and build-backend entrypoints
  uv-publish-command      uv publish
  uv-venv-command         uv venv
  uv-help-command         uv help
  uv-self-update-command  uv self update (optional)
  uv-pylock-command       shared pylock command support

Callers import directly from owning modules. Existing domain crates retain their responsibilities, and the split keeps command behavior, error classification, and application metadata intact. self-update remains optional.

@codspeed

codspeed Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by 14.72%

⚠️ 8 benchmarks spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
✅ 68 untouched benchmarks
⏩ 35 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
⚡ ⚠️ Simulation discover_workspace_from_all_members 151.5 ms 132.1 ms +14.72%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing zb/split-uv-crate (f0541ca) with main (64e2ac8)

Open in CodSpeed

Footnotes

  1. 35 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@zaniebot zaniebot changed the title Split shared operations and output into separate crates Split command implementations and shared support out of uv Oct 5, 2026
@astral-automations-bot
astral-automations-bot Bot force-pushed the zb/split-uv-crate branch 9 times, most recently from c059bbf to b99d3ad Compare October 7, 2026 18:20
@zaniebot zaniebot added the build:skip-release Disable building release binaries for a pull request label Oct 7, 2026
Comment thread Cargo.toml Outdated
uv-help-command = { version = "0.0.90", path = "crates/uv-help-command" }
uv-init-command = { version = "0.0.90", path = "crates/uv-init-command" }
uv-lock-command = { version = "0.0.90", path = "crates/uv-lock-command" }
uv-pip-command = { version = "0.0.90", path = "crates/uv-pip-command" }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] Remove the superseded command and support crates

The new command crates copy implementations while leaving uv-pip-commands, uv-python-commands, uv-tool-commands, and uv-workspace-commands intact. Cargo metadata shows those four crates have no consumers, and their old support crates form a dependency graph unreachable from uv. Because workspace membership uses crates/*, workspace checks still maintain both implementations. Remove the superseded crates and their workspace dependency entries so each workflow has one owner.

Comment thread crates/uv-operations/Cargo.toml Outdated

anyhow = { workspace = true }
fs-err = { workspace = true }
insta = { workspace = true }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] Keep snapshot dependencies limited to test builds

insta is used only inside the #[cfg(test)] module in installation.rs and is already declared under [dev-dependencies]. Adding it here unnecessarily brings snapshot infrastructure into ordinary uv builds. The new uv-publish-command manifest also moves its test-only insta dependency into production dependencies. Keep both declarations under [dev-dependencies].

Comment on lines +232 to +236
let build_result = build_impl(
project_dir,
skip_dependency_check,
src.as_deref(),
package.as_ref(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] Avoid duplicating the complete build entry point

build_impl is private and has only this caller; it still performs CLI reporting and error rendering. The wrapper forwards the entire argument list and converts a new two-variant BuildResult directly into ExitStatus, so every future build option must now be maintained across two signatures and another forwarding call without establishing a separate reusable operation. Keep the implementation in build_frontend and return ExitStatus directly.

Comment on lines +772 to +777
let package_name = serde_json::to_string(&final_version.package_name)?;
let version = serde_json::to_string(&final_version.version)?;
let commit_info = serde_json::to_string(&final_version.commit_info)?;
writeln!(
printer.stdout_important(),
"{{\n \"package_name\": {package_name},\n \"version\": {version},\n \"commit_info\": {commit_info}\n}}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] Retain derived serialization for project version output

Replacing ProjectVersionInfo's Serialize implementation with separately serialized fields and a handwritten JSON object creates a second definition of the output schema. Field additions or removals must now be synchronized with this format string, although the previous serde_json::to_string_pretty(&final_version) already produced the output covered by version_get_json. Restore the derive and serialize the struct directly in the new crate.

Comment on lines +1893 to +1897
uv_virtualenv::Seed::Disabled,
upgradeable,
)?;

if centralized {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Restore interpreter caching after environment creation

The moved project and script creation paths omit environment.cache_virtualenv(false, cache)?. create_venv does not populate that cache, so the next invocation queries Python again and executes startup hooks. The existing sync_caches_interpreter test explicitly checks this contract with a sitecustomize.py marker. Restore the cache writes after creating both environments.

let has_editable = requirements
.iter()
.any(|source| matches!(source, RequirementsSource::Editable(_)));
return Err(anyhow::Error::new(ExtrasWithoutSourceError { has_editable }).into());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] Keep the extras validation failure in the operation error enum

read_requirements already returns this crate's closed Error enum. Erasing this known failure into Anyhow now requires Error::hints to walk and downcast its own nested error, plus another registration in the central hint registry. Retain the original ExtrasWithoutSource { has_editable } variant and handle its hint directly, keeping this validation path statically typed.

Comment on lines +524 to +529
let state = UniversalState::default();

// Lock and sync the environment, if necessary.
let lock = match Box::pin(
uv_lock_command::lock::LockOperation::new(
LockMode::Frozen(frozen_source.into()),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] Read the frozen version directly from the lock target

LockOperation::execute handles Frozen by calling target.read_frozen(source) directly. This wrapper therefore adds shared state, a logger, boxed futures, and resolver/client configuration parameters without adding validation. Restore the direct read_frozen(...).await.map_err(UvError::from)? call so the read-only version path requires only the state it uses.

Comment thread crates/uv-init-command/src/init.rs Outdated
Comment on lines +730 to +735
trait InitProjectKindExt {
fn init(
self,
name: &PackageName,
path: &Path,
requires_python: &RequiresPython,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] Keep project initialization as a free function

InitProjectKindExt has one implementation and one caller, with no generic or dynamic consumer. It duplicates the long initialization signature solely to provide method syntax, making each future initialization option require changes to both declarations. Keep init_project_kind in this command crate and pass the closed enum explicitly.

@@ -1,28 +1,24 @@
[package]
name = "uv-publish-commands"
name = "uv-publish-command"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Update publish-test routing for the renamed crate

The publish implementation now lives under crates/uv-publish-command, but .github/workflows/plan.yml:197 still matches crates/uv-publish-commands/. A PR changing only the new directory will therefore skip the dedicated trusted-publishing tests unless explicitly enabled by a label. Update the path predicate alongside this rename.

Comment on lines 86 to +87
writeln!(
printer.stderr_important(),
printer.stderr(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Restore the pip-check output priorities

The stream swaps change uv pip check -q: incompatible environments lose the Found … incompatibilities summary, while compatible environments now print a success message. The existing check_incompatible_packages_quiet snapshot explicitly requires that summary. Keep the success message on stderr() and the incompatibility summary on stderr_important() so the crate move retains the command's output policy.

Comment on lines +518 to +522
write_error_chain_with_options(
err.as_ref(),
&hints,
ErrorOptions::default().with_stream(printer.stderr_important()),
)?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] Keep build failures using the shared error renderer

This duplicates uv::diagnostics::write_error_chain, including its default options and output-stream selection. Future changes to the shared rendering policy would need a separate update here, while tool upgrades still use the existing renderer callback. Retain the fn(&anyhow::Error, Printer) -> std::fmt::Result callback and pass diagnostics::write_error_chain from the dispatcher to keep that policy in one place.

}
}

/// Update a [`PythonEnvironment`] to satisfy a set of [`RequirementsSource`]s.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] Document the actual environment-update input type

This function still consumes a RequirementsSpecification. RequirementsSource is neither used in the signature nor imported, leaving the new rustdoc link unresolved and the API description misleading. Restore the RequirementsSpecification wording here and on EnvironmentUpdate.

Comment on lines +1 to +4
[package]
name = "uv-cli-types"
version = "0.0.93"
edition = { workspace = true }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Add required descriptions to the new publishable crates

Cargo metadata reports no package.description for 28 new crates, including this one. scripts/publish-crates.py selects all publishable workspace members, but crates.io requires a nonempty description, so the next workspace publication will fail. Release preparation only updates versions and READMEs; it does not supply this metadata. Add descriptions to these manifests, following the existing component crates.

Self::Python(err) => err.hints(),
Self::Operation(err) => err.hints(),
Self::Client(err) => uv_errors::Hinted::hints(err),
_ => uv_errors::Hints::none(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] Keep project-error hint dispatch exhaustive

The merged Hinted implementation replaces exhaustive matches in the original error types with this wildcard. Adding a ProjectError variant now silently selects no hints unless its author remembers to update this separate match, including variants that should delegate to an inner error. Enumerate the intentional hint-free variants so additions require an explicit hint policy, following the original implementations and repository convention.

Comment on lines +102 to +109
#[cfg(test)]
mod error_tests {
use std::io::{Error, ErrorKind};

// Command context retains the lockfile's regeneration hint.
let error = anyhow::Error::new(error).context("Failed to check the lockfile");
use anyhow::bail;
use insta::{allow_duplicates, assert_snapshot};

let hints = hints_for_error(&error);
assert_debug_snapshot!(hints.iter().collect::<Vec<_>>(), @r#"
[
"To regenerate the lockfile, run `uv lock --refresh --preview-features lockfile-format-check`.",
]
"#);
}
use uv_cli_error::UvError;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] Keep error-conversion tests in their owning crates

This new module tests error conversions without calling either diagnostic-rendering function. Consequently, focused tests for uv-cli-error or uv-project miss this coverage, while exercising it requires building the application and all command crates. Move the two operation-classification tests into uv-cli-error and the ProjectError conversion test into uv-project; keep tests of the central hint registry here.

Comment thread Cargo.lock
Comment on lines +4262 to +4264
version = "0.103.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4443b1b6d39d7c663139942cc4558262562d2c84123bb6282ef177009ca8b281"
checksum = "0527518605e68109d875e248ea259b6758801cf165e4b2c2733ae3b51f12535a"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] Keep the TLS dependency downgrade separate from the crate split

This also downgrades rustls-webpki from 0.103.16 to 0.103.14. The workspace’s webpki constraint and all other external lockfile records are unchanged, so the crate split does not require this downgrade. It introduces an unrelated certificate-verification dependency change that needs separate justification and validation. Restore 0.103.16 with cargo update -p rustls-webpki --precise 0.103.16, or move an intentional downgrade into a separate change.

Comment on lines +3197 to +3199
| ProjectError::EmptyEnvironment
| ProjectError::InvalidProjectEnvironmentDir(..)
| ProjectError::UvLockParse(..)

ghost Oct 25, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Handle InvalidScriptEnvironmentDir in the error conversion

ProjectError declares InvalidScriptEnvironmentDir, but this match never handles it. Rust therefore rejects the conversion as non-exhaustive, preventing uv-project and uv from compiling. Add ProjectError::InvalidScriptEnvironmentDir(..) to the unexpected-error alternatives, matching the previous EnvironmentError conversion and the exit status required by sync_active_script_environment_non_virtualenv.

This branch was successfully deployed

1 active (outdated) deployment
automations — b77a89c1 Deployed Oct 21, 2026 by astral-automations-bot[bot] via review-code-quality / report #11214
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build:skip-release Disable building release binaries for a pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants