Skip to content

Commit 1fedeb5

Browse files
committed
fixed bugs
1 parent add0fec commit 1fedeb5

File tree

1 file changed

+57
-8
lines changed

1 file changed

+57
-8
lines changed

tools/aaz-flow/helpers.py

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55

66
import asyncio
77
from pathlib import Path
8-
import sys
98
from typing import Literal
109
from fastmcp import Context
11-
import requests
1210
import os
13-
import subprocess as sp
11+
import shutil
12+
import sys
1413
from models import AAZRequest
1514

1615
paths = {
@@ -53,7 +52,7 @@ async def validate_paths(ctx: Context) -> dict:
5352
response_type=Literal["yes", "no"]
5453
)
5554

56-
if check_result.action == "reject":
55+
if check_result.action != "accept":
5756
return None
5857

5958
if check_result.data == "no":
@@ -221,22 +220,72 @@ async def run_command(ctx: Context, command: str, step_name: str, progress_start
221220
await ctx.report_progress(progress_end, 100)
222221
await ctx.info(f"az_cli : Completed: {step_name}")
223222

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+
224270
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+
225274
cmd1 = (
226-
f"aaz-dev command-model generate-from-swagger "
275+
f"{aaz_dev} command-model generate-from-swagger "
227276
f"-a {paths['aaz']} "
228277
f"--sm {request.swagger_module_path} "
229-
f"-m {request.extension_or_module_name} "
278+
f"-m {request.name} "
230279
f"--rp {request.resource_provider} "
231280
f"--swagger-tag {request.swagger_tag}"
232281
)
233282

234283
cmd2 = (
235-
f"aaz-dev cli generate-by-swagger-tag "
284+
f"{aaz_dev} cli generate-by-swagger-tag "
236285
f"--aaz-path {paths['aaz']} "
237286
f"--cli-path {paths['cli']} "
238287
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} "
240289
f"--swagger-module-path {request.swagger_module_path} "
241290
f"--resource-provider {request.resource_provider} "
242291
f"--swagger-tag {request.swagger_tag} "

0 commit comments

Comments
 (0)