Skip to content

Commit c9eb3e9

Browse files
committed
clippy
1 parent f7eedcc commit c9eb3e9

File tree

5 files changed

+34
-42
lines changed

5 files changed

+34
-42
lines changed

src/config.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -256,21 +256,12 @@ impl Anysnake2 {
256256
}
257257
}
258258

259-
#[derive(Deserialize, Debug)]
259+
#[derive(Deserialize, Debug, Default)]
260260
pub struct DevShell {
261261
pub inputs: Option<Vec<String>>,
262262
pub shell: Option<String>,
263263
}
264264

265-
impl Default for DevShell {
266-
fn default() -> Self {
267-
DevShell {
268-
inputs: None,
269-
shell: None,
270-
}
271-
}
272-
}
273-
274265
#[derive(Deserialize, Debug)]
275266
pub struct TofuDevShell {
276267
pub inputs: Vec<String>,
@@ -426,9 +417,9 @@ impl TofuPythonPackageSource {
426417

427418
#[cfg(test)]
428419
mod test {
429-
use serde_json::json;
420+
430421

431-
use crate::{config::remove_username_from_url, vcs::{TofuVCS}};
422+
432423

433424

434425

@@ -494,6 +485,7 @@ impl<'de> Deserialize<'de> for StrOrHashMap {
494485
}
495486

496487
impl<'de> Deserialize<'de> for PythonPackageDefinition {
488+
#[allow(clippy::too_many_lines)]
497489
fn deserialize<D>(deserializer: D) -> StdResult<Self, D::Error>
498490
where
499491
D: Deserializer<'de>,

src/flake_writer.rs

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ pub fn write_flake(
108108
//
109109
////todo: does rust even need to be a special case?
110110
add_jupyter_kernels(
111-
&parsed_config,
111+
parsed_config,
112112
&mut definitions,
113113
&mut nixpkgs_pkgs,
114114
&mut rust_extensions,
@@ -207,7 +207,7 @@ pub fn write_flake(
207207
&flake_filename,
208208
flake_dir,
209209
)?;
210-
res = res | python_locks_changed;
210+
res |= python_locks_changed;
211211

212212
run_git_add(&git_tracked_files, flake_dir)?;
213213
run_git_commit(flake_dir)?; //after nix 2.23 we will need to commit the flake, possibly. At
@@ -293,7 +293,7 @@ fn insert_allow_unfree(
293293
"\"%PERMITTED_INSECURE_PACKAGES%\"",
294294
&(permitted_insecure_packages
295295
.as_ref()
296-
.map_or_else(|| String::new(), |x| x.join(" "))),
296+
.map_or_else(String::new, |x| x.join(" "))),
297297
)
298298
}
299299

@@ -304,18 +304,14 @@ fn add_jupyter_kernels(
304304
rust_extensions: &mut Vec<String>,
305305
) {
306306
let mut jupyter_kernels = String::new();
307-
let jupyter_included = parsed_config
308-
.python
309-
.as_ref()
310-
.map(|p| {
311-
p.packages
312-
.iter()
313-
.any(|(k, _)| k == "jupyter" || k == "notebook" || k == "jupyterlab")
314-
})
315-
.unwrap_or(false);
307+
let jupyter_included = parsed_config.python.as_ref().is_some_and(|p| {
308+
p.packages
309+
.iter()
310+
.any(|(k, _)| k == "jupyter" || k == "notebook" || k == "jupyterlab")
311+
});
316312
if let Some(r) = &parsed_config.r {
317313
// install R kernel
318-
if jupyter_included && r.packages.iter().any(|x| x == "IRkernel") && jupyter_included {
314+
if jupyter_included && r.packages.iter().any(|x| x == "IRkernel") {
319315
jupyter_kernels.push_str(
320316
"
321317
mkdir $out/share/jupyter/kernels/R
@@ -347,12 +343,13 @@ fn add_jupyter_kernels(
347343
.to_string()
348344
+ &jupyter_kernels;
349345
}
350-
if jupyter_included && !jupyter_kernels.is_empty(){
346+
if jupyter_included && !jupyter_kernels.is_empty() {
351347
definitions.insert(
352348
"zzz_jupyter_kernel_drv".to_string(),
353349
"pkgs.runCommand \"anysnake2-jupyter-kernels\" {} ''
354350
mkdir -p $out/share/jupyter/kernels
355-
".to_string()
351+
"
352+
.to_string()
356353
+ &jupyter_kernels
357354
+ "''",
358355
);
@@ -534,8 +531,7 @@ fn copy_for_poetry(
534531
) -> Result<String> {
535532
let pre_poetry_patch_sha = pre_poetry_patch
536533
.as_ref()
537-
.map(|x| sha256::digest(x))
538-
.unwrap_or_else(|| "None".to_string());
534+
.map_or_else(|| "None".to_string(), sha256::digest);
539535

540536
let target_path = pyproject_toml_path
541537
.parent()
@@ -1131,6 +1127,7 @@ fn format_poetry_build_input_overrides(
11311127
}
11321128

11331129
#[allow(clippy::too_many_arguments)]
1130+
#[allow(clippy::too_many_lines)]
11341131
fn add_python(
11351132
parsed_config: &mut config::TofuConfigToml,
11361133
inputs: &mut Vec<InputFlake>,
@@ -1148,9 +1145,9 @@ fn add_python(
11481145
match &mut parsed_config.python {
11491146
Some(python) => {
11501147
let original_pyproject_toml =
1151-
ex::fs::read_to_string(pyproject_toml_path).unwrap_or_else(|_| "".to_string());
1148+
ex::fs::read_to_string(pyproject_toml_path).unwrap_or_else(|_| String::new());
11521149
let original_poetry_lock =
1153-
ex::fs::read_to_string(poetry_lock_path).unwrap_or_else(|_| "".to_string());
1150+
ex::fs::read_to_string(poetry_lock_path).unwrap_or_else(|_| String::new());
11541151

11551152
if !Regex::new(r"^\d+\.\d+$").unwrap().is_match(&python.version) {
11561153
bail!(
@@ -1255,9 +1252,9 @@ fn add_python(
12551252
git_tracked_files.push("poetry_rewritten/poetry.lock".to_string());
12561253
git_tracked_files.push("poetry_rewritten/pyproject.toml".to_string());
12571254
let new_pyproject_toml =
1258-
ex::fs::read_to_string(pyproject_toml_path).unwrap_or_else(|_| "".to_string());
1255+
ex::fs::read_to_string(pyproject_toml_path).unwrap_or_else(|_| String::new());
12591256
let new_poetry_lock =
1260-
ex::fs::read_to_string(poetry_lock_path).unwrap_or_else(|_| "".to_string());
1257+
ex::fs::read_to_string(poetry_lock_path).unwrap_or_else(|_| String::new());
12611258
if new_pyproject_toml != original_pyproject_toml
12621259
|| new_poetry_lock != original_poetry_lock
12631260
{

src/tofu.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ trait Tofu<A> {
2222
}
2323

2424
impl Tofu<config::TofuConfigToml> for config::ConfigToml {
25+
#[allow(clippy::too_many_lines)]
2526
fn tofu(self, updates: &mut TomlUpdates) -> Result<config::TofuConfigToml> {
2627
let converted_clone_regexps = match self.clone_regexps {
2728
Some(cr) => Some(clone_regex_strings_to_regex(cr)?),
@@ -388,6 +389,7 @@ impl TofuToNewest<Option<config::TofuRust>> for Option<config::Rust> {
388389
None => None,
389390
Some(rust) => {
390391
let url = tofu_repo_to_newest(&url_toml_name, updates, rust.url, default_url)?;
392+
#[allow(clippy::single_match_else)]
391393
let version = match rust.version {
392394
Some(v) => v,
393395
None => {
@@ -402,7 +404,7 @@ impl TofuToNewest<Option<config::TofuRust>> for Option<config::Rust> {
402404
let rust = json["packages"]["x86_64-linux"]["default"]["name"]
403405
.as_str()
404406
.context("Could not find default version in flake show")?;
405-
let actual_version = rust.split("-").last().context("rust version naming scheme changed, expected something like 'rust-default-1.81.0?'")?;
407+
let actual_version = rust.split('-').last().context("rust version naming scheme changed, expected something like 'rust-default-1.81.0?'")?;
406408
debug!("Found version: {actual_version}");
407409
actual_version.to_string()
408410
}
@@ -431,6 +433,7 @@ impl TofuToNewest<Option<config::TofuR>> for Option<config::R> {
431433
Some(inner_self) => {
432434
let url =
433435
tofu_repo_to_newest(&ref_url_toml_name, updates, inner_self.url, default_url)?;
436+
#[allow(clippy::single_match_else)]
434437
let date = match inner_self.date {
435438
Some(date) => date,
436439
None => {
@@ -477,11 +480,11 @@ fn find_newest_nixr_date(url: &TofuVCS) -> Result<String> {
477480
.find_iter(&text)
478481
.map(|x| x.as_str())
479482
.collect::<Vec<_>>();
480-
all_dates.sort();
483+
all_dates.sort_unstable();
481484
let last_date = all_dates
482485
.last()
483486
.with_context(|| format!("Could not find dates on {url}"))?;
484-
Ok(last_date.to_string())
487+
Ok((*last_date).to_string())
485488
}
486489
_ => {
487490
bail!("Only know how to determite newest date for R from nixR github, not from other VCS. Add it manually, please");

src/vcs.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::{borrow::Cow, collections::HashMap};
22

33
use anyhow::{bail, Context, Result};
44
use log::{debug, error};
5-
use serde::{Serialize, Serializer};
5+
use serde::{Serialize};
66
use version_compare::Version;
77

88
use crate::{
@@ -143,7 +143,7 @@ impl TofuVCS {
143143
run_without_ctrl_c(|| {
144144
let inner = || {
145145
let mut proc = std::process::Command::new("hg");
146-
proc.args(["clone", &url, target_dir]);
146+
proc.args(["clone", url, target_dir]);
147147
debug!("Running {:?}", proc);
148148
let status = proc
149149
.status()
@@ -152,7 +152,7 @@ impl TofuVCS {
152152
bail!("hg clone failed for {self}");
153153
}
154154
let mut proc = std::process::Command::new("hg");
155-
proc.args(["checkout", &rev]);
155+
proc.args(["checkout", rev]);
156156
proc.current_dir(target_dir);
157157
debug!("Running {:?}", proc);
158158
let status = proc
@@ -900,7 +900,7 @@ mod test {
900900
branch: "main".to_string(),
901901
rev: "123".to_string(),
902902
};
903-
let str_vcs = format!("{}", git_vcs);
903+
let str_vcs = git_vcs.to_string();
904904
assert!(str_vcs.contains("https://example.com"));
905905
assert!(!str_vcs.contains("user:password"));
906906
}
@@ -911,7 +911,7 @@ mod test {
911911
url: "https://user:password@example.com".to_string(),
912912
rev: "123".to_string(),
913913
};
914-
let str_vcs = format!("{}", git_vcs);
914+
let str_vcs = git_vcs.to_string();
915915
dbg!(&str_vcs);
916916
assert!(str_vcs.contains("https://example.com"));
917917
assert!(!str_vcs.contains("user:password"));

tests/integration_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ fn test_empty() {
672672
run_test_tempdir("examples/test_empty", &["run", "--", "bash", "--version"]);
673673
assert!(stdout.contains("GNU bash"));
674674
let generated_anysnake2_toml = td.path().join("anysnake2.toml");
675-
let read = ex::fs::read_to_string(&generated_anysnake2_toml).unwrap();
675+
let read = ex::fs::read_to_string(generated_anysnake2_toml).unwrap();
676676
let parsed_toml = read.parse::<toml_edit::DocumentMut>().unwrap();
677677
assert!(parsed_toml.contains_key("anysnake2"));
678678
assert!(parsed_toml["anysnake2"]["rev"].as_str().is_some());

0 commit comments

Comments
 (0)