MCPcopy Create free account
hub / github.com/OpenBMB/ChatDev / uv_run

Function uv_run

functions/function_calling/uv_related.py:271–313  ·  view source on GitHub ↗

Execute uv run for a module or script inside the workspace root.

(
    *,
    module: str | None = None,
    script: str | None = None,
    args: Sequence[str] | None = None,
    env: Mapping[str, str] | None = None,
    timeout_seconds: float | None = None,
    _context: Dict[str, Any] | None = None,
)

Source from the content-addressed store, hash-verified

269
270
271def uv_run(
272 *,
273 module: str | None = None,
274 script: str | None = None,
275 args: Sequence[str] | None = None,
276 env: Mapping[str, str] | None = None,
277 timeout_seconds: float | None = None,
278 _context: Dict[str, Any] | None = None,
279) -> Dict[str, Any]:
280 """Execute uv run for a module or script inside the workspace root."""
281
282 ctx = WorkspaceCommandContext(_context)
283 timeout_seconds = _coerce_timeout_seconds(timeout_seconds)
284
285 has_module = module is not None
286 has_script = script is not None
287 if has_module == has_script:
288 raise ValueError("Provide exactly one of module or script")
289
290 cmd: List[str] = ["uv", "run"]
291 if has_module:
292 module_name = module.strip()
293 if not module_name:
294 raise ValueError("module cannot be empty")
295 cmd.extend(["python", "-m", module_name])
296 else:
297 script_value = script.strip() if isinstance(script, str) else script
298 if not script_value:
299 raise ValueError("script cannot be empty")
300 script_path = ctx.resolve_under_workspace(script_value)
301 cmd.append(str(script_path))
302
303 cmd.extend(_validate_args(args))
304 env_overrides = _validate_env(env)
305 result = _run_uv_command(
306 cmd,
307 ctx.workspace_root,
308 step="uv run",
309 env=env_overrides,
310 timeout=timeout_seconds,
311 )
312 result["workspace_root"] = str(ctx.workspace_root)
313 return result

Callers

nothing calls this directly

Calls 6

_coerce_timeout_secondsFunction · 0.85
_validate_argsFunction · 0.85
_validate_envFunction · 0.85
_run_uv_commandFunction · 0.85

Tested by

no test coverage detected