From 8df48f035f88bd98c1f1999a0f5db31dec598ea4 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Tue, 20 Feb 2024 14:35:36 -0500 Subject: [PATCH] Fix pep508-rs tests without features (#1778) --- crates/pep508-rs/src/lib.rs | 38 ++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/crates/pep508-rs/src/lib.rs b/crates/pep508-rs/src/lib.rs index fa1a797c7..c590e3fd4 100644 --- a/crates/pep508-rs/src/lib.rs +++ b/crates/pep508-rs/src/lib.rs @@ -743,7 +743,7 @@ fn preprocess_url( start: usize, len: usize, ) -> Result { - let url = if let Some((scheme, path)) = split_scheme(url) { + if let Some((scheme, path)) = split_scheme(url) { match Scheme::parse(scheme) { // Ex) `file:///home/ferris/project/scripts/...` or `file:../editable/`. 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 { message: Pep508ErrorSource::UrlError(err), start, len, input: cursor.to_string(), })? - .with_given(url.to_string()) + .with_given(url.to_string())) } // Ex) `https://download.pytorch.org/whl/torch_stable.html` Some(_) => { // 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), start, len, input: cursor.to_string(), - })? + })?) } // Ex) `C:\Users\ferris\wheel-0.42.0.tar.gz` _ => { + #[cfg(feature = "non-pep508-extensions")] if let Some(working_dir) = working_dir { - 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()) + return Ok(VerbatimUrl::from_path(url, working_dir).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 { @@ -802,16 +803,15 @@ fn preprocess_url( 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 { message: Pep508ErrorSource::UrlError(err), start, len, input: cursor.to_string(), })? - .with_given(url.to_string()) - }; - Ok(url) + .with_given(url.to_string())) + } } /// PEP 440 wrapper