Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions crates/uv-resolver/src/lock/export/metadata.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::collections::BTreeMap;
use std::fmt::Display;
use std::path::Path;

use uv_distribution_filename::WheelFilename;
use uv_distribution_types::{Name, RequiresPython, ResolvedDist, UrlString};
Expand Down Expand Up @@ -62,6 +63,9 @@ pub struct Metadata {
/// Ideally absolute paths to things that are found in subdirs of this should have exactly
/// this as a prefix so it can be stripped to get relative paths if one wants.
workspace_root: PortablePathBuf,
/// Information about the synchronized environment, when `--sync` was used.
#[serde(skip_serializing_if = "Option::is_none", default)]
environment: Option<MetadataEnvironment>,
/// The version of python required by the workspace
///
/// Every `marker` we emit implicitly assumes this constraint to keep things clean
Expand Down Expand Up @@ -97,6 +101,13 @@ struct SchemaReport {
version: SchemaVersion,
}

/// Information about the environment synchronized for the workspace.
#[derive(Debug, serde::Serialize)]
struct MetadataEnvironment {
/// Absolute path to the environment root.
root: PortablePathBuf,
}

/// Info for looking up workspace members, most information is stored in the node behind `id`
#[derive(Debug, serde::Serialize)]
struct MetadataWorkspaceMember {
Expand Down Expand Up @@ -830,6 +841,7 @@ impl Metadata {
version: SchemaVersion::Preview,
},
conflicts,
environment: None,
module_owners: BTreeMap::new(),
workspace_root,
requires_python: lock.requires_python.clone(),
Expand All @@ -852,6 +864,14 @@ impl Metadata {
.to_flat())
}

#[must_use]
pub fn with_environment_root(mut self, environment_root: &Path) -> Self {
self.environment = Some(MetadataEnvironment {
root: PortablePathBuf::from(environment_root),
});
self
}

#[must_use]
pub fn with_module_owners(mut self, module_owners: BTreeMap<ModuleName, Vec<String>>) -> Self {
self.module_owners = module_owners
Expand Down
4 changes: 3 additions & 1 deletion crates/uv/src/commands/workspace/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ pub(crate) async fn metadata(
)
.await
.context("Failed to collect module owners")?;
export = export.with_module_owners(module_owners);
export = export
.with_environment_root(environment.root())
.with_module_owners(module_owners);
}

print_metadata(&export, printer)
Expand Down
3 changes: 3 additions & 0 deletions crates/uv/tests/it/workspace_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ dependencies = [
"version": "preview"
},
"workspace_root": "[TEMP_DIR]/",
"environment": {
"root": "[VENV]/"
},
"requires_python": ">=3.12",
"conflicts": {
"sets": []
Expand Down
5 changes: 5 additions & 0 deletions docs/reference/internals/metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ Here is a human-readable annotated example:
},
// The directory the uv.lock can be found in
"workspace_root": "/workspace",
// Information about the environment synchronized by `--sync`; omitted otherwise

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: Maybe "currently only shown wiht --sync"? I can see us shown the root in other cases in the future too, especially if it's fresh anyway, and you shouldn't rely on the absence of it.

"environment": {
// The absolute path to the environment root
"root": "/workspace/.venv"
},
// Any requirements on the python version this workspace has
//
// `marker` fields all have this as an implicit constraint that is omitted for cleanliness

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: Indentation error.

Expand Down