From b672a1dffe86624d30109be714a90dd3bc2137d1 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Thu, 25 Jul 2024 14:30:05 -0400 Subject: [PATCH] Always write --index-url before --extra-index-url --- rye/src/cli/add.rs | 2 +- rye/src/cli/rye.rs | 2 +- rye/src/installer.rs | 4 ++-- rye/src/pyproject.rs | 47 +++++++++++++++++++++++++++++--------------- 4 files changed, 35 insertions(+), 20 deletions(-) diff --git a/rye/src/cli/add.rs b/rye/src/cli/add.rs index 9fa56f2ad2..fc538b5b91 100644 --- a/rye/src/cli/add.rs +++ b/rye/src/cli/add.rs @@ -445,7 +445,7 @@ fn find_best_matches_with_unearth( Some(ver) => ver.format_simple(), None => "".into(), }) - .arg(&format_requirement(requirement).to_string()) + .arg(format_requirement(requirement).to_string()) .arg(serde_json::to_string(&sources)?); if pre { unearth.arg("--pre"); diff --git a/rye/src/cli/rye.rs b/rye/src/cli/rye.rs index b744bb0b7c..e1891297d7 100644 --- a/rye/src/cli/rye.rs +++ b/rye/src/cli/rye.rs @@ -454,7 +454,7 @@ fn uninstall(args: UninstallCommand) -> Result<(), Error> { let shim_dir = app_dir.join("shims"); if let Ok(dir) = shim_dir.read_dir() { for entry in dir.flatten() { - fs::remove_file(&entry.path()).ok(); + fs::remove_file(entry.path()).ok(); } } diff --git a/rye/src/installer.rs b/rye/src/installer.rs index 55fd8f4e51..d34fa9d60c 100644 --- a/rye/src/installer.rs +++ b/rye/src/installer.rs @@ -180,7 +180,7 @@ pub fn install( } cmd.env("PYTHONWARNINGS", "ignore"); } - cmd.arg("--").arg(&requirement.to_string()); + cmd.arg("--").arg(requirement.to_string()); // we don't support versions below 3.7, but for 3.7 we need importlib-metadata // to be installed @@ -410,7 +410,7 @@ fn uninstall_helper(target_venv_path: &Path, shim_dir: &Path) -> Result<(), Erro let script = script?; if let Some(base_name) = script.path().file_name() { let shim_path = shim_dir.join(base_name); - if let Ok(true) = is_same_file(&shim_path, &script.path()) { + if let Ok(true) = is_same_file(&shim_path, script.path()) { fs::remove_file(&shim_path).ok(); } } diff --git a/rye/src/pyproject.rs b/rye/src/pyproject.rs index d1865bd92f..34dcd5c41e 100644 --- a/rye/src/pyproject.rs +++ b/rye/src/pyproject.rs @@ -1421,17 +1421,25 @@ impl ExpandedSources { /// Attach common pip args to a command. pub fn add_as_pip_args(&self, cmd: &mut Command) { - for (url, default) in self.index_urls.iter() { - if *default { - cmd.arg("--index-url"); - } else { - cmd.arg("--extra-index-url"); - } - cmd.arg(&url.to_string()); + for url in self + .index_urls + .iter() + .filter_map(|(url, default)| if *default { Some(url) } else { None }) + { + cmd.arg("--index-url"); + cmd.arg(url.to_string()); + } + for url in self + .index_urls + .iter() + .filter_map(|(url, default)| if *default { None } else { Some(url) }) + { + cmd.arg("--extra-index-url"); + cmd.arg(url.to_string()); } for link in &self.find_links { cmd.arg("--find-links"); - cmd.arg(&link.to_string()); + cmd.arg(link.to_string()); } for host in &self.trusted_hosts { cmd.arg("--trusted-host"); @@ -1441,18 +1449,25 @@ impl ExpandedSources { /// Write the sources to a lockfile. pub fn add_to_lockfile(&self, out: &mut dyn std::io::Write) -> std::io::Result<()> { - for (url, default) in self.index_urls.iter() { - if *default { - writeln!(out, "--index-url {}", url)?; - } else { - writeln!(out, "--extra-index-url {}", url)?; - } + for url in self + .index_urls + .iter() + .filter_map(|(url, default)| if *default { Some(url) } else { None }) + { + writeln!(out, "--index-url {url}")?; + } + for url in self + .index_urls + .iter() + .filter_map(|(url, default)| if *default { None } else { Some(url) }) + { + writeln!(out, "--extra-index-url {url}")?; } for link in &self.find_links { - writeln!(out, "--find-links {}", link)?; + writeln!(out, "--find-links {link}")?; } for host in &self.trusted_hosts { - writeln!(out, "--trusted-host {}", host)?; + writeln!(out, "--trusted-host {host}")?; } Ok(()) }