Use separate path types for directories and files (#4285)

## Summary

This is what I consider to be the "real" fix for #8072. We now treat
directory and path URLs as separate `ParsedUrl` types and
`RequirementSource` types. This removes a lot of `.is_dir()` forking
within the `ParsedUrl::Path` arms and makes some states impossible
(e.g., you can't have a `.whl` path that is editable). It _also_ fixes
the `direct_url.json` for direct URLs that refer to files. Previously,
we wrote out to these as if they were installed as directories, which is
just wrong.
This commit is contained in:
Charlie Marsh 2024-06-12 12:59:21 -07:00 committed by GitHub
parent c4483017ac
commit d8f1de6134
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
28 changed files with 524 additions and 167 deletions

View file

@ -4791,9 +4791,9 @@ fn missing_path_requirement() -> Result<()> {
Ok(())
}
/// Attempt to resolve an editable requirement at a path that doesn't exist.
/// Attempt to resolve an editable requirement at a file path that doesn't exist.
#[test]
fn missing_editable_requirement() -> Result<()> {
fn missing_editable_file() -> Result<()> {
let context = TestContext::new("3.12");
let requirements_in = context.temp_dir.child("requirements.in");
requirements_in.write_str("-e foo/anyio-3.7.0.tar.gz")?;
@ -4805,7 +4805,28 @@ fn missing_editable_requirement() -> Result<()> {
----- stdout -----
----- stderr -----
error: Distribution not found at: file://[TEMP_DIR]/foo/anyio-3.7.0.tar.gz
error: Unsupported editable requirement in `requirements.in`
Caused by: Editable must refer to a local directory, not an archive: `file://[TEMP_DIR]/foo/anyio-3.7.0.tar.gz`
"###);
Ok(())
}
/// Attempt to resolve an editable requirement at a directory path that doesn't exist.
#[test]
fn missing_editable_directory() -> Result<()> {
let context = TestContext::new("3.12");
let requirements_in = context.temp_dir.child("requirements.in");
requirements_in.write_str("-e foo/bar")?;
uv_snapshot!(context.filters(), context.compile()
.arg("requirements.in"), @r###"
success: false
exit_code: 2
----- stdout -----
----- stderr -----
error: Distribution not found at: file://[TEMP_DIR]/foo/bar
"###);
Ok(())