|
5 | 5 |
|
6 | 6 | import asyncio |
7 | 7 | from pathlib import Path |
8 | | -import sys |
9 | 8 | from typing import Literal |
10 | 9 | from fastmcp import Context |
11 | | -import requests |
12 | 10 | import os |
13 | | -import subprocess as sp |
| 11 | +import shutil |
| 12 | +import sys |
14 | 13 | from models import AAZRequest |
15 | 14 |
|
16 | 15 | paths = { |
@@ -53,7 +52,7 @@ async def validate_paths(ctx: Context) -> dict: |
53 | 52 | response_type=Literal["yes", "no"] |
54 | 53 | ) |
55 | 54 |
|
56 | | - if check_result.action == "reject": |
| 55 | + if check_result.action != "accept": |
57 | 56 | return None |
58 | 57 |
|
59 | 58 | if check_result.data == "no": |
@@ -221,22 +220,72 @@ async def run_command(ctx: Context, command: str, step_name: str, progress_start |
221 | 220 | await ctx.report_progress(progress_end, 100) |
222 | 221 | await ctx.info(f"az_cli : Completed: {step_name}") |
223 | 222 |
|
| 223 | + |
| 224 | +def _resolve_python_candidates() -> list[str]: |
| 225 | + candidates = [] |
| 226 | + venv = os.environ.get("VIRTUAL_ENV") |
| 227 | + if venv: |
| 228 | + candidates.append(str(Path(venv) / "bin" / "python")) |
| 229 | + ws_venv_python = Path("/workspaces/.venv/bin/python") |
| 230 | + if ws_venv_python.exists(): |
| 231 | + candidates.append(str(ws_venv_python)) |
| 232 | + if sys.executable: |
| 233 | + candidates.append(sys.executable) |
| 234 | + for name in ("python3", "python"): |
| 235 | + p = shutil.which(name) |
| 236 | + if p: |
| 237 | + candidates.append(p) |
| 238 | + deduped = [] |
| 239 | + seen = set() |
| 240 | + for c in candidates: |
| 241 | + if c not in seen: |
| 242 | + deduped.append(c) |
| 243 | + seen.add(c) |
| 244 | + return deduped |
| 245 | + |
| 246 | + |
| 247 | +def _resolve_aaz_dev_prefix() -> str: |
| 248 | + for py in _resolve_python_candidates(): |
| 249 | + try: |
| 250 | + import subprocess |
| 251 | + code = ( |
| 252 | + "import importlib.util, sys; " |
| 253 | + "spec = importlib.util.find_spec('aaz_dev.__main__'); " |
| 254 | + "sys.exit(0 if spec else 1)" |
| 255 | + ) |
| 256 | + res = subprocess.run([py, "-c", code], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) |
| 257 | + if res.returncode == 0: |
| 258 | + return f"{py} -m aaz_dev" |
| 259 | + except Exception: |
| 260 | + pass |
| 261 | + for maybe in [ |
| 262 | + "/workspaces/.venv/bin/aaz-dev", |
| 263 | + str(Path(os.environ.get("VIRTUAL_ENV", "")) / "bin" / "aaz-dev") if os.environ.get("VIRTUAL_ENV") else None, |
| 264 | + shutil.which("aaz-dev") |
| 265 | + ]: |
| 266 | + if maybe and os.path.exists(maybe): |
| 267 | + return maybe |
| 268 | + return "aaz-dev" |
| 269 | + |
224 | 270 | async def execute_commands(ctx: Context, paths: dict, request: AAZRequest): |
| 271 | + aaz_dev = _resolve_aaz_dev_prefix() |
| 272 | + await ctx.info(f"az_cli : Using aaz-dev invocation: {aaz_dev}") |
| 273 | + |
225 | 274 | cmd1 = ( |
226 | | - f"aaz-dev command-model generate-from-swagger " |
| 275 | + f"{aaz_dev} command-model generate-from-swagger " |
227 | 276 | f"-a {paths['aaz']} " |
228 | 277 | f"--sm {request.swagger_module_path} " |
229 | | - f"-m {request.extension_or_module_name} " |
| 278 | + f"-m {request.name} " |
230 | 279 | f"--rp {request.resource_provider} " |
231 | 280 | f"--swagger-tag {request.swagger_tag}" |
232 | 281 | ) |
233 | 282 |
|
234 | 283 | cmd2 = ( |
235 | | - f"aaz-dev cli generate-by-swagger-tag " |
| 284 | + f"{aaz_dev} cli generate-by-swagger-tag " |
236 | 285 | f"--aaz-path {paths['aaz']} " |
237 | 286 | f"--cli-path {paths['cli']} " |
238 | 287 | f"--cli-extension-path {paths['cli_extension']} " |
239 | | - f"--extension-or-module-name {request.extension_or_module_name} " |
| 288 | + f"--extension-or-module-name {request.name} " |
240 | 289 | f"--swagger-module-path {request.swagger_module_path} " |
241 | 290 | f"--resource-provider {request.resource_provider} " |
242 | 291 | f"--swagger-tag {request.swagger_tag} " |
|
0 commit comments