syncable_cli/analyzer/tool_management/installers/
python.rs1use crate::analyzer::tool_management::ToolDetector;
2use crate::error::Result;
3use super::common::InstallationUtils;
4use std::collections::HashMap;
5use log::{info, warn, debug};
6
7pub fn install_pip_audit(
9 tool_detector: &mut ToolDetector,
10 installed_tools: &mut HashMap<String, bool>,
11) -> Result<()> {
12 if tool_detector.detect_tool("pip-audit").available {
13 return Ok(());
14 }
15
16 info!("🔧 Installing pip-audit for Python vulnerability scanning...");
17
18 let install_commands = vec![
20 ("pipx", vec!["install", "pip-audit"]),
21 ("pip3", vec!["install", "--user", "pip-audit"]),
22 ("pip", vec!["install", "--user", "pip-audit"]),
23 ];
24
25 for (cmd, args) in install_commands {
26 debug!("Trying installation command: {} {}", cmd, args.join(" "));
27
28 if InstallationUtils::is_command_available(cmd) {
29 if let Ok(success) = InstallationUtils::execute_command(cmd, &args.iter().map(|s| *s).collect::<Vec<_>>()) {
30 if success {
31 info!("✅ pip-audit installed successfully using {}", cmd);
32 installed_tools.insert("pip-audit".to_string(), true);
33 tool_detector.clear_cache();
34 return Ok(());
35 }
36 }
37 }
38 }
39
40 warn!("📦 Failed to auto-install pip-audit. Please install manually:");
41 warn!(" Option 1: pipx install pip-audit");
42 warn!(" Option 2: pip3 install --user pip-audit");
43
44 Ok(()) }