Reject --editable flag on non-directory requirements (#10994)

## Summary

Closes https://github.com/astral-sh/uv/issues/10992.
This commit is contained in:
Charlie Marsh 2025-01-27 14:37:23 -05:00 committed by GitHub
parent 71f0798536
commit a00f6f5d3d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 67 additions and 0 deletions

View file

@ -1312,6 +1312,10 @@ pub enum SourceError {
UnusedTag(String, String),
#[error("`{0}` did not resolve to a Git repository, but a Git reference (`--branch {1}`) was provided.")]
UnusedBranch(String, String),
#[error("`{0}` did not resolve to a local directory, but the `--editable` flag was provided. Editable installs are only supported for local directories.")]
UnusedEditable(String),
#[error("Workspace dependency `{0}` was marked as `--no-editable`, but workspace dependencies are always added in editable mode. Pass `--no-editable` to `uv sync` or `uv run` to install workspace dependencies in non-editable mode.")]
UnusedNoEditable(String),
#[error("Failed to resolve absolute path")]
Absolute(#[from] std::io::Error),
#[error("Path contains invalid characters: `{}`", _0.display())]
@ -1349,6 +1353,20 @@ impl Source {
}
}
if workspace {
// If a workspace source is added with `--no-editable`, error.
if editable == Some(false) {
return Err(SourceError::UnusedNoEditable(name.to_string()));
}
} else {
// If we resolved a non-path source, and user specified an `--editable` flag, error.
if !matches!(source, RequirementSource::Directory { .. }) {
if editable == Some(true) {
return Err(SourceError::UnusedEditable(name.to_string()));
}
}
}
// If the source is a workspace package, error if the user tried to specify a source.
if workspace {
return match source {