Inspired by the poetry-monorepo-dependency-plugin, this uv geared tool facilitates the usage of more complex monorepo project structures by pinning version dependencies when building archives with local path dependencies to other uv projects within the same monorepo.
uv tool install rewrite-path-dependencies
During archive building, this tool will rewrite path dependencies
to other uv projects using the corresponding pinned version dependency extracted from the referenced project's pyproject.toml
.
By referencing pinned version dependencies in published archive files, package consumers may more easily depend on
and install packages that are built within complex monorepos, without needing to replicate the exact folder structure utilized within
the monorepo for that project's dependencies.
For example, assume that project-a
and project-a-consumer
are uv projects that exist within the same monorepo and use the following pyproject.toml
configurations.
project-a/pyproject.toml
:
[project]
name = "project-a"
version = "1.0.0.dev0"
project-a-consumer/pyproject.toml
:
[project]
name = "project-a-consumer"
version = "1.0.0.dev0"
dependencies = ["project-a"]
[tool.uv.sources]
project-a = { path = "../project-a", editable = true }
When generating wheel
or sdist
archives for the project-a-consumer
project through rewrite-path-dependencies build
, the corresponding package-a-consumer
source distribution will be constructed as if its dependency on the
project-a
project were declared as project-a = "1.0.0.dev0"
. As a result, package metadata in archives for project-a-consumer
will shift from
Requires-Dist: project-a
to Requires-Dist: project-a=="1.0.0.dev0"
.
To run this tool via the command line, within the desired package directory run uv tool run rewrite-path-dependencies build
.
uv-monorepo-dependency-tool
is available under the MIT licence.