Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

fix(cua-sandbox): package Fleet SDK with cua-train (#2519)

r33drichardscf0463a0d862
diff --git a/libs/python/cua-sandbox/README.md b/libs/python/cua-sandbox/README.md
index 899a1c8741..093d3ce51b 100644
--- a/libs/python/cua-sandbox/README.md
+++ b/libs/python/cua-sandbox/README.md
@@ -6,6 +6,14 @@ Sandboxed VM environments with a unified Python API. Cloud by default.
pip install cua-sandbox
```
+Fleet support requires the platform-specific `cua-train` wheel that bundles the
+`cyclops_sdk` native binding. Install from the Cua wheel index when resolving
+dependencies with pip:
+
+```bash
+pip install --extra-index-url https://wheels.cua.ai/simple cua-sandbox
+```
+
## Ephemeral sandbox
Created on enter, destroyed on exit.
diff --git a/libs/python/cua-sandbox/hatch_build.py b/libs/python/cua-sandbox/hatch_build.py
deleted file mode 100644
index cd63132064..0000000000
--- a/libs/python/cua-sandbox/hatch_build.py
+++ /dev/null
@@ -1,40 +0,0 @@
-import platform
-import subprocess
-from pathlib import Path
-
-from hatchling.builders.hooks.plugin.interface import BuildHookInterface
-
-
-class CustomBuildHook(BuildHookInterface):
- repository_root = Path(__file__).resolve().parents[3]
- native_target_dir = repository_root / "target" / "cyclops-sdk-bindings-native"
-
- def initialize(self, version, build_data):
- mirror_root = self.repository_root / "libs" / "fleet"
- subprocess.run(
- [
- "cargo",
- "build",
- "--locked",
- "--manifest-path",
- str(mirror_root / "Cargo.toml"),
- "--package",
- "cyclops-sdk",
- "--target-dir",
- str(self.native_target_dir),
- ],
- check=True,
- )
-
- suffix = {"Darwin": ".dylib", "Linux": ".so"}.get(platform.system())
- if suffix is None:
- raise RuntimeError(f"unsupported host for Cyclops SDK bindings: {platform.system()}")
-
- native_library = self.native_target_dir / "debug" / f"libcyclops_sdk{suffix}"
- if not native_library.is_file():
- raise RuntimeError(f"native Cyclops SDK library was not built: {native_library}")
-
- build_data["infer_tag"] = True
- force_include = build_data.setdefault("force_include", {})
- force_include[str(mirror_root / "sdk-bindings" / "python" / "cyclops_sdk")] = "cyclops_sdk"
- force_include[str(native_library)] = f"cyclops_sdk/{native_library.name}"
diff --git a/libs/python/cua-sandbox/pyproject.toml b/libs/python/cua-sandbox/pyproject.toml
index 603685db7e..88f5d0e896 100644
--- a/libs/python/cua-sandbox/pyproject.toml
+++ b/libs/python/cua-sandbox/pyproject.toml
@@ -29,6 +29,7 @@ requires-python = ">=3.11,<3.14"
dependencies = [
"cua-core>=0.3.0,<0.4.0",
"cua-auto>=0.1.2",
+ "cua-train==0.1.1",
"websockets>=12.0",
"httpx>=0.27.0",
"oras>=0.2.40",
@@ -95,5 +96,9 @@ dev = [
[tool.uv.sources]
cua-agent = { path = "../agent", editable = true }
+cua-train = { index = "cua-wheels" }
-[tool.hatch.build.hooks.custom]
+[[tool.uv.index]]
+name = "cua-wheels"
+url = "https://wheels.cua.ai/simple"
+explicit = true
diff --git a/libs/python/cua-sandbox/tests/test_cyclops_sdk_distribution.py b/libs/python/cua-sandbox/tests/test_cyclops_sdk_distribution.py
new file mode 100644
index 0000000000..d13d3d26e2
--- /dev/null
+++ b/libs/python/cua-sandbox/tests/test_cyclops_sdk_distribution.py
@@ -0,0 +1,16 @@
+from importlib.metadata import distribution
+from pathlib import Path
+
+import cyclops_sdk
+from cua_sandbox.transport.fleet_cloud import FleetCloudTransport
+
+
+def test_cyclops_sdk_is_provided_by_cua_train_distribution():
+ cua_train = distribution("cua-train")
+ installed_files = {str(path) for path in cua_train.files or []}
+ distribution_root = Path(cua_train.locate_file(".")).resolve()
+ binding_path = Path(cyclops_sdk.__file__).resolve()
+
+ assert "cyclops_sdk/__init__.py" in installed_files
+ assert binding_path.is_relative_to(distribution_root)
+ assert FleetCloudTransport.__module__ == "cua_sandbox.transport.fleet_cloud"
diff --git a/libs/python/cua-sandbox/tests/test_cyclops_sdk_packaging.py b/libs/python/cua-sandbox/tests/test_cyclops_sdk_packaging.py
index 0851e7dc02..4b36f02d35 100644
--- a/libs/python/cua-sandbox/tests/test_cyclops_sdk_packaging.py
+++ b/libs/python/cua-sandbox/tests/test_cyclops_sdk_packaging.py
@@ -1,75 +1,45 @@
-import importlib.util
-import tempfile
+import tomllib
import unittest
from pathlib import Path
-from unittest.mock import patch
PROJECT_ROOT = Path(__file__).resolve().parents[1]
-BUILD_HOOK_PATH = PROJECT_ROOT / "hatch_build.py"
-
-
-def load_build_hook():
- spec = importlib.util.spec_from_file_location("cua_sandbox_hatch_build", BUILD_HOOK_PATH)
- assert spec and spec.loader
- module = importlib.util.module_from_spec(spec)
- spec.loader.exec_module(module)
- return module.CustomBuildHook
+PYPROJECT_PATH = PROJECT_ROOT / "pyproject.toml"
+FLEET_IMPORTS = (
+ PROJECT_ROOT / "cua_sandbox" / "transport" / "cyclops_http_client.py",
+ PROJECT_ROOT / "cua_sandbox" / "transport" / "fleet.py",
+ PROJECT_ROOT / "cua_sandbox" / "transport" / "fleet_cloud.py",
+)
class CyclopsSdkPackagingTests(unittest.TestCase):
- def test_build_hook_stages_mirrored_cyclops_sdk(self):
- CustomBuildHook = load_build_hook()
- with tempfile.TemporaryDirectory() as temporary_directory:
- temporary_root = Path(temporary_directory)
- repository_root = temporary_root / "repository"
- mirror_root = repository_root / "libs" / "fleet"
- binding_root = mirror_root / "sdk-bindings" / "python" / "cyclops_sdk"
- binding_root.mkdir(parents=True)
- native_library = temporary_root / "native" / "debug" / "libcyclops_sdk.so"
- calls = []
-
- def fake_run(command, check):
- calls.append((command, check))
- native_library.parent.mkdir(parents=True)
- native_library.touch()
-
- with (
- patch("platform.system", return_value="Linux"),
- patch("subprocess.run", fake_run),
- patch.object(CustomBuildHook, "repository_root", repository_root),
- patch.object(CustomBuildHook, "native_target_dir", temporary_root / "native"),
- ):
- hook = object.__new__(CustomBuildHook)
- build_data = {"force_include": {}}
- hook.initialize("0.1.0", build_data)
-
- self.assertEqual(
- calls,
- [
- (
- [
- "cargo",
- "build",
- "--locked",
- "--manifest-path",
- str(mirror_root / "Cargo.toml"),
- "--package",
- "cyclops-sdk",
- "--target-dir",
- str(temporary_root / "native"),
- ],
- True,
- )
- ],
- )
- self.assertEqual(
- build_data["force_include"],
- {
- str(binding_root): "cyclops_sdk",
- str(native_library): "cyclops_sdk/libcyclops_sdk.so",
- },
- )
- self.assertTrue(build_data["infer_tag"])
+ def test_declares_packaged_cyclops_sdk_distribution(self):
+ with PYPROJECT_PATH.open("rb") as pyproject_file:
+ project = tomllib.load(pyproject_file)
+
+ self.assertIn("cua-train==0.1.1", project["project"]["dependencies"])
+ self.assertEqual(project["tool"]["uv"]["sources"]["cua-train"], {"index": "cua-wheels"})
+ self.assertEqual(
+ project["tool"]["uv"]["index"][0],
+ {
+ "name": "cua-wheels",
+ "url": "https://wheels.cua.ai/simple",
+ "explicit": True,
+ },
+ )
+
+ def test_package_does_not_copy_the_binding_from_the_checkout(self):
+ self.assertFalse((PROJECT_ROOT / "hatch_build.py").exists())
+ with PYPROJECT_PATH.open("rb") as pyproject_file:
+ project = tomllib.load(pyproject_file)
+ self.assertNotIn("hooks", project.get("tool", {}).get("hatch", {}).get("build", {}))
+
+ def test_fleet_imports_do_not_mutate_paths_or_load_native_libraries(self):
+ for source_path in FLEET_IMPORTS:
+ source = source_path.read_text()
+ self.assertIn("from cyclops_sdk import", source)
+ self.assertNotIn("sys.path", source)
+ self.assertNotIn("site.addsitedir", source)
+ self.assertNotIn("ctypes.CDLL", source)
if __name__ == "__main__":
diff --git a/libs/python/cua-sandbox/uv.lock b/libs/python/cua-sandbox/uv.lock
index 5caa780a68..442d2c0824 100644
--- a/libs/python/cua-sandbox/uv.lock
+++ b/libs/python/cua-sandbox/uv.lock
@@ -414,7 +414,7 @@ wheels = [
[[package]]
name = "cua-agent"
-version = "0.8.3"
+version = "0.8.4"
source = { editable = "../agent" }
dependencies = [
{ name = "aiohttp" },
@@ -450,12 +450,14 @@ requires-dist = [
{ name = "cua-som", marker = "extra == 'omni'", editable = "../som" },
{ name = "einops", marker = "extra == 'all'" },
{ name = "einops", marker = "extra == 'internvl-hf'" },
+ { name = "fastmcp", marker = "extra == 'hud'", specifier = ">=3.2.0,<3.3.0" },
{ name = "google-genai", marker = "extra == 'all'", specifier = ">=1.41.0" },
{ name = "google-genai", marker = "extra == 'cloud'", specifier = ">=1.41.0" },
{ name = "google-genai", marker = "extra == 'gemini'", specifier = ">=1.41.0" },
{ name = "gradio", marker = "extra == 'all'", specifier = ">=6.0.0" },
{ name = "gradio", marker = "extra == 'ui'", specifier = ">=6.0.0" },
{ name = "httpx", specifier = ">=0.27.0" },
+ { name = "hud-python", marker = "extra == 'hud'", specifier = "==0.4.52" },
{ name = "litellm", specifier = "==1.86.2" },
{ name = "mlx-vlm", marker = "sys_platform == 'darwin' and extra == 'all'", specifier = ">=0.1.27" },
{ name = "mlx-vlm", marker = "sys_platform == 'darwin' and extra == 'uitars-mlx'", specifier = ">=0.1.27" },
@@ -537,11 +539,12 @@ dev = [{ name = "pytest", specifier = ">=8.3.5" }]
[[package]]
name = "cua-sandbox"
-version = "0.1.16"
+version = "0.1.17"
source = { editable = "." }
dependencies = [
{ name = "cua-auto" },
{ name = "cua-core" },
+ { name = "cua-train" },
{ name = "grpcio" },
{ name = "httpx" },
{ name = "oras" },
@@ -573,6 +576,7 @@ dev = [
requires-dist = [
{ name = "cua-auto", specifier = ">=0.1.2" },
{ name = "cua-core", specifier = ">=0.3.0,<0.4.0" },
+ { name = "cua-train", specifier = "==0.1.1", index = "https://wheels.cua.ai/simple" },
{ name = "grpcio", specifier = "==1.78.0" },
{ name = "httpx", specifier = ">=0.27.0" },
{ name = "oras", specifier = ">=0.2.40" },
@@ -595,6 +599,22 @@ dev = [
{ name = "pytest-asyncio", specifier = ">=1.3.0" },
]
+[[package]]
+name = "cua-train"
+version = "0.1.1"
+source = { registry = "https://wheels.cua.ai/simple" }
+dependencies = [
+ { name = "attrs" },
+ { name = "httpx" },
+ { name = "python-dateutil" },
+]
+wheels = [
+ { url = "https://wheels.cua.ai/simple/cua-train/cua_train-0.1.1-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:1822fb9a63c6566d2763a9fb2e384ba4cc6a3771d97fb2cd3f1f9af66916e6df" },
+ { url = "https://wheels.cua.ai/simple/cua-train/cua_train-0.1.1-py3-none-macosx_11_0_arm64.whl", hash = "sha256:045b51e3ebebc7bf2107ec5a97801250b551e9617bcbbeec97a1e4f4c2ebd884" },
+ { url = "https://wheels.cua.ai/simple/cua-train/cua_train-0.1.1-py3-none-manylinux_2_34_aarch64.whl", hash = "sha256:6f8eb7f450f05d4a495de70a0a8f7acdb3dce20d842bae96f2aec27e2869fb85" },
+ { url = "https://wheels.cua.ai/simple/cua-train/cua_train-0.1.1-py3-none-manylinux_2_34_x86_64.whl", hash = "sha256:9ab37ae89ef6f95a1c0e315226af7716625bc6225e54770f94315905a744c5ad" },
+]
+
[[package]]
name = "distro"
version = "1.9.0"
@@ -615,7 +635,7 @@ name = "ewmhlib"
version = "0.2"
source = { registry = "https://pypi.org/simple" }
dependencies = [
- { name = "python-xlib", marker = "sys_platform == 'linux'" },
+ { name = "python-xlib" },
{ name = "typing-extensions" },
]
wheels = [