uv icon indicating copy to clipboard operation
uv copied to clipboard

Are doubly-nested packages supported in a workspace?

Open StefanSmith opened this issue 7 months ago • 3 comments

Question

Does uv support workspace packages nested inside other (non-root) workspace packages? Note: I'm not asking about nested workspaces. I'm asking about scenarios involving a single workspace.

For reasons related to code reuse, I want to define the following nested package structure

(workspace root) > child > grandchild1, grandchild2

From an empty directory, I can issue the following commands:

uv init --lib --no-readme root
cd root
uv init --lib --no-readme child
cd child
uv init --lib --no-readme grandchild1
uv init --lib --no-readme grandchild2
cd grandchild2
uv add grandchild1

Everything works up until the last line, which outputs:

Using CPython 3.12.6
Creating virtual environment at: .venv
  × No solution found when resolving dependencies:
  ╰─▶ Because grandchild1 was not found in the package registry and your project depends on grandchild1, we can conclude that your project's requirements are unsatisfiable.
  help: If you want to add the package regardless of the failed resolution, provide the `--frozen` flag to skip locking and syncing.

Running uv lock --dry-run --verbose from inside grandchild2, the workspace defined in the root package is not detected. Instead, the command outputs:

DEBUG uv 0.7.2 (481d05d8d 2025-04-30)
DEBUG Project is contained in non-workspace project: `/private/var/folders/h6/n37ms9d553962m47nj3695s40000gp/T/tmp.Vv4Q1KoaRK/root/child`
DEBUG Found workspace root: `/private/var/folders/h6/n37ms9d553962m47nj3695s40000gp/T/tmp.Vv4Q1KoaRK/root/child/grandchild2`
DEBUG Adding root workspace member: `/private/var/folders/h6/n37ms9d553962m47nj3695s40000gp/T/tmp.Vv4Q1KoaRK/root/child/grandchild2`
...

Conversely, if I run uv lock --dry-run --verbose from inside child, the correct workspace is detected and the command outputs:

DEBUG uv 0.7.2 (481d05d8d 2025-04-30)
DEBUG Found workspace root: `/private/var/folders/h6/n37ms9d553962m47nj3695s40000gp/T/tmp.Vv4Q1KoaRK/root`
DEBUG Adding root workspace member: `/private/var/folders/h6/n37ms9d553962m47nj3695s40000gp/T/tmp.Vv4Q1KoaRK/root`
DEBUG Adding discovered workspace member: `/private/var/folders/h6/n37ms9d553962m47nj3695s40000gp/T/tmp.Vv4Q1KoaRK/root/child`
DEBUG Adding discovered workspace member: `/private/var/folders/h6/n37ms9d553962m47nj3695s40000gp/T/tmp.Vv4Q1KoaRK/root/child/grandchild1`
DEBUG Adding discovered workspace member: `/private/var/folders/h6/n37ms9d553962m47nj3695s40000gp/T/tmp.Vv4Q1KoaRK/root/child/grandchild2`
...

Note that, if run from the root directory, certain commands work as expected. For example, running uv tree from the root directory outputs:

Resolved 4 packages in 12ms
root v0.1.0
grandchild2 v0.1.0
grandchild1 v0.1.0
child v0.1.0

And running uv add --package child grandchild1 also works:

Resolved 4 packages in 3ms
      Built child @ file:///private/var/folders/h6/n37ms9d553962m47nj3695s40000gp/T/tmp.Vv4Q1KoaRK/root/child
Prepared 1 package in 440ms
Uninstalled 1 package in 0.67ms
Installed 2 packages in 13ms
 ~ child==0.1.0 (from file:///private/var/folders/h6/n37ms9d553962m47nj3695s40000gp/T/tmp.Vv4Q1KoaRK/root/child)
 + grandchild1==0.1.0 (from file:///private/var/folders/h6/n37ms9d553962m47nj3695s40000gp/T/tmp.Vv4Q1KoaRK/root/child/grandchild1)

On the other hand, running uv add --package grandchild1 child fails with the following output:

error: Failed to generate package metadata for `grandchild1==0.1.0 @ editable+child/grandchild1`
  Caused by: Failed to parse entry: `child`
  Caused by: `child` references a workspace in `tool.uv.sources` (e.g., `child = { workspace = true }`), but is not a workspace member

Should I conclude that, at present, uv only supports packages nested inside the workspace root package but not deeper?

Platform

macOs 14 arm64

Version

uv 0.7.2 (481d05d8d 2025-04-30)

StefanSmith avatar May 05 '25 07:05 StefanSmith