Skip to content

Commit

Permalink
Add to root member
Browse files Browse the repository at this point in the history
  • Loading branch information
j178 committed Jul 22, 2024
1 parent 8675181 commit 0f9f37d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
11 changes: 11 additions & 0 deletions crates/uv-workspace/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,17 @@ impl ProjectWorkspace {
&self.workspace().packages[&self.project_name]
}

/// Returns the workspace root member as a [`WorkspaceMember`].
pub fn root_member(&self) -> &WorkspaceMember {
self.workspace().packages.iter().find_map(|(_, member)| {
if member.root() == self.workspace().install_path() {
Some(member)
} else {
None
}
}).expect("workspace root member must exist")
}

/// Find the workspace for a project.
pub async fn from_project(
install_path: &Path,
Expand Down
12 changes: 5 additions & 7 deletions crates/uv/src/commands/project/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,23 +111,21 @@ pub(crate) async fn init(

if let Some(workspace) = workspace {
// Add the package to the workspace.
let mut pyproject =
PyProjectTomlMut::from_toml(workspace.current_project().pyproject_toml())?;
pyproject.add_workspace(path.strip_prefix(workspace.project_root())?)?;
let root_member = workspace.root_member();
let mut pyproject = PyProjectTomlMut::from_toml(root_member.pyproject_toml())?;
pyproject.add_workspace(path.strip_prefix(root_member.root())?)?;

// Save the modified `pyproject.toml`.
fs_err::write(
workspace.current_project().root().join("pyproject.toml"),
root_member.root().join("pyproject.toml"),
pyproject.to_string(),
)?;

writeln!(
printer.stderr(),
"Adding {} as member of workspace {}",
name.cyan(),
workspace
.workspace()
.install_path()
root_member.root()
.simplified_display()
.cyan()
)?;
Expand Down

0 comments on commit 0f9f37d

Please sign in to comment.