Enable workspace lint configuration in remaining crates (#4329)

## Summary

We didn't have Clippy enabled (to match our workspace settings) in a few
crates.
This commit is contained in:
Charlie Marsh 2024-06-17 23:02:28 -04:00 committed by GitHub
parent b8c0391667
commit c996e8e3f3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
28 changed files with 249 additions and 204 deletions

View file

@ -16,13 +16,13 @@ authors = { workspace = true }
name = "pep508_rs"
crate-type = ["cdylib", "rlib"]
[dependencies]
pep440_rs = { workspace = true }
uv-fs = { workspace = true }
uv-normalize = { workspace = true }
[lints]
workspace = true
[dependencies]
derivative = { workspace = true }
once_cell = { workspace = true }
pep440_rs = { workspace = true }
pyo3 = { workspace = true, optional = true, features = ["abi3", "extension-module"] }
pyo3-log = { workspace = true, optional = true }
regex = { workspace = true }
@ -32,6 +32,8 @@ thiserror = { workspace = true }
tracing = { workspace = true, optional = true }
unicode-width = { workspace = true }
url = { workspace = true, features = ["serde"] }
uv-fs = { workspace = true }
uv-normalize = { workspace = true }
[dev-dependencies]
insta = { version = "1.36.1" }

View file

@ -35,7 +35,6 @@ use pyo3::{
};
use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
use thiserror::Error;
use unicode_width::UnicodeWidthChar;
use url::Url;
use cursor::Cursor;
@ -95,7 +94,7 @@ impl<T: Pep508Url> Display for Pep508Error<T> {
// We can use char indices here since it's a Vec<char>
let start_offset = self.input[..self.start]
.chars()
.flat_map(|c| c.width())
.filter_map(unicode_width::UnicodeWidthChar::width)
.sum::<usize>();
let underline_len = if self.start == self.input.len() {
// We also allow 0 here for convenience
@ -108,7 +107,7 @@ impl<T: Pep508Url> Display for Pep508Error<T> {
} else {
self.input[self.start..self.start + self.len]
.chars()
.flat_map(|c| c.width())
.filter_map(unicode_width::UnicodeWidthChar::width)
.sum::<usize>()
};
write!(
@ -247,7 +246,7 @@ impl PyRequirement {
/// `requests [security,tests] >= 2.8.1, == 2.8.* ; python_version > "3.8"`
#[getter]
pub fn marker(&self) -> Option<String> {
self.marker.as_ref().map(std::string::ToString::to_string)
self.marker.as_ref().map(ToString::to_string)
}
/// Parses a PEP 440 string
@ -405,6 +404,7 @@ impl<T: Pep508Url> Requirement<T> {
///
/// For example, given `flask >= 2.0.2`, calling `with_extra_marker("dotenv")` would return
/// `flask >= 2.0.2 ; extra == "dotenv"`.
#[must_use]
pub fn with_extra_marker(self, extra: &ExtraName) -> Self {
let marker = match self.marker {
Some(expression) => MarkerTree::And(vec![
@ -463,7 +463,7 @@ where
F: FnMut(MarkerWarningKind, String),
{
fn report(&mut self, kind: MarkerWarningKind, warning: String) {
(self)(kind, warning)
(self)(kind, warning);
}
}
@ -471,10 +471,11 @@ where
pub struct TracingReporter;
impl Reporter for TracingReporter {
fn report(&mut self, _kind: MarkerWarningKind, _message: String) {
#[allow(unused_variables)]
fn report(&mut self, _kind: MarkerWarningKind, message: String) {
#[cfg(feature = "tracing")]
{
tracing::warn!("{}", _message);
tracing::warn!("{message}");
}
}
}

View file

@ -274,8 +274,7 @@ impl FromStr for MarkerOperator {
// ends with in
.and_then(|space_in| space_in.strip_suffix("in"))
// and has only whitespace in between
.map(|space| !space.is_empty() && space.trim().is_empty())
.unwrap_or_default() =>
.is_some_and(|space| !space.is_empty() && space.trim().is_empty()) =>
{
Self::NotIn
}
@ -547,6 +546,7 @@ impl MarkerEnvironment {
///
/// See also [`MarkerEnvironment::implementation_name`].
#[inline]
#[must_use]
pub fn with_implementation_name(mut self, value: impl Into<String>) -> MarkerEnvironment {
Arc::make_mut(&mut self.inner).implementation_name = value.into();
self
@ -556,6 +556,7 @@ impl MarkerEnvironment {
///
/// See also [`MarkerEnvironment::implementation_version`].
#[inline]
#[must_use]
pub fn with_implementation_version(
mut self,
value: impl Into<StringVersion>,
@ -568,6 +569,7 @@ impl MarkerEnvironment {
///
/// See also [`MarkerEnvironment::os_name`].
#[inline]
#[must_use]
pub fn with_os_name(mut self, value: impl Into<String>) -> MarkerEnvironment {
Arc::make_mut(&mut self.inner).os_name = value.into();
self
@ -577,6 +579,7 @@ impl MarkerEnvironment {
///
/// See also [`MarkerEnvironment::platform_machine`].
#[inline]
#[must_use]
pub fn with_platform_machine(mut self, value: impl Into<String>) -> MarkerEnvironment {
Arc::make_mut(&mut self.inner).platform_machine = value.into();
self
@ -587,6 +590,7 @@ impl MarkerEnvironment {
///
/// See also [`MarkerEnvironment::platform_python_implementation`].
#[inline]
#[must_use]
pub fn with_platform_python_implementation(
mut self,
value: impl Into<String>,
@ -599,6 +603,7 @@ impl MarkerEnvironment {
///
/// See also [`MarkerEnvironment::platform_release`].
#[inline]
#[must_use]
pub fn with_platform_release(mut self, value: impl Into<String>) -> MarkerEnvironment {
Arc::make_mut(&mut self.inner).platform_release = value.into();
self
@ -608,6 +613,7 @@ impl MarkerEnvironment {
///
/// See also [`MarkerEnvironment::platform_system`].
#[inline]
#[must_use]
pub fn with_platform_system(mut self, value: impl Into<String>) -> MarkerEnvironment {
Arc::make_mut(&mut self.inner).platform_system = value.into();
self
@ -617,6 +623,7 @@ impl MarkerEnvironment {
///
/// See also [`MarkerEnvironment::platform_version`].
#[inline]
#[must_use]
pub fn with_platform_version(mut self, value: impl Into<String>) -> MarkerEnvironment {
Arc::make_mut(&mut self.inner).platform_version = value.into();
self
@ -626,6 +633,7 @@ impl MarkerEnvironment {
///
/// See also [`MarkerEnvironment::python_full_version`].
#[inline]
#[must_use]
pub fn with_python_full_version(
mut self,
value: impl Into<StringVersion>,
@ -638,6 +646,7 @@ impl MarkerEnvironment {
///
/// See also [`MarkerEnvironment::python_full_version`].
#[inline]
#[must_use]
pub fn with_python_version(mut self, value: impl Into<StringVersion>) -> MarkerEnvironment {
Arc::make_mut(&mut self.inner).python_version = value.into();
self
@ -647,6 +656,7 @@ impl MarkerEnvironment {
///
/// See also [`MarkerEnvironment::sys_platform`].
#[inline]
#[must_use]
pub fn with_sys_platform(mut self, value: impl Into<String>) -> MarkerEnvironment {
Arc::make_mut(&mut self.inner).sys_platform = value.into();
self
@ -1004,9 +1014,8 @@ impl MarkerExpression {
reporter.report(
MarkerWarningKind::Pep440Error,
format!(
"Expected double quoted PEP 440 version to compare with {}, found {},
will evaluate to false",
key, r_value
"Expected double quoted PEP 440 version to compare with {key}, found {r_value},
will evaluate to false"
),
);
@ -1166,8 +1175,7 @@ impl MarkerExpression {
reporter.report(
MarkerWarningKind::Pep440Error,
format!(
"Expected PEP 440 version to compare with {}, found {}, will evaluate to false: {}",
key, value, err
"Expected PEP 440 version to compare with {key}, found {value}, will evaluate to false: {err}"
),
);
@ -1219,8 +1227,7 @@ impl MarkerExpression {
reporter.report(
MarkerWarningKind::Pep440Error,
format!(
"Expected PEP 440 version to compare with {}, found {}, will evaluate to false: {}",
key, value, err
"Expected PEP 440 version to compare with {key}, found {value}, will evaluate to false: {err}"
),
);
@ -1232,9 +1239,8 @@ impl MarkerExpression {
reporter.report(
MarkerWarningKind::Pep440Error,
format!(
"Expected PEP 440 version operator to compare {} with '{}',
found '{}', will evaluate to false",
key, version, marker_operator
"Expected PEP 440 version operator to compare {key} with '{version}',
found '{marker_operator}', will evaluate to false"
),
);
@ -1267,17 +1273,16 @@ impl MarkerExpression {
}
};
match ExtraOperator::from_marker_operator(operator) {
Some(operator) => Some(MarkerExpression::Extra { operator, name }),
None => {
reporter.report(
MarkerWarningKind::ExtraInvalidComparison,
"Comparing extra with something other than a quoted string is wrong,
if let Some(operator) = ExtraOperator::from_marker_operator(operator) {
Some(MarkerExpression::Extra { operator, name })
} else {
reporter.report(
MarkerWarningKind::ExtraInvalidComparison,
"Comparing extra with something other than a quoted string is wrong,
will evaluate to false"
.to_string(),
);
None
}
.to_string(),
);
None
}
}
@ -1324,7 +1329,7 @@ impl MarkerExpression {
} => env
.map(|env| {
let l_string = env.get_string(key);
self.compare_strings(l_string, operator, value, reporter)
Self::compare_strings(l_string, *operator, value, reporter)
})
.unwrap_or(true),
MarkerExpression::StringInverted {
@ -1334,7 +1339,7 @@ impl MarkerExpression {
} => env
.map(|env| {
let r_string = env.get_string(key);
self.compare_strings(value, operator, r_string, reporter)
Self::compare_strings(value, *operator, r_string, reporter)
})
.unwrap_or(true),
MarkerExpression::Extra {
@ -1424,9 +1429,8 @@ impl MarkerExpression {
/// Compare strings by PEP 508 logic, with warnings
fn compare_strings(
&self,
l_string: &str,
operator: &MarkerOperator,
operator: MarkerOperator,
r_string: &str,
reporter: &mut impl Reporter,
) -> bool {
@ -1857,7 +1861,7 @@ impl MarkerTree {
let this = std::mem::replace(self, MarkerTree::And(vec![]));
*self = MarkerTree::And(vec![this]);
}
_ => {}
MarkerTree::And(_) => {}
}
if let MarkerTree::And(ref mut exprs) = *self {
if let MarkerTree::And(tree) = tree {
@ -1879,7 +1883,7 @@ impl MarkerTree {
let this = std::mem::replace(self, MarkerTree::And(vec![]));
*self = MarkerTree::Or(vec![this]);
}
_ => {}
MarkerTree::Or(_) => {}
}
if let MarkerTree::Or(ref mut exprs) = *self {
if let MarkerTree::Or(tree) = tree {
@ -1928,7 +1932,7 @@ impl Display for MarkerTree {
fn parse_marker_operator<T: Pep508Url>(
cursor: &mut Cursor,
) -> Result<MarkerOperator, Pep508Error<T>> {
let (start, len) = if cursor.peek_char().is_some_and(|c| c.is_alphabetic()) {
let (start, len) = if cursor.peek_char().is_some_and(char::is_alphabetic) {
// "in" or "not"
cursor.take_while(|char| !char.is_whitespace() && char != '\'' && char != '"')
} else {
@ -2301,7 +2305,7 @@ mod test {
assert_eq!(captured_logs[0].level, log::Level::Warn);
assert_eq!(captured_logs.len(), 1);
});
let string_string = MarkerTree::from_str(r#"os.name == 'posix' and platform.machine == 'x86_64' and platform.python_implementation == 'CPython' and 'Ubuntu' in platform.version and sys.platform == 'linux'"#).unwrap();
let string_string = MarkerTree::from_str(r"os.name == 'posix' and platform.machine == 'x86_64' and platform.python_implementation == 'CPython' and 'Ubuntu' in platform.version and sys.platform == 'linux'").unwrap();
string_string.evaluate(&env37, &[]);
testing_logger::validate(|captured_logs| {
let messages: Vec<_> = captured_logs

View file

@ -137,7 +137,7 @@ impl<Url: UnnamedRequirementUrl> Display for UnnamedRequirement<Url> {
)?;
}
if let Some(marker) = &self.marker {
write!(f, " ; {}", marker)?;
write!(f, " ; {marker}")?;
}
Ok(())
}

View file

@ -50,7 +50,7 @@ impl VerbatimUrl {
// Convert to a URL.
let mut url = Url::from_file_path(path.clone())
.map_err(|_| VerbatimUrlError::UrlConversion(path.to_path_buf()))?;
.map_err(|()| VerbatimUrlError::UrlConversion(path.to_path_buf()))?;
// Set the fragment, if it exists.
if let Some(fragment) = fragment {
@ -84,14 +84,14 @@ impl VerbatimUrl {
// Normalize the path.
let path = normalize_path(&path)
.map_err(|err| VerbatimUrlError::Normalization(path.to_path_buf(), err))?;
.map_err(|err| VerbatimUrlError::Normalization(path.clone(), err))?;
// Extract the fragment, if it exists.
let (path, fragment) = split_fragment(&path);
// Convert to a URL.
let mut url = Url::from_file_path(path.clone())
.map_err(|_| VerbatimUrlError::UrlConversion(path.to_path_buf()))?;
.map_err(|()| VerbatimUrlError::UrlConversion(path.to_path_buf()))?;
// Set the fragment, if it exists.
if let Some(fragment) = fragment {
@ -122,7 +122,7 @@ impl VerbatimUrl {
// Convert to a URL.
let mut url = Url::from_file_path(path.clone())
.unwrap_or_else(|_| panic!("path is absolute: {}", path.display()));
.unwrap_or_else(|()| panic!("path is absolute: {}", path.display()));
// Set the fragment, if it exists.
if let Some(fragment) = fragment {
@ -160,7 +160,7 @@ impl VerbatimUrl {
pub fn as_path(&self) -> Result<PathBuf, VerbatimUrlError> {
self.url
.to_file_path()
.map_err(|_| VerbatimUrlError::UrlConversion(self.url.to_file_path().unwrap()))
.map_err(|()| VerbatimUrlError::UrlConversion(self.url.to_file_path().unwrap()))
}
}