Skip to content
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

fix: fix for using file::// in pyproject.toml dependencies #1196

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions src/lock_file/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,15 +517,30 @@ pub async fn resolve_pypi(
None
};

// Given a pyproject.toml and either case:
// 1) dependencies = [ foo @ /home/foo ]
// 2) tool.pixi.pypi-depencies.foo = { path = "/home/foo"}
// uv has different behavior for each.
//
// 1) Because uv processes 1) during the 'source build' first we get a `file::` as a given. Which is never relative.
// because of PEP508.
// 2) We get our processed path as a given, which can be relative, as our lock may store relative url's.
//
// For case 1) we can just use the original path, as it can never be relative. And should be the same
// For case 2) we need to use the given as it may be relative
//
// I think this has to do with the order of UV processing the requirements
let given = path.url.given().expect("path should have a given url");
let given_path = if given.starts_with("file://") {
path.path
} else {
PathBuf::from(given)
};

// Create the url for the lock file. This is based on the passed in URL
// instead of from the source path to copy the path that was passed in from
// the requirement.
let url_or_path = path
.url
.given()
.map(|path| UrlOrPath::Path(PathBuf::from(path)))
.expect("path should be given");

let url_or_path = UrlOrPath::Path(given_path);
(url_or_path, hash, path.editable)
}
};
Expand Down
25 changes: 21 additions & 4 deletions src/project/manifest/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,27 @@ impl From<pep508_rs::Requirement> for PyPiRequirement {
version: VersionOrStar::Version(v),
extras: req.extras,
},
pep508_rs::VersionOrUrl::Url(u) => PyPiRequirement::Url {
url: u.to_url(),
extras: req.extras,
},
pep508_rs::VersionOrUrl::Url(u) => {
let url = u.to_url();
// Have a different code path when the url is a file.
// i.e. package @ file:///path/to/package
if url.scheme() == "file" {
// Convert the file url to a path.
let file = url
.to_file_path()
.expect("could not convert to file url to path");
PyPiRequirement::Path {
path: file,
editable: None,
extras: req.extras,
}
} else {
PyPiRequirement::Url {
url,
extras: req.extras,
}
}
}
}
} else if !req.extras.is_empty() {
PyPiRequirement::Version {
Expand Down
Loading