Fix pep508-rs tests without features (#1778)

This commit is contained in:
Charlie Marsh 2024-02-20 14:35:36 -05:00 committed by GitHub
parent 2928c6e574
commit 8df48f035f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -743,7 +743,7 @@ fn preprocess_url(
start: usize, start: usize,
len: usize, len: usize,
) -> Result<VerbatimUrl, Pep508Error> { ) -> Result<VerbatimUrl, Pep508Error> {
let url = if let Some((scheme, path)) = split_scheme(url) { if let Some((scheme, path)) = split_scheme(url) {
match Scheme::parse(scheme) { match Scheme::parse(scheme) {
// Ex) `file:///home/ferris/project/scripts/...` or `file:../editable/`. // Ex) `file:///home/ferris/project/scripts/...` or `file:../editable/`.
Some(Scheme::File) => { Some(Scheme::File) => {
@ -759,40 +759,41 @@ fn preprocess_url(
); );
} }
VerbatimUrl::from_absolute_path(path) Ok(VerbatimUrl::from_absolute_path(path)
.map_err(|err| Pep508Error { .map_err(|err| Pep508Error {
message: Pep508ErrorSource::UrlError(err), message: Pep508ErrorSource::UrlError(err),
start, start,
len, len,
input: cursor.to_string(), input: cursor.to_string(),
})? })?
.with_given(url.to_string()) .with_given(url.to_string()))
} }
// Ex) `https://download.pytorch.org/whl/torch_stable.html` // Ex) `https://download.pytorch.org/whl/torch_stable.html`
Some(_) => { Some(_) => {
// Ex) `https://download.pytorch.org/whl/torch_stable.html` // Ex) `https://download.pytorch.org/whl/torch_stable.html`
VerbatimUrl::from_str(url).map_err(|err| Pep508Error { Ok(VerbatimUrl::from_str(url).map_err(|err| Pep508Error {
message: Pep508ErrorSource::UrlError(err), message: Pep508ErrorSource::UrlError(err),
start, start,
len, len,
input: cursor.to_string(), input: cursor.to_string(),
})? })?)
} }
// Ex) `C:\Users\ferris\wheel-0.42.0.tar.gz` // Ex) `C:\Users\ferris\wheel-0.42.0.tar.gz`
_ => { _ => {
#[cfg(feature = "non-pep508-extensions")]
if let Some(working_dir) = working_dir { if let Some(working_dir) = working_dir {
VerbatimUrl::from_path(url, working_dir).with_given(url.to_string()) return Ok(VerbatimUrl::from_path(url, working_dir).with_given(url.to_string()));
} else {
VerbatimUrl::from_absolute_path(url)
.map_err(|err| Pep508Error {
message: Pep508ErrorSource::UrlError(err),
start,
len,
input: cursor.to_string(),
})?
.with_given(url.to_string())
} }
Ok(VerbatimUrl::from_absolute_path(url)
.map_err(|err| Pep508Error {
message: Pep508ErrorSource::UrlError(err),
start,
len,
input: cursor.to_string(),
})?
.with_given(url.to_string()))
} }
} }
} else { } else {
@ -802,16 +803,15 @@ fn preprocess_url(
return Ok(VerbatimUrl::from_path(url, working_dir).with_given(url.to_string())); return Ok(VerbatimUrl::from_path(url, working_dir).with_given(url.to_string()));
} }
VerbatimUrl::from_absolute_path(url) Ok(VerbatimUrl::from_absolute_path(url)
.map_err(|err| Pep508Error { .map_err(|err| Pep508Error {
message: Pep508ErrorSource::UrlError(err), message: Pep508ErrorSource::UrlError(err),
start, start,
len, len,
input: cursor.to_string(), input: cursor.to_string(),
})? })?
.with_given(url.to_string()) .with_given(url.to_string()))
}; }
Ok(url)
} }
/// PEP 440 wrapper /// PEP 440 wrapper