Skip to content
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
6 changes: 5 additions & 1 deletion crates/uv-client/src/flat_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,12 @@ impl<'a> FlatIndexClient<'a> {
path: &Path,
flat_index: &IndexUrl,
) -> Result<FlatIndexEntries, FindLinksDirectoryError> {
// The path context is provided by the caller.
#[allow(clippy::disallowed_methods)]
let entries = std::fs::read_dir(path)?;

let mut dists = Vec::new();
for entry in fs_err::read_dir(path)? {
for entry in entries {
let entry = entry?;
let metadata = entry.metadata()?;

Expand Down
29 changes: 21 additions & 8 deletions crates/uv-distribution-types/src/index_url.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use itertools::Either;
use rustc_hash::{FxHashMap, FxHashSet};
use std::borrow::Cow;
use std::fmt::{Display, Formatter};
use std::ops::Deref;
use std::path::Path;
use std::str::FromStr;
use std::sync::{Arc, LazyLock, RwLock};

use itertools::Either;
use rustc_hash::{FxHashMap, FxHashSet};
use thiserror::Error;
use url::{ParseError, Url};

use uv_pep508::{VerbatimUrl, VerbatimUrlError};
use uv_pep508::{split_scheme, Scheme, VerbatimUrl, VerbatimUrlError};

use crate::{Index, Verbatim};

Expand Down Expand Up @@ -114,10 +114,23 @@ impl FromStr for IndexUrl {
type Err = IndexUrlError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
let url = if Path::new(s).exists() {
VerbatimUrl::from_absolute_path(std::path::absolute(s)?)?
} else {
VerbatimUrl::parse_url(s)?
let url = match split_scheme(s) {
Some((scheme, ..)) => {
match Scheme::parse(scheme) {
Some(_) => {
// Ex) `https://pypi.org/simple`
VerbatimUrl::parse_url(s)?
}
None => {
// Ex) `C:\Users\user\index`
VerbatimUrl::from_absolute_path(std::path::absolute(s)?)?
}
}
}
None => {
// Ex) `/Users/user/index`
VerbatimUrl::from_absolute_path(std::path::absolute(s)?)?
}
};
Ok(Self::from(url.with_given(s)))
}
Expand Down
35 changes: 35 additions & 0 deletions crates/uv/tests/it/pip_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,41 @@ fn missing_pyproject_toml() {
);
}

#[test]
fn missing_find_links() -> Result<()> {
let context = TestContext::new("3.12");
let requirements_txt = context.temp_dir.child("requirements.txt");
requirements_txt.write_str("flask")?;

let error = regex::escape("The system cannot find the path specified. (os error 3)");
let filters = context
.filters()
.into_iter()
.chain(std::iter::once((
error.as_str(),
"No such file or directory (os error 2)",
)))
.collect::<Vec<_>>();

uv_snapshot!(filters, context.pip_install()
.arg("-r")
.arg("requirements.txt")
.arg("--find-links")
.arg("./missing")
.arg("--strict"), @r###"
success: false
exit_code: 2
----- stdout -----

----- stderr -----
error: Failed to read `--find-links` directory: [TEMP_DIR]/missing
Caused by: No such file or directory (os error 2)
"###
);

Ok(())
}

#[test]
fn invalid_pyproject_toml_syntax() -> Result<()> {
let context = TestContext::new("3.12");
Expand Down