MCPcopy Index your code
hub / github.com/OpenBMB/ChatDev / init_python_env

Function init_python_env

functions/function_calling/uv_related.py:225–268  ·  view source on GitHub ↗

Run uv lock and uv venv inside the workspace.

(
    *,
    # recreate: bool = False,
    python_version: str | None = None,
    # lock_args: Sequence[str] | None = None,
    # venv_args: Sequence[str] | None = None,
    _context: Dict[str, Any] | None = None,
)

Source from the content-addressed store, hash-verified

223
224
225def init_python_env(
226 *,
227 # recreate: bool = False,
228 python_version: str | None = None,
229 # lock_args: Sequence[str] | None = None,
230 # venv_args: Sequence[str] | None = None,
231 _context: Dict[str, Any] | None = None,
232) -> Dict[str, Any]:
233 """Run uv lock and uv venv inside the workspace."""
234
235 ctx = WorkspaceCommandContext(_context)
236 steps: List[Dict[str, Any]] = []
237
238 lock_cmd: List[str] = ["uv", "lock"]
239 # lock_cmd.extend(_validate_flag_args(lock_args))
240 lock_result = _run_uv_command(lock_cmd, ctx.workspace_root, step="uv lock")
241 steps.append(lock_result)
242 if lock_result["returncode"] != 0:
243 return {
244 "workspace_root": str(ctx.workspace_root),
245 "steps": steps,
246 }
247
248 venv_cmd: List[str] = ["uv", "venv"]
249 # if recreate:
250 # venv_cmd.append("--recreate")
251 # venv_cmd.extend(_validate_flag_args(venv_args))
252 if python_version is not None:
253 python_spec = python_version.strip()
254 if not python_spec:
255 raise ValueError("python argument cannot be empty")
256 venv_cmd.extend(["--python", python_spec])
257
258 venv_result = _run_uv_command(venv_cmd, ctx.workspace_root, step="uv venv")
259 steps.append(venv_result)
260
261 init_cmd: List[str] = ["uv", "init", "--bare", "--no-workspace"]
262 init_result = _run_uv_command(init_cmd, ctx.workspace_root, step="uv init")
263 steps.append(init_result)
264
265 return {
266 "workspace_root": str(ctx.workspace_root),
267 "steps": steps,
268 }
269
270
271def uv_run(

Callers

nothing calls this directly

Calls 2

_run_uv_commandFunction · 0.85

Tested by

no test coverage detected