-
Notifications
You must be signed in to change notification settings - Fork 667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow workspace members from sibling directories #4499
Conversation
64b4c1e
to
1fd8c2f
Compare
959c662
to
6da8f64
Compare
The reason we've been enforcing that package need to be below the workspace root is for dependencies into other workspace. Say we have a workspace:
and another
and dependencies B -> E and E -> F. With our current design, E can say For your use case, can you use a regular editable path dependency instead of a workspace? |
In this example I know this is not the most elegant solution. There is a method in pub fn with_current_project(self, package_name: PackageName) -> Option<ProjectWorkspace> It could read the [tool.uv]
top-level = true If that's set it would filter out members that aren't a direct or transitive dependency of
I tried that a while ago, but I'm not a big fan of either of these PRs, ideally I'd like to see workspaces support independent members natively. |
48e168e
to
2013de9
Compare
2013de9
to
6884e15
Compare
After looking at the source a bit more I realize this isn't quite right. I updated the sample workspace to allow dependencies between libraries. |
I am aware of the current problems when trying to combine relative paths, PEP 621/pyproject.toml and a build backend, but i don't think workspaces are the right tool to solve. Workspaces are intended for cases where there's a single project consisting of multiple package, to give each package an individual dependency specification and - if wanted - configuration in pyproject.toml. They don't work well as a tool for sharing a library between two applications. |
That's true, but I think with a few tweaks they could provide a clean solution for both. This particular change is a few lines only, doesn't break any existing code, and already makes the scenario possible. I also opened #4574, proposing a friendlier solution. It'll require a bit more coding, but I don't think it's going to be too intrusive either. |
The new PR provides explicit support for the use-case. |
Currently it doesn't break any existing code, but with #3943 in place and people starting to have e.g. git dependencies into a package in a workspace, i'm afraid this change would cause some breakage. If you could write-up an issue about your problems using hatch and uv together with relative path dependencies, i can have look and we can figure out a way to make this work. Starting off with a specific problem and discussing possible solutions and existing constraints we can much better solve your use case and avoid rejecting PRs that you've put effort into. |
I believe this PR kinda close the 1st bullet point from #3943, while #4610 addresses the same underlying issue differently, within a single workspace, with no extra toml to write.
I'll try to come up with an example. But from what I remember, it was something like
I don't mean to overwhelm you with PRs, but figuring out a solution is fun regardless of whether it gets merged or not. The problem I'm trying to solve is described in #4574. |
The use-case is supported using [tool.uv.sources]
shared_lib = { path = "../shared_lib", editable = true} |
Summary
Shared libraries for independent projects.
Let's say I have the following layout:
app1
andapp2
never have to coexist in the same virtualenv, their dependencies are independentand allowed to conflict with each other.
shared_lib
andshared_corelib
, being libraries, have to play nice with both of them.I want to use worskpaces to define the following direct dependencies:
app1->shared_lib
app2->shared_lib
shared_lib->shared_corelib
But if I simply create a workspace in
src_root
it'll try to create a shared lock and shared virtualenv for all four projects.And if I create a workspace in either
app1
orapp2
, they won't let me includeshared_lib
because it's in a sibling directory, and workspaces require a single root.At my previous job I've implemented a build, that assumed this kind of scenario, and the workspace part was only responsible for locating members, and storing shared settings like default dependency versions, constraints, etc. This has the downside of having many virtualenvs so may not be for everyone, but I think it's a valid case.
I don't know if there are any future plans to support this in
uv
, perhaps by introducing the notion of a "leaf" member?In the meantime, the scenario could be supported if workspaces were allowed to include sibling directories.
This is what this PR does.
Test Plan
Unit test