Skip to content

Split tool commands and shared CLI support into separate crates - #2292

Closed
zaniebot wants to merge 10 commits into
mainfrom
zb/split-crate-i
Closed

zaniebot wants to merge 10 commits into
mainfrom
zb/split-crate-i

Conversation

@zaniebot

@zaniebot zaniebot commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator

Tool commands and shared project workflows live alongside the dispatcher in uv. Move tool command handlers into uv-cli-tool, project environment and lock workflows into uv-cli-project, shared resolution and installation operations into uv-cli-operations, and shared CLI types and output into uv-cli-common.

Selected dependencies (A -> B means A uses B):

uv (dispatch, pip/project handlers, settings resolution)
|
+-- uv-cli-tool
|   +-- uv-cli-project
|   `-- uv-cli-operations
+-- uv-cli-project
|   `-- uv-cli-operations
+-- uv-cli-operations
`-- uv-cli-common

uv-cli-tool, uv-cli-project, uv-cli-operations -> uv-cli-common

Shared command support:
  uv-cli-project     project environments, sync, lock validation, and audit
  uv-cli-operations  shared resolution and installation workflows
  uv-cli-common      settings types, output, processes, and errors

Command crates:
  uv-cli-tool        uv tool ... and uvx

uv-cli-operations serves pip, project, and tool commands. uv-cli-project manages project environments, synchronization, lock validation, and audit support. Pip and project command handlers remain in uv.

@astral-automations-bot astral-automations-bot Bot added the internal A refactor or improvement that is not user-facing label Oct 5, 2026
@zaniebot zaniebot changed the title Prototype separate tool and shared command crates Split tool commands and shared CLI support into separate crates Oct 5, 2026
@codspeed

codspeed Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 54 untouched benchmarks
⏩ 35 skipped benchmarks1


Comparing zb/split-crate-i (3897155) with main (5411378)

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. ↩

Comment on lines +317 to +318
if let Some(members) = lock.member_group_metadata() {
let group_root = target.group_root(groups);

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] Reuse the public lockfile requirement API

group_root and the includes_group calls below access private methods defined in the sibling install_target module. Rust rejects these calls with E0624, preventing ordinary uv builds because uv-cli-project is now an unconditional dependency. Reuse InstallTarget::python_requirement, with a consistent requirement type, instead of duplicating its implementation here.

Comment thread crates/uv/tests/lock/lock.rs Outdated
.arg("--offline")
.arg("--no-cache")
.env("RUST_LOG", "uv_lock_operations::validated_lock=debug"), @"
.env("RUST_LOG", "uv_cli_project::lock=debug"), @"

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] Keep the tracing filter aligned with the executed validator

The lock command still uses uv_lock_operations::ValidatedLock, whose debug event originates in uv_lock_operations::validated_lock. This filter excludes that event, so both modified tests lose the debug line required by their snapshots when test-universal is enabled. Retain the original filter until the actual command uses the new validator.

Comment thread crates/uv/Cargo.toml
Comment on lines +28 to +31
uv-cli-common = { workspace = true }
uv-cli-operations = { workspace = true }
uv-cli-project = { workspace = true }
uv-cli-tool = { 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] Complete the migration before adding a duplicate command stack

No production Rust caller outside these four crates references them: the dispatcher still aliases uv_tool_commands and uv_project_commands, and shared types still come from uv_command_support and uv_settings. Consequently, this adds roughly 17,000 lines of parallel implementations while integration tests continue exercising the original stack. Remove the unused copies, or migrate the callers and remove the superseded implementations together, so subsequent fixes have one authoritative location.


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 insta in dev-dependencies

The only insta use is inside the #[cfg(test)] module in operations.rs, but this declaration pulls snapshot-testing machinery into uv's normal dependency graph. The original uv-install-operations correctly declares it under [dev-dependencies]. Keep that separation in the new crate.

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] Retain the typed extras validation error

This erases a known error into anyhow, requiring Error::hints to search and downcast the error chain to recover ExtrasWithoutSourceError. The existing resolver represents this as Error::ExtrasWithoutSource { has_editable } and selects its hint directly. Retain that variant in the new error enum to avoid introducing runtime type recovery during the crate split.

@zaniebot
zaniebot deployed to automations October 8, 2026 20:19 — with GitHub Actions Active
@zaniebot
zaniebot deployed to automations October 8, 2026 20:26 — with GitHub Actions Active
}
}

if python_preference.allows_source(PythonSource::DiscoveredEnvironment) {

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] Preserve interpreter-aware Python preference validation

allows_source(DiscoveredEnvironment) always returns true, so the extracted project/script workflow accepts an existing managed environment under --no-managed-python, and an unmanaged environment under --managed-python. The original compatibility check uses PythonInstallation::satisfies_preference to inspect the interpreter; sync_python_preference already covers this invariant. Retain that interpreter-aware check during the extraction.

Comment on lines +1548 to +1552
async fn from_request(
python_request: Option<PythonRequest>,
workspace: Option<&Workspace>,
script: Pep723ItemRef<'_>,
config_discovery: ConfigDiscovery,

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 script selection free of unused workspace support

The sole caller of this private function explicitly passes workspace = None. Nevertheless, the extraction introduces workspace requirements, discovery boundaries, a RequiresPythonSource enum, and a separate project-validation branch that cannot execute. This adds unsupported paths to maintain when changing script selection. Keep the original workspace-free selector and introduce workspace support alongside a concrete consumer.

Comment on lines +15 to +18
pub fn read_env_files(env_files: &[PathBuf]) -> anyhow::Result<Vec<(String, String)>> {
let mut environment = Vec::new();

for env_file_path in env_files.iter().rev().map(PathBuf::as_path) {

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 one dotenv reader within uv-cli-common

The new env_file.rs contains an identical read_env_files implementation, and the extracted tool runner already imports that version. Keeping this public copy creates two implementations of dotenv precedence and parse-error handling within the same crate. Remove the copy from child.rs, or re-export the single implementation if both module paths are needed.

@zaniebot zaniebot closed this Oct 9, 2026

This branch was successfully deployed

1 active deployment
automations — 38971559 Deployed Oct 8, 2026 by zaniebot via review-code-quality / report #8460
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 internal A refactor or improvement that is not user-facing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants