@@ -472,3 +472,208 @@ func (li *LanguageInstaller) CheckLanguageForFile(fileType string) (bool, string
472472 return true , ""
473473 }
474474}
475+
476+ // GetPythonInstallCommand returns the appropriate command to install Python based on OS
477+ func (li * LanguageInstaller ) GetPythonInstallCommand () (string , string , error ) {
478+ switch runtime .GOOS {
479+ case "windows" :
480+ return "winget" , "winget install -e --id Python.Python.3.12" , nil
481+ case "darwin" :
482+ return "brew" , "brew install python@3.12" , nil
483+ case "linux" :
484+ // Try to detect package manager
485+ if _ , err := exec .LookPath ("apt" ); err == nil {
486+ return "apt" , "sudo apt update && sudo apt install -y python3 python3-venv python3-pip" , nil
487+ }
488+ if _ , err := exec .LookPath ("dnf" ); err == nil {
489+ return "dnf" , "sudo dnf install -y python3 python3-pip" , nil
490+ }
491+ if _ , err := exec .LookPath ("pacman" ); err == nil {
492+ return "pacman" , "sudo pacman -S --noconfirm python python-pip" , nil
493+ }
494+ return "manual" , "Download and install from https://www.python.org/downloads/" , nil
495+ default :
496+ return "" , "" , fmt .Errorf ("unsupported operating system: %s" , runtime .GOOS )
497+ }
498+ }
499+
500+ // InstallPython attempts to install Python using the appropriate method for the OS
501+ func (li * LanguageInstaller ) InstallPython () (string , error ) {
502+ switch runtime .GOOS {
503+ case "linux" :
504+ return li .InstallPythonLinux ()
505+ case "windows" :
506+ return li .InstallPythonWindows ()
507+ case "darwin" :
508+ return li .InstallPythonDarwin ()
509+ default :
510+ return "" , fmt .Errorf ("unsupported operating system: %s" , runtime .GOOS )
511+ }
512+ }
513+
514+ // InstallPythonWindows installs Python on Windows using winget
515+ func (li * LanguageInstaller ) InstallPythonWindows () (string , error ) {
516+ var output strings.Builder
517+ output .WriteString ("Starting Python installation for Windows...\n \n " )
518+ li .reportProgress ("🚀 Starting Python installation for Windows..." )
519+
520+ // Check if winget is available
521+ output .WriteString ("1. Checking for winget...\n " )
522+ li .reportProgress ("🔍 Checking for winget..." )
523+ checkCmd := exec .Command ("winget" , "--version" )
524+ if err := checkCmd .Run (); err != nil {
525+ return output .String (), fmt .Errorf ("winget is not installed or not in PATH" )
526+ }
527+ output .WriteString (" winget is available\n \n " )
528+ li .reportProgress ("✓ winget is available" )
529+
530+ // Install Python
531+ output .WriteString ("2. Installing Python via winget...\n " )
532+ li .reportProgress ("⬇️ Installing Python via winget... This may take a few minutes..." )
533+ cmd := exec .Command ("powershell" , "-NoProfile" , "-Command" , "winget install -e --id Python.Python.3.12" )
534+ cmdOutput , err := cmd .CombinedOutput ()
535+ output .WriteString (string (cmdOutput ))
536+
537+ if err != nil {
538+ return output .String (), fmt .Errorf ("installation failed: %w" , err )
539+ }
540+
541+ output .WriteString ("\n ✓ Python installation complete!\n " )
542+ output .WriteString ("\n IMPORTANT: Please restart Terminal Intelligence to update your PATH.\n " )
543+ li .reportProgress ("🎉 Python installation complete!" )
544+ li .reportProgress ("⚠️ IMPORTANT: Restart Terminal Intelligence to update PATH" )
545+
546+ return output .String (), nil
547+ }
548+
549+ // InstallPythonLinux installs Python on Linux using the system package manager
550+ func (li * LanguageInstaller ) InstallPythonLinux () (string , error ) {
551+ var output strings.Builder
552+ output .WriteString ("Starting Python installation for Linux...\n \n " )
553+ li .reportProgress ("🚀 Starting Python installation for Linux..." )
554+
555+ // Detect package manager
556+ output .WriteString ("1. Detecting package manager...\n " )
557+ li .reportProgress ("🔍 Detecting package manager..." )
558+
559+ var installCmd * exec.Cmd
560+ var pkgManager string
561+
562+ if _ , err := exec .LookPath ("apt" ); err == nil {
563+ pkgManager = "apt"
564+ output .WriteString (" Detected: apt (Debian/Ubuntu)\n \n " )
565+ li .reportProgress ("✓ Detected: apt (Debian/Ubuntu)" )
566+
567+ // Update package list
568+ output .WriteString ("2. Updating package list...\n " )
569+ li .reportProgress ("📡 Updating package list..." )
570+ updateCmd := exec .Command ("sudo" , "apt" , "update" )
571+ if updateOutput , err := updateCmd .CombinedOutput (); err != nil {
572+ output .WriteString (fmt .Sprintf (" Warning: apt update failed: %v\n " , err ))
573+ output .WriteString (string (updateOutput ))
574+ } else {
575+ output .WriteString (" Package list updated\n " )
576+ li .reportProgress ("✓ Package list updated" )
577+ }
578+ output .WriteString ("\n " )
579+
580+ output .WriteString ("3. Installing Python...\n " )
581+ li .reportProgress ("⬇️ Installing Python packages..." )
582+ installCmd = exec .Command ("sudo" , "apt" , "install" , "-y" , "python3" , "python3-venv" , "python3-pip" )
583+ } else if _ , err := exec .LookPath ("dnf" ); err == nil {
584+ pkgManager = "dnf"
585+ output .WriteString (" Detected: dnf (Fedora/RHEL)\n \n " )
586+ li .reportProgress ("✓ Detected: dnf (Fedora/RHEL)" )
587+
588+ output .WriteString ("2. Installing Python...\n " )
589+ li .reportProgress ("⬇️ Installing Python packages..." )
590+ installCmd = exec .Command ("sudo" , "dnf" , "install" , "-y" , "python3" , "python3-pip" )
591+ } else if _ , err := exec .LookPath ("pacman" ); err == nil {
592+ pkgManager = "pacman"
593+ output .WriteString (" Detected: pacman (Arch Linux)\n \n " )
594+ li .reportProgress ("✓ Detected: pacman (Arch Linux)" )
595+
596+ output .WriteString ("2. Installing Python...\n " )
597+ li .reportProgress ("⬇️ Installing Python packages..." )
598+ installCmd = exec .Command ("sudo" , "pacman" , "-S" , "--noconfirm" , "python" , "python-pip" )
599+ } else {
600+ return output .String (), fmt .Errorf ("no supported package manager found (apt, dnf, or pacman). Please install Python manually from https://www.python.org/downloads/" )
601+ }
602+
603+ _ = pkgManager // used for logging above
604+
605+ cmdOutput , err := installCmd .CombinedOutput ()
606+ output .WriteString (string (cmdOutput ))
607+
608+ if err != nil {
609+ return output .String (), fmt .Errorf ("installation failed: %w" , err )
610+ }
611+
612+ output .WriteString ("\n " )
613+
614+ // Verify installation
615+ output .WriteString ("4. Verifying installation...\n " )
616+ li .reportProgress ("🔍 Verifying installation..." )
617+
618+ verifyCmd := exec .Command ("python3" , "--version" )
619+ if verifyOutput , err := verifyCmd .Output (); err != nil {
620+ output .WriteString (fmt .Sprintf (" Warning: Could not verify: %v\n " , err ))
621+ li .reportProgress ("⚠️ Warning: Could not verify installation" )
622+ } else {
623+ versionOutput := strings .TrimSpace (string (verifyOutput ))
624+ output .WriteString (fmt .Sprintf (" %s\n " , versionOutput ))
625+ li .reportProgress (fmt .Sprintf ("✓ %s" , versionOutput ))
626+ }
627+ output .WriteString ("\n " )
628+
629+ output .WriteString ("✓ Python installation complete!\n " )
630+ li .reportProgress ("🎉 Python installation complete!" )
631+
632+ return output .String (), nil
633+ }
634+
635+ // InstallPythonDarwin installs Python on macOS using Homebrew
636+ func (li * LanguageInstaller ) InstallPythonDarwin () (string , error ) {
637+ var output strings.Builder
638+ output .WriteString ("Starting Python installation for macOS...\n \n " )
639+ li .reportProgress ("🚀 Starting Python installation for macOS..." )
640+
641+ // Check if brew is available
642+ output .WriteString ("1. Checking for Homebrew...\n " )
643+ li .reportProgress ("🔍 Checking for Homebrew..." )
644+ checkCmd := exec .Command ("brew" , "--version" )
645+ if err := checkCmd .Run (); err != nil {
646+ return output .String (), fmt .Errorf ("Homebrew is not installed. Install from: https://brew.sh" )
647+ }
648+ output .WriteString (" Homebrew is available\n \n " )
649+ li .reportProgress ("✓ Homebrew is available" )
650+
651+ // Update brew
652+ output .WriteString ("2. Updating Homebrew...\n " )
653+ li .reportProgress ("📡 Updating Homebrew..." )
654+ updateCmd := exec .Command ("brew" , "update" )
655+ if _ , err := updateCmd .CombinedOutput (); err != nil {
656+ output .WriteString (fmt .Sprintf (" Warning: brew update failed: %v\n " , err ))
657+ } else {
658+ output .WriteString (" Homebrew updated\n " )
659+ li .reportProgress ("✓ Homebrew updated" )
660+ }
661+ output .WriteString ("\n " )
662+
663+ // Install Python
664+ output .WriteString ("3. Installing Python via Homebrew...\n " )
665+ li .reportProgress ("⬇️ Installing Python via Homebrew... This may take a few minutes..." )
666+ cmd := exec .Command ("brew" , "install" , "python@3.12" )
667+ cmdOutput , err := cmd .CombinedOutput ()
668+ output .WriteString (string (cmdOutput ))
669+
670+ if err != nil {
671+ return output .String (), fmt .Errorf ("installation failed: %w" , err )
672+ }
673+
674+ output .WriteString ("\n ✓ Python installation complete!\n " )
675+ output .WriteString ("\n Python should now be available in your PATH.\n " )
676+ li .reportProgress ("🎉 Python installation complete!" )
677+
678+ return output .String (), nil
679+ }
0 commit comments