From ba2b1e31942db69810a86084368849e6ce16107f Mon Sep 17 00:00:00 2001 From: Chris Pryer <14341145+cnpryer@users.noreply.github.com> Date: Sat, 3 Feb 2024 17:14:37 -0500 Subject: [PATCH] Fix clippy lints and update pep440_rs and pep508_rs (#882) * Fix clippy lints * Typos * Update pep440_rs and pep508_rs --- Cargo.lock | 46 ++++++++++++------- Cargo.toml | 4 +- .../huak-package-manager/src/ops/toolchain.rs | 10 ++-- .../src/python_environment.rs | 2 +- crates/huak-package-manager/src/workspace.rs | 6 +-- crates/huak-pyproject-toml/src/lib.rs | 14 ++---- crates/huak-python-manager/src/install.rs | 28 +++++------ 7 files changed, 55 insertions(+), 55 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index eddcf5ab..51eaa910 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -590,7 +590,7 @@ dependencies = [ "huak-workspace", "indexmap 2.1.0", "lazy_static", - "pep440_rs", + "pep440_rs 0.4.0", "pep508_rs", "pyproject-toml", "regex", @@ -942,9 +942,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.18.0" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "openssl" @@ -1023,14 +1023,26 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "pep440_rs" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0c29f9c43de378b4e4e0cd7dbcce0e5cfb80443de8c05620368b2948bc936a1" +dependencies = [ + "once_cell", + "regex", + "serde", + "unicode-width", +] + [[package]] name = "pep508_rs" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4516b53d9ea6112ebb38b4af08d5707d30b994fb7f98ff133c5dcf7ed8fa854" +checksum = "aa9d1320b78f4a5715b3ec914f32b5e85a50287ad923730e3cbf0255259432eb" dependencies = [ "once_cell", - "pep440_rs", + "pep440_rs 0.4.0", "regex", "serde", "thiserror", @@ -1065,9 +1077,9 @@ checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" [[package]] name = "proc-macro2" -version = "1.0.69" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] @@ -1079,7 +1091,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "569e259cd132eb8cec5df8b672d187c5260f82ad352156b5da9549d4472e64b0" dependencies = [ "indexmap 2.1.0", - "pep440_rs", + "pep440_rs 0.3.12", "pep508_rs", "serde", "toml 0.7.8", @@ -1087,9 +1099,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.33" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -1238,18 +1250,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.192" +version = "1.0.196" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bca2a08484b285dcb282d0f67b26cadc0df8b19f8c12502c13d966bf9482f001" +checksum = "870026e60fa08c69f064aa766c10f10b1d62db9ccd4d0abb206472bee0ce3b32" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.192" +version = "1.0.196" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6c7207fbec9faa48073f3e3074cbe553af6ea512d7c21ba46e434e70ea9fbc1" +checksum = "33c85360c95e7d137454dc81d9a4ed2b8efd8fbe19cee57357b32b9771fccb67" dependencies = [ "proc-macro2", "quote", @@ -1342,9 +1354,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" -version = "2.0.39" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 35bfe12b..1579c40a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,8 +15,8 @@ glob = "0.3.1" hex = "0.4.3" human-panic = "1.1.5" lazy_static = "1.4.0" -pep440_rs = "0.3.11" -pep508_rs = "0.2.1" +pep440_rs = "0.4.0" +pep508_rs = "0.2.4" regex = "1.10.2" sha2 = "0.10.8" tempfile = "3.7.1" diff --git a/crates/huak-package-manager/src/ops/toolchain.rs b/crates/huak-package-manager/src/ops/toolchain.rs index 67d217b2..79f9c37f 100644 --- a/crates/huak-package-manager/src/ops/toolchain.rs +++ b/crates/huak-package-manager/src/ops/toolchain.rs @@ -23,7 +23,7 @@ use termcolor::Color; /// already installed to the toolchain, and a version is provided that's different from the /// installed tool, then replace the installed tool with the desired version. pub fn add_tool(tool: &LocalTool, channel: Option<&Channel>, config: &Config) -> HuakResult<()> { - // Resolve a toolchain if a channel is provided. Otherwise resolve the curerent. + // Resolve a toolchain if a channel is provided. Otherwise resolve the current. let toolchain = config.workspace().resolve_local_toolchain(channel)?; add_tool_to_toolchain(tool, &toolchain, config) @@ -360,7 +360,7 @@ pub fn remove_tool(tool: &LocalTool, channel: Option<&Channel>, config: &Config) unimplemented!() } - // Resolve a toolchain if a channel is provided. Otherwise resolve the curerent. + // Resolve a toolchain if a channel is provided. Otherwise resolve the current. let toolchain = config.workspace().resolve_local_toolchain(channel)?; let venv = PythonEnvironment::new(toolchain.root().join(".venv"))?; @@ -492,7 +492,7 @@ pub fn update_toolchain( channel: Option<&Channel>, config: &Config, ) -> HuakResult<()> { - // Resolve a toolchain if a channel is provided. Otherwise resolve the curerent. + // Resolve a toolchain if a channel is provided. Otherwise resolve the current. let toolchain = config.workspace().resolve_local_toolchain(channel)?; let mut terminal = config.terminal(); @@ -551,9 +551,7 @@ pub fn use_toolchain(channel: &Channel, config: &Config) -> HuakResult<()> { } fn resolve_installed_toolchains(config: &Config) -> Option> { - let Some(home) = config.home.clone() else { - return None; - }; + let home = config.home.clone()?; let Ok(toolchains) = std::fs::read_dir(home.join("toolchains")) else { return None; diff --git a/crates/huak-package-manager/src/python_environment.rs b/crates/huak-package-manager/src/python_environment.rs index 0f69c45d..e666d926 100644 --- a/crates/huak-package-manager/src/python_environment.rs +++ b/crates/huak-package-manager/src/python_environment.rs @@ -655,7 +655,7 @@ mod tests { fn python_search() { let dir = tempdir().unwrap(); std::fs::write(dir.path().join("python3.11"), "").unwrap(); - let path_vals = vec![dir.path().to_str().unwrap().to_string()]; + let path_vals = [dir.path().to_str().unwrap().to_string()]; std::env::set_var("PATH", path_vals.join(":")); let mut interpreter_paths = python_paths(); diff --git a/crates/huak-package-manager/src/workspace.rs b/crates/huak-package-manager/src/workspace.rs index 11863a30..f1e0a4ed 100644 --- a/crates/huak-package-manager/src/workspace.rs +++ b/crates/huak-package-manager/src/workspace.rs @@ -199,11 +199,7 @@ fn resolve_local_toolchain( channel: Option<&Channel>, ) -> Option { let config = &workspace.config; - - let Some(home) = config.home.as_ref() else { - return None; - }; - + let home = config.home.as_ref()?; let toolchains = home.join("toolchains"); let settings = toolchains.join("settings.toml"); diff --git a/crates/huak-pyproject-toml/src/lib.rs b/crates/huak-pyproject-toml/src/lib.rs index fddf1dcf..f2a87070 100644 --- a/crates/huak-pyproject-toml/src/lib.rs +++ b/crates/huak-pyproject-toml/src/lib.rs @@ -184,13 +184,10 @@ impl PyProjectToml { #[must_use] pub fn project_dependencies(&self) -> Option> { - let Some(array) = self + let array = self .project_table() .and_then(|it| it.get("dependencies")) - .and_then(Item::as_array) - else { - return None; - }; + .and_then(Item::as_array)?; Some( array @@ -245,13 +242,10 @@ impl PyProjectToml { #[must_use] pub fn project_optional_dependencies(&self) -> Option>> { - let Some(table) = self + let table = self .project_table() .and_then(|it| it.get("optional-dependencies")) - .and_then(Item::as_table) - else { - return None; - }; + .and_then(Item::as_table)?; let mut deps = HashMap::new(); let groups = table.iter().map(|(k, _)| k).collect::>(); diff --git a/crates/huak-python-manager/src/install.rs b/crates/huak-python-manager/src/install.rs index 6fefc8b1..329a14d8 100644 --- a/crates/huak-python-manager/src/install.rs +++ b/crates/huak-python-manager/src/install.rs @@ -168,24 +168,24 @@ mod tests { let py = bin.join("python"); let py3 = bin.join("python3"); let py312 = bin.join("python3.12"); - let pys = [py.clone(), py3, py312]; + let pythons = [py.clone(), py3, py312]; let module = bin.join("module"); std::fs::create_dir_all(&bin).unwrap(); - for file in pys.iter().chain([&module]) { + for file in pythons.iter().chain([&module]) { let mut file = File::create(file).unwrap(); file.write_all(&[]).unwrap(); } let release_dir = PythonReleaseDir::new(dir); - let ibin = release_dir.bin_path(); - let ipy = ibin.join("python"); + let release_bin = release_dir.bin_path(); + let release_py = release_bin.join("python"); - assert_eq!(bin, ibin); - assert_eq!(py, ipy); - assert_eq!(module, ibin.join("module")); + assert_eq!(bin, release_bin); + assert_eq!(py, release_py); + assert_eq!(module, release_bin.join("module")); } #[cfg(windows)] @@ -197,23 +197,23 @@ mod tests { let parent = dir.join("install"); let bin = parent.join("Scripts"); let py = parent.join("python.exe"); - let pys = [py.clone()]; + let pythons = [py.clone()]; let module = bin.join("module.exe"); std::fs::create_dir_all(&bin).unwrap(); - for file in pys.iter().chain([&module]) { + for file in pythons.iter().chain([&module]) { let mut file = File::create(file).unwrap(); file.write_all(&[]).unwrap(); } let release_dir = PythonReleaseDir::new(dir); - let ibin = release_dir.bin_path(); - let ipy = release_dir.python_path(None); + let release_bin = release_dir.bin_path(); + let release_py = release_dir.python_path(None); - assert_eq!(bin, ibin); - assert_eq!(py, ipy); - assert_eq!(module, ibin.join("module.exe")); + assert_eq!(bin, release_bin); + assert_eq!(py, release_py); + assert_eq!(module, release_bin.join("module.exe")); } }