Skip to content

Commit

Permalink
Fix clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
cnpryer committed Feb 3, 2024
1 parent 4cb2100 commit c97fe31
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 33 deletions.
4 changes: 1 addition & 3 deletions crates/huak-package-manager/src/ops/toolchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,9 +551,7 @@ pub fn use_toolchain(channel: &Channel, config: &Config) -> HuakResult<()> {
}

fn resolve_installed_toolchains(config: &Config) -> Option<Vec<LocalToolchain>> {
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;
Expand Down
2 changes: 1 addition & 1 deletion crates/huak-package-manager/src/python_environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
6 changes: 1 addition & 5 deletions crates/huak-package-manager/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,7 @@ fn resolve_local_toolchain(
channel: Option<&Channel>,
) -> Option<LocalToolchain> {
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");

Expand Down
14 changes: 4 additions & 10 deletions crates/huak-pyproject-toml/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,10 @@ impl PyProjectToml {

#[must_use]
pub fn project_dependencies(&self) -> Option<Vec<String>> {
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
Expand Down Expand Up @@ -245,13 +242,10 @@ impl PyProjectToml {

#[must_use]
pub fn project_optional_dependencies(&self) -> Option<HashMap<String, Vec<String>>> {
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::<Vec<_>>();
Expand Down
28 changes: 14 additions & 14 deletions crates/huak-python-manager/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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"));
}
}

0 comments on commit c97fe31

Please sign in to comment.