uv workspace doesn't install development dependencies for packages
I have a uv workspace, following a very similar layout to the albatros one in the docs. The when bird-feeder (a workspace package) have development dependencies that are in addition to the root packages dependencies, they don't get installed.
For example:
# add in root pyproject.toml
[tool.uv]
dev-dependencies = [
"tqdm"
]
in
# in packages/bird-feeder/pyproject.toml
[tool.uv]
dev-dependencies = [
"pytest"
]
Doing a uv sync in the root finds both but does not install both. Is that the expected?
What expected
Package resolution is done across the whole workspace, including dev packages.
What happens
Root and each package just installs their own development dependencies:
❯ uv sync
warning: Missing version constraint (e.g., a lower bound) for `tqdm`
warning: Missing version constraint (e.g., a lower bound) for `pytest`
Resolved 8 packages in 1.28s
Built albatros @ file:///Users/gergely/prog/uvworkspace/albatros
Built bird-feeder @ file:///Users/gergely/prog/uvworkspace/albatros/packages/bird-feeder
Prepared 2 packages in 800ms
Uninstalled 2 packages in 3ms
Installed 3 packages in 5ms
- albatros==0.1.1.dev2+g59d56f9.d20241212 (from file:///Users/gergely/prog/uvworkspace/albatros)
+ albatros==0.1.1.dev3+ge5c6435.d20241213 (from file:///Users/gergely/prog/uvworkspace/albatros)
- bird-feeder==0.1.1.dev2+g59d56f9.d20241212 (from file:///Users/gergely/prog/uvworkspace/albatros/packages/bird-feeder)
+ bird-feeder==0.1.1.dev3+ge5c6435.d20241213 (from file:///Users/gergely/prog/uvworkspace/albatros/packages/bird-feeder)
+ tqdm==4.67.1
On the other hand, running the sync restricted to the package:
❯ uv sync --package bird-feeder
warning: Missing version constraint (e.g., a lower bound) for `tqdm`
warning: Missing version constraint (e.g., a lower bound) for `pytest`
Resolved 8 packages in 2ms
Uninstalled 2 packages in 19ms
Installed 4 packages in 8ms
- albatros==0.1.1.dev3+ge5c6435.d20241213 (from file:///Users/gergely/prog/uvworkspace/albatros)
+ iniconfig==2.0.0
+ packaging==24.2
+ pluggy==1.5.0
+ pytest==8.3.4
- tqdm==4.67.1
here it uninstalls the root requirement. So I cannot really get a "development environment suitable for the whole workspace", despite the docs' saying.
Workspaces are intended to facilitate the development of multiple interconnected packages within a single repository.
I have an impression that this was intentional. I think you can try uv sync --all-packages.
But I'm not sure if this usage is correct, so I suggest waiting for others' responses before considering closing the issue.
I have a very similar issue: I wish to install both a workspace package and the root dev dependencies to be able to run tests on the package. I don't want to use uv sync --all-packages because I don't want other workspace packages' dependencies in the environment.
@imrehg I was looking into the same, and can see what you mean.
I think unfortunately the solution is to have pytest in each repository which is not ideal
Yeah, it's intentional that if each project relies on pytest, then each project should declare a dependency on pytest.
@charliermarsh What is the best way to make sure that it is the same version as the root? Just defining it without a version?
Hey, sorry to confuse things with the "too many examples".
The main thing wasn't to have things installed when they are not defined, but to understand whether or not the union of all the workspace's dev dependencies should be installed by default?
@FishAlchemist the --all-packages seem to be doing what I meant in this particular case, I'll try it a bit more to confirm! :D Cheers!
To clarify, does this mean that uv does not support inheriting dependency groups from a workspace into a project? I can understand the confusion this would cause if it was done implicitly.
Is there a way to explicitly define and select groups for inheritance? Configurations such as tool.uv.workspace.dependency-groups, and tool.uv.workspace.constraint-dependencies could provide a lot of monorepo value in support of tool.uv.workspace.members.
Projects could still select which of these dependencies to install using --group, or include them in tool.uv.default-groups.
Edit: Adding here that inheriting tool.uv.workspace.environments may be of value as well.
We just ran into this and would love the ability to inherit dependency groups / tool settings from the workspace.
You can use uv sync --inexact to leave existing packages in the venv alone. So you would do this to sync a specific package and root dev:
# from repo root
# sync package
uv sync --package my-package
# sync root dev deps
uv sync --inexact --only-group dev
Would still be great to have a single command for this. For example, the above can mess up a background lsp like basedpyright since the binary is deleted by the first sync
Just restructured my repo to use workspaces and am hitting the same disconnect of expectations vs reality.
When developing an application that is in a workspace with dependent libraries, I'd expect running uv sync to install the dev dependencies, as needed, across the workspace, without --all-packages, which is way too aggressive.
To "fix" this so I can simply run uv sync I need to put all my dev-dependencies in each pyproject.toml, which strikes me as both non-DRY and a recipe for pain, e.g., drifting versions of tools.
How about a command-line option / environment-variable: --include-workspace-dev / UV_SYNC_WORKSPACE_DEV