Skip to content

Preserve relative structure of transitive editables in uv pip compile#19151

Open
Aditya-PS-05 wants to merge 3 commits intoastral-sh:mainfrom
Aditya-PS-05:fix/pip-compile-transitive-editable-paths
Open

Preserve relative structure of transitive editables in uv pip compile#19151
Aditya-PS-05 wants to merge 3 commits intoastral-sh:mainfrom
Aditya-PS-05:fix/pip-compile-transitive-editable-paths

Conversation

@Aditya-PS-05
Copy link
Copy Markdown
Contributor

closes #19091

Issue: When a project that depends on a local package, and that package that depends on another local package (written in [tool.uv.sources]). When we run uv pip compile, the transitive editable's path gets dumped into requirements.txt exactly as it was written in the inner pyproject.toml but path is relative to the inner package, not to wherever we're writing the requirements.txt. So we end up with a requirements.txt that has the wrong path and uv intall errors up with "Distribution not found."

Fix: Instead of just copying the path string from the source, we take the abs path that uv already resolved internally, and convert it back into a relative path but this time relative to the dir the requirements.txt is being written into. That way the path actually makes sense from the requirements file's point of view. I also made sure to leave absolute file URLs and env-var paths alone, since those are intentional and shouldn't be rewritten.

Copilot AI review requested due to automatic review settings April 25, 2026 18:14
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes incorrect path emission for transitive editable dependencies in uv pip compile by re-anchoring relative editable paths to the output requirements file location (or working directory when emitting to stdout), preventing “Distribution not found” errors for compiled requirements.

Changes:

  • Compute an “output anchor” directory for uv pip compile output (output file’s directory when -o is used; otherwise the working directory).
  • Pass that anchor through the requirements.txt rendering pipeline to rewrite transitive editable paths based on the resolved absolute source tree.
  • Add a regression test covering transitive editable path rewriting; update an existing snapshot to reflect the new anchoring behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
crates/uv/src/commands/pip/compile.rs Establishes and threads an output anchor directory into requirements/lock emission.
crates/uv-resolver/src/resolution/display.rs Plumbs an optional anchor into requirements.txt graph display.
crates/uv-resolver/src/resolution/requirements_txt.rs Rewrites editable path emission relative to the output anchor for transitive editables.
crates/uv/tests/it/pip_compile.rs Adds a regression test for transitive editable relative paths and updates a snapshot expectation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/uv-resolver/src/resolution/requirements_txt.rs Outdated
@nooscraft
Copy link
Copy Markdown
Contributor

Couple of observations, neither blocking:

  • The new test only exercises the stdout path. A second invocation with -o subdir/requirements.txt from cwd would lock in the output_file.parent() branch too.
  • relative_to: Option<&Path> on DisplayResolutionGraph::new is always Some(...) from the only caller — could be &Path if you want to tighten the signature.

@Aditya-PS-05
Copy link
Copy Markdown
Contributor Author

Couple of observations, neither blocking:

* The new test only exercises the stdout path. A second invocation with `-o subdir/requirements.txt` from cwd would lock in the `output_file.parent()` branch too.

* `relative_to: Option<&Path>` on `DisplayResolutionGraph::new` is always `Some(...)` from the only caller — could be `&Path` if you want to tighten the signature.

Thanks and it's done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

uv pip compile does not preserve relative structure of transitive local dependencies

3 participants