Skip to content

Commit

Permalink
fix: fix for using file::// in pyproject.toml dependencies (#1196)
Browse files Browse the repository at this point in the history
  • Loading branch information
tdejager authored Apr 16, 2024
1 parent 952f465 commit 64210ff
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
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

0 comments on commit 64210ff

Please sign in to comment.