|
17 | 17 | import os |
18 | 18 | import pathlib |
19 | 19 | import shutil |
| 20 | +import subprocess |
20 | 21 | import sys |
21 | 22 | import tempfile |
22 | 23 | from dataclasses import dataclass |
|
25 | 26 | import yaml |
26 | 27 | from cookiecutter.main import cookiecutter |
27 | 28 | from rich.console import Console |
28 | | -from rich.prompt import IntPrompt, Prompt |
| 29 | +from rich.prompt import Confirm, IntPrompt, Prompt |
29 | 30 |
|
30 | 31 | from agent_starter_pack.cli.utils.version import get_current_version |
31 | 32 |
|
|
36 | 37 | ) |
37 | 38 |
|
38 | 39 |
|
| 40 | +def add_base_template_dependencies_interactively( |
| 41 | + project_path: pathlib.Path, |
| 42 | + base_dependencies: list[str], |
| 43 | + base_template_name: str, |
| 44 | + auto_approve: bool = False, |
| 45 | +) -> bool: |
| 46 | + """Interactively add base template dependencies using uv add. |
| 47 | +
|
| 48 | + Args: |
| 49 | + project_path: Path to the project directory |
| 50 | + base_dependencies: List of dependencies from base template's extra_dependencies |
| 51 | + base_template_name: Name of the base template being used |
| 52 | + auto_approve: Whether to skip confirmation and auto-install |
| 53 | +
|
| 54 | + Returns: |
| 55 | + True if dependencies were added successfully, False otherwise |
| 56 | + """ |
| 57 | + if not base_dependencies: |
| 58 | + return True |
| 59 | + |
| 60 | + console = Console() |
| 61 | + |
| 62 | + # Construct dependency string once for reuse |
| 63 | + deps_str = " ".join(f"'{dep}'" for dep in base_dependencies) |
| 64 | + |
| 65 | + # Show what dependencies will be added |
| 66 | + console.print( |
| 67 | + f"\n✓ Base template override: Using '{base_template_name}' as foundation", |
| 68 | + style="bold cyan", |
| 69 | + ) |
| 70 | + console.print(" This requires adding the following dependencies:", style="white") |
| 71 | + for dep in base_dependencies: |
| 72 | + console.print(f" • {dep}", style="yellow") |
| 73 | + |
| 74 | + # Ask for confirmation unless auto-approve |
| 75 | + should_add = True |
| 76 | + if not auto_approve: |
| 77 | + should_add = Confirm.ask( |
| 78 | + "\n? Add these dependencies automatically?", default=True |
| 79 | + ) |
| 80 | + |
| 81 | + if not should_add: |
| 82 | + console.print("\n⚠️ Skipped dependency installation.", style="yellow") |
| 83 | + console.print(" To add them manually later, run:", style="dim") |
| 84 | + console.print(f" cd {project_path.name}", style="dim") |
| 85 | + console.print(f" uv add {deps_str}\n", style="dim") |
| 86 | + return False |
| 87 | + |
| 88 | + # Run uv add |
| 89 | + try: |
| 90 | + if auto_approve: |
| 91 | + console.print( |
| 92 | + f"✓ Auto-installing dependencies: {', '.join(base_dependencies)}", |
| 93 | + style="bold cyan", |
| 94 | + ) |
| 95 | + else: |
| 96 | + console.print(f"\n✓ Running: uv add {deps_str}", style="bold cyan") |
| 97 | + |
| 98 | + # Run uv add in the project directory |
| 99 | + cmd = ["uv", "add"] + base_dependencies |
| 100 | + result = subprocess.run( |
| 101 | + cmd, |
| 102 | + cwd=project_path, |
| 103 | + capture_output=True, |
| 104 | + text=True, |
| 105 | + check=True, |
| 106 | + ) |
| 107 | + |
| 108 | + # Show success message |
| 109 | + if not auto_approve: |
| 110 | + # Show a summary line from uv output |
| 111 | + output_lines = result.stderr.strip().split("\n") |
| 112 | + for line in output_lines: |
| 113 | + if "Resolved" in line or "Installed" in line: |
| 114 | + console.print(f" {line}", style="dim") |
| 115 | + break |
| 116 | + |
| 117 | + console.print("✓ Dependencies added successfully\n", style="bold green") |
| 118 | + return True |
| 119 | + |
| 120 | + except subprocess.CalledProcessError as e: |
| 121 | + console.print( |
| 122 | + f"\n✗ Failed to add dependencies: {e.stderr.strip()}", style="bold red" |
| 123 | + ) |
| 124 | + console.print(" You can add them manually:", style="yellow") |
| 125 | + console.print(f" cd {project_path.name}", style="dim") |
| 126 | + console.print(f" uv add {deps_str}\n", style="dim") |
| 127 | + return False |
| 128 | + except FileNotFoundError: |
| 129 | + console.print( |
| 130 | + "\n✗ uv command not found. Please install uv first.", style="bold red" |
| 131 | + ) |
| 132 | + console.print(" Install from: https://docs.astral.sh/uv/", style="dim") |
| 133 | + console.print("\n To add dependencies manually:", style="yellow") |
| 134 | + console.print(f" cd {project_path.name}", style="dim") |
| 135 | + console.print(f" uv add {deps_str}\n", style="dim") |
| 136 | + return False |
| 137 | + |
| 138 | + |
39 | 139 | def validate_agent_directory_name(agent_dir: str) -> None: |
40 | 140 | """Validate that an agent directory name is a valid Python identifier. |
41 | 141 |
|
|
0 commit comments