feat: Add GitHub Actions workflow for building and testing the Depth Anything 3 extension
- Create a build workflow in `.github/workflows/build.yml` to automate the build process. - Configure Python environment and install dependencies. - Add steps for running tests and packaging the extension. chore: Initialize project metadata and dependencies for Depth Anything 3 - Add `pyproject.toml` for project configuration and dependencies. - Include optional dependencies for app and gs functionalities. - Define project scripts and metadata. chore: Add requirements file for Depth Anything 3 dependencies - Create `requirements.txt` listing all necessary packages for the project. feat: Implement export utility functions for Depth Anything 3 - Create `src/depth_anything_3/utils/export/__init__.py` to handle various export formats. - Implement functions for exporting predictions in different formats. feat: Add ray utility functions for homography estimation - Create `src/depth_anything_3/utils/ray_utils.py` with functions for computing optimal rotation and homography using RANSAC. feat: Implement vendor preparation script - Add `prepare_vendor.py` to manage third-party dependencies and artifacts. - Include functions for downloading and verifying artifacts based on a lock file. test: Add unit tests for vendor preparation script - Create `tests/test_prepare_vendor.py` to test artifact downloading and verification. - Implement tests for handling hash mismatches and unsupported platforms. chore: Add vendor lock file for dependency management - Create `vendor.lock.toml` to define artifacts and platforms for the project.
This commit is contained in:
@@ -27,12 +27,12 @@ def load_bootstrap_runtime():
|
||||
|
||||
|
||||
class BootstrapRuntimeTest(unittest.TestCase):
|
||||
def create_bundled_sources(self, root):
|
||||
sources = root / "sources"
|
||||
sources.mkdir()
|
||||
(sources / "depth-anything-3.tar.gz").write_bytes(b"da3")
|
||||
(sources / "ben2.tar.gz").write_bytes(b"ben2")
|
||||
return sources
|
||||
def create_bundled_vendor(self, root):
|
||||
vendor = root / "vendor"
|
||||
vendor.mkdir()
|
||||
(vendor / "depth-anything-3.tar.gz").write_bytes(b"da3")
|
||||
(vendor / "ben2.tar.gz").write_bytes(b"ben2")
|
||||
return vendor
|
||||
|
||||
def test_installs_da3_from_archives_without_gsplat(self):
|
||||
bootstrap = load_bootstrap_runtime()
|
||||
@@ -40,11 +40,11 @@ class BootstrapRuntimeTest(unittest.TestCase):
|
||||
root = Path(directory)
|
||||
runtime_dir = root / "runtime"
|
||||
runtime_dir.mkdir()
|
||||
self.create_bundled_sources(root)
|
||||
self.create_bundled_vendor(root)
|
||||
da3_uri = (
|
||||
root / "sources" / "depth-anything-3.tar.gz"
|
||||
root / "vendor" / "depth-anything-3.tar.gz"
|
||||
).as_uri()
|
||||
ben2_uri = (root / "sources" / "ben2.tar.gz").as_uri()
|
||||
ben2_uri = (root / "vendor" / "ben2.tar.gz").as_uri()
|
||||
uv_path = root / "uv"
|
||||
uv_path.write_bytes(b"uv")
|
||||
args = SimpleNamespace(
|
||||
@@ -184,7 +184,7 @@ class BootstrapRuntimeTest(unittest.TestCase):
|
||||
root = Path(directory)
|
||||
runtime_dir = root / "runtime"
|
||||
runtime_dir.mkdir()
|
||||
self.create_bundled_sources(root)
|
||||
self.create_bundled_vendor(root)
|
||||
uv_path = root / "uv"
|
||||
uv_path.write_bytes(b"uv")
|
||||
args = SimpleNamespace(
|
||||
@@ -356,7 +356,7 @@ class BootstrapRuntimeTest(unittest.TestCase):
|
||||
root = Path(directory)
|
||||
runtime_dir = root / "runtime"
|
||||
runtime_dir.mkdir()
|
||||
self.create_bundled_sources(root)
|
||||
self.create_bundled_vendor(root)
|
||||
uv_path = root / "uv"
|
||||
uv_path.write_bytes(b"uv")
|
||||
args = SimpleNamespace(
|
||||
@@ -662,7 +662,7 @@ class BootstrapRuntimeTest(unittest.TestCase):
|
||||
root = Path(directory)
|
||||
runtime_dir = root / "runtime"
|
||||
runtime_dir.mkdir()
|
||||
self.create_bundled_sources(root)
|
||||
self.create_bundled_vendor(root)
|
||||
uv_path = root / "uv"
|
||||
uv_path.write_bytes(b"uv")
|
||||
args = SimpleNamespace(
|
||||
@@ -705,7 +705,7 @@ class BootstrapRuntimeTest(unittest.TestCase):
|
||||
root = Path(directory)
|
||||
runtime_dir = root / "runtime"
|
||||
runtime_dir.mkdir()
|
||||
self.create_bundled_sources(root)
|
||||
self.create_bundled_vendor(root)
|
||||
(runtime_dir / "partial-python.exe").write_text("junk")
|
||||
args = SimpleNamespace(
|
||||
uv="uv",
|
||||
@@ -738,7 +738,7 @@ class BootstrapRuntimeTest(unittest.TestCase):
|
||||
root = Path(directory)
|
||||
runtime_dir = root / "runtime"
|
||||
runtime_dir.mkdir(parents=True)
|
||||
self.create_bundled_sources(root)
|
||||
self.create_bundled_vendor(root)
|
||||
(runtime_dir / "Scripts").mkdir()
|
||||
(runtime_dir / "Scripts" / "python.exe").write_text("python")
|
||||
(runtime_dir / "snapform_ready.json").write_text(
|
||||
@@ -783,7 +783,7 @@ class BootstrapRuntimeTest(unittest.TestCase):
|
||||
root = Path(directory)
|
||||
runtime_dir = root / "runtime"
|
||||
runtime_dir.mkdir()
|
||||
self.create_bundled_sources(root)
|
||||
self.create_bundled_vendor(root)
|
||||
args = SimpleNamespace(
|
||||
uv="uv",
|
||||
runtime_dir=str(runtime_dir),
|
||||
@@ -823,7 +823,7 @@ class BootstrapRuntimeTest(unittest.TestCase):
|
||||
root = Path(directory)
|
||||
runtime_dir = root / "runtime"
|
||||
runtime_dir.mkdir()
|
||||
self.create_bundled_sources(root)
|
||||
self.create_bundled_vendor(root)
|
||||
uv_path = root / "uv" / "uv.exe"
|
||||
args = SimpleNamespace(
|
||||
uv=str(uv_path),
|
||||
@@ -858,7 +858,7 @@ class BootstrapRuntimeTest(unittest.TestCase):
|
||||
):
|
||||
bootstrap.install(args)
|
||||
|
||||
def test_install_uses_bundled_sources_and_uv_without_network(self):
|
||||
def test_install_uses_bundled_vendor_and_uv_without_network(self):
|
||||
bootstrap = load_bootstrap_runtime()
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
@@ -911,7 +911,7 @@ class BootstrapRuntimeTest(unittest.TestCase):
|
||||
|
||||
with patch.object(
|
||||
bootstrap,
|
||||
"bundled_sources_directory",
|
||||
"bundled_vendor_directory",
|
||||
return_value=bundled,
|
||||
), patch.object(
|
||||
bootstrap,
|
||||
@@ -946,8 +946,8 @@ class BootstrapRuntimeTest(unittest.TestCase):
|
||||
for command in install_commands
|
||||
if any("depth-anything-3 @" in str(value) for value in command)
|
||||
)
|
||||
da3_uri = (root / "sources" / "depth-anything-3.tar.gz").as_uri()
|
||||
ben2_uri = (root / "sources" / "ben2.tar.gz").as_uri()
|
||||
da3_uri = (root / "vendor" / "depth-anything-3.tar.gz").as_uri()
|
||||
ben2_uri = (root / "vendor" / "ben2.tar.gz").as_uri()
|
||||
self.assertIn(f"depth-anything-3 @ {da3_uri}", ai_command)
|
||||
self.assertIn(f"ben2 @ {ben2_uri}", ai_command)
|
||||
|
||||
@@ -957,7 +957,7 @@ class BootstrapRuntimeTest(unittest.TestCase):
|
||||
root = Path(directory)
|
||||
runtime_dir = root / "runtime"
|
||||
runtime_dir.mkdir()
|
||||
self.create_bundled_sources(root)
|
||||
self.create_bundled_vendor(root)
|
||||
uv_path = root / "uv.exe"
|
||||
uv_path.write_bytes(b"uv")
|
||||
args = SimpleNamespace(
|
||||
@@ -995,7 +995,7 @@ class BootstrapRuntimeTest(unittest.TestCase):
|
||||
|
||||
self.assertEqual(uv_path.read_bytes(), b"binary")
|
||||
|
||||
def test_sync_bundled_sources_copies_missing_archives(self):
|
||||
def test_sync_bundled_vendor_copies_missing_archives(self):
|
||||
bootstrap = load_bootstrap_runtime()
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
@@ -1003,29 +1003,48 @@ class BootstrapRuntimeTest(unittest.TestCase):
|
||||
bundled.mkdir()
|
||||
(bundled / "depth-anything-3.tar.gz").write_bytes(b"da3")
|
||||
(bundled / "ben2.tar.gz").write_bytes(b"ben2")
|
||||
sources = root / "sources"
|
||||
vendor = root / "vendor"
|
||||
|
||||
bootstrap.sync_bundled_sources(bundled, sources)
|
||||
bootstrap.sync_bundled_vendor(bundled, vendor)
|
||||
|
||||
self.assertEqual(
|
||||
(sources / "depth-anything-3.tar.gz").read_bytes(),
|
||||
(vendor / "depth-anything-3.tar.gz").read_bytes(),
|
||||
b"da3",
|
||||
)
|
||||
self.assertEqual(
|
||||
(sources / "ben2.tar.gz").read_bytes(),
|
||||
(vendor / "ben2.tar.gz").read_bytes(),
|
||||
b"ben2",
|
||||
)
|
||||
|
||||
def test_sync_bundled_vendor_replaces_same_size_stale_archive(self):
|
||||
bootstrap = load_bootstrap_runtime()
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
bundled = root / "bundled"
|
||||
bundled.mkdir()
|
||||
(bundled / "depth-anything-3.tar.gz").write_bytes(b"new")
|
||||
(bundled / "ben2.tar.gz").write_bytes(b"ben2")
|
||||
vendor = root / "vendor"
|
||||
vendor.mkdir()
|
||||
(vendor / "depth-anything-3.tar.gz").write_bytes(b"old")
|
||||
|
||||
bootstrap.sync_bundled_vendor(bundled, vendor)
|
||||
|
||||
self.assertEqual(
|
||||
(vendor / "depth-anything-3.tar.gz").read_bytes(),
|
||||
b"new",
|
||||
)
|
||||
|
||||
def test_install_stages_uses_local_source_archives(self):
|
||||
bootstrap = load_bootstrap_runtime()
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
runtime_dir = root / "runtime"
|
||||
runtime_dir.mkdir()
|
||||
sources = root / "sources"
|
||||
sources.mkdir()
|
||||
(sources / "depth-anything-3.tar.gz").write_bytes(b"da3")
|
||||
(sources / "ben2.tar.gz").write_bytes(b"ben2")
|
||||
vendor = root / "vendor"
|
||||
vendor.mkdir()
|
||||
(vendor / "depth-anything-3.tar.gz").write_bytes(b"da3")
|
||||
(vendor / "ben2.tar.gz").write_bytes(b"ben2")
|
||||
uv_path = root / "uv"
|
||||
uv_path.write_bytes(b"uv")
|
||||
args = SimpleNamespace(
|
||||
@@ -1051,8 +1070,8 @@ class BootstrapRuntimeTest(unittest.TestCase):
|
||||
if kind == "install"
|
||||
and any("depth-anything-3" in str(value) for value in command)
|
||||
)
|
||||
da3_local = (sources / "depth-anything-3.tar.gz").as_uri()
|
||||
ben2_local = (sources / "ben2.tar.gz").as_uri()
|
||||
da3_local = (vendor / "depth-anything-3.tar.gz").as_uri()
|
||||
ben2_local = (vendor / "ben2.tar.gz").as_uri()
|
||||
self.assertIn(f"depth-anything-3 @ {da3_local}", ai_command)
|
||||
self.assertIn(f"ben2 @ {ben2_local}", ai_command)
|
||||
|
||||
@@ -1062,10 +1081,10 @@ class BootstrapRuntimeTest(unittest.TestCase):
|
||||
root = Path(directory)
|
||||
runtime_dir = root / "runtime"
|
||||
runtime_dir.mkdir()
|
||||
sources = root / "sources"
|
||||
sources.mkdir()
|
||||
(sources / "depth-anything-3.tar.gz").write_bytes(b"da3")
|
||||
(sources / "ben2.tar.gz").write_bytes(b"ben2")
|
||||
vendor = root / "vendor"
|
||||
vendor.mkdir()
|
||||
(vendor / "depth-anything-3.tar.gz").write_bytes(b"da3")
|
||||
(vendor / "ben2.tar.gz").write_bytes(b"ben2")
|
||||
uv_path = root / "uv"
|
||||
uv_path.write_bytes(b"uv")
|
||||
args = SimpleNamespace(
|
||||
@@ -1100,7 +1119,7 @@ class BootstrapRuntimeTest(unittest.TestCase):
|
||||
root = Path(directory)
|
||||
runtime_dir = root / "runtime"
|
||||
runtime_dir.mkdir()
|
||||
self.create_bundled_sources(root)
|
||||
self.create_bundled_vendor(root)
|
||||
uv_path = root / "uv"
|
||||
uv_path.write_bytes(b"uv")
|
||||
args = SimpleNamespace(
|
||||
@@ -1213,7 +1232,7 @@ class BootstrapRuntimeTest(unittest.TestCase):
|
||||
tar.addfile(info, io.BytesIO(content))
|
||||
with patch.object(
|
||||
bootstrap,
|
||||
"bundled_sources_directory",
|
||||
"bundled_vendor_directory",
|
||||
return_value=bundled,
|
||||
):
|
||||
bootstrap.install_uv(uv_path, str(root / "status.json"))
|
||||
@@ -1229,7 +1248,7 @@ class BootstrapRuntimeTest(unittest.TestCase):
|
||||
bundled.mkdir()
|
||||
with patch.object(
|
||||
bootstrap,
|
||||
"bundled_sources_directory",
|
||||
"bundled_vendor_directory",
|
||||
return_value=bundled,
|
||||
):
|
||||
with self.assertRaisesRegex(
|
||||
|
||||
@@ -3,6 +3,7 @@ import importlib.util
|
||||
import io
|
||||
import tarfile
|
||||
import tempfile
|
||||
import tomllib
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from zipfile import ZipFile
|
||||
@@ -32,13 +33,16 @@ class PackTest(unittest.TestCase):
|
||||
finally:
|
||||
pack.DIST_DIR = original_dist
|
||||
|
||||
version = tomllib.loads(
|
||||
(pack.SOURCE_DIR / "blender_manifest.toml").read_text(
|
||||
encoding="utf-8"
|
||||
)
|
||||
)["version"]
|
||||
self.assertEqual(
|
||||
{path.name for path in output_paths},
|
||||
{
|
||||
"SnapForm.v0.10.10.windows-x64.zip",
|
||||
"SnapForm.v0.10.10.macos-x64.zip",
|
||||
"SnapForm.v0.10.10.macos-arm64.zip",
|
||||
"SnapForm.v0.10.10.linux-x64.zip",
|
||||
f"SnapForm.v{version}.{platform}.zip"
|
||||
for platform in pack.PLATFORMS
|
||||
},
|
||||
)
|
||||
for output_path in output_paths:
|
||||
@@ -56,12 +60,24 @@ class PackTest(unittest.TestCase):
|
||||
self.assertIn("ai_host.py", names)
|
||||
self.assertNotIn("snapform/__init__.py", names)
|
||||
self.assertNotIn("importer.py", names)
|
||||
self.assertIn("sources/depth-anything-3.tar.gz", names)
|
||||
self.assertIn("sources/ben2.tar.gz", names)
|
||||
self.assertIn("vendor/depth-anything-3.tar.gz", names)
|
||||
self.assertIn("vendor/ben2.tar.gz", names)
|
||||
self.assertIn(
|
||||
f"sources/{pack.PLATFORMS[platform]}",
|
||||
f"vendor/{pack.PLATFORMS[platform]}",
|
||||
names,
|
||||
)
|
||||
self.assertFalse(
|
||||
any(name.startswith("sources/") for name in names)
|
||||
)
|
||||
bundled_uv = {
|
||||
name
|
||||
for name in names
|
||||
if name.startswith("vendor/uv-")
|
||||
}
|
||||
self.assertEqual(
|
||||
bundled_uv,
|
||||
{f"vendor/{pack.PLATFORMS[platform]}"},
|
||||
)
|
||||
self.assertIn(f'platforms = ["{platform}"]', manifest)
|
||||
self.assertNotIn(
|
||||
"windows-x64"
|
||||
@@ -75,11 +91,24 @@ class PackTest(unittest.TestCase):
|
||||
with self.assertRaisesRegex(ValueError, "Unsupported platform"):
|
||||
pack.build_extension("windows-arm64")
|
||||
|
||||
def test_platforms_match_manifest(self):
|
||||
pack = load_pack()
|
||||
manifest = tomllib.loads(
|
||||
(pack.SOURCE_DIR / "blender_manifest.toml").read_text(
|
||||
encoding="utf-8"
|
||||
)
|
||||
)
|
||||
self.assertEqual(set(pack.PLATFORMS), set(manifest["platforms"]))
|
||||
self.assertEqual(
|
||||
set(pack.PLATFORMS),
|
||||
{"windows-x64", "macos-arm64", "linux-x64"},
|
||||
)
|
||||
|
||||
def test_bundled_depth_anything_3_has_no_xformers_dependency(self):
|
||||
pack = load_pack()
|
||||
with tarfile.open(
|
||||
fileobj=io.BytesIO(
|
||||
pack.bundled_source_bytes("depth-anything-3.tar.gz")
|
||||
pack.bundled_artifact_bytes("depth-anything-3.tar.gz")
|
||||
),
|
||||
mode="r:gz",
|
||||
) as archive:
|
||||
@@ -95,7 +124,7 @@ class PackTest(unittest.TestCase):
|
||||
pack = load_pack()
|
||||
with tarfile.open(
|
||||
fileobj=io.BytesIO(
|
||||
pack.bundled_source_bytes("depth-anything-3.tar.gz")
|
||||
pack.bundled_artifact_bytes("depth-anything-3.tar.gz")
|
||||
),
|
||||
mode="r:gz",
|
||||
) as archive:
|
||||
@@ -116,7 +145,7 @@ class PackTest(unittest.TestCase):
|
||||
|
||||
def test_official_depth_anything_3_baseline_is_pristine(self):
|
||||
pack = load_pack()
|
||||
archive_path = pack.SOURCES_DIR / "depth-anything-3.tar.gz"
|
||||
archive_path = pack.VENDOR_DIR / "depth-anything-3.tar.gz"
|
||||
with tarfile.open(archive_path, "r:gz") as archive:
|
||||
raw_pyproject = archive.extractfile(
|
||||
"Depth-Anything-3-3d835ec1a5802d64a8b8b15f817a1ab54809bfe4/"
|
||||
@@ -138,7 +167,7 @@ class PackTest(unittest.TestCase):
|
||||
pack = load_pack()
|
||||
with tarfile.open(
|
||||
fileobj=io.BytesIO(
|
||||
pack.bundled_source_bytes("depth-anything-3.tar.gz")
|
||||
pack.bundled_artifact_bytes("depth-anything-3.tar.gz")
|
||||
),
|
||||
mode="r:gz",
|
||||
) as archive:
|
||||
@@ -152,7 +181,7 @@ class PackTest(unittest.TestCase):
|
||||
|
||||
def test_official_depth_anything_3_ray_utils_is_pristine(self):
|
||||
pack = load_pack()
|
||||
archive_path = pack.SOURCES_DIR / "depth-anything-3.tar.gz"
|
||||
archive_path = pack.VENDOR_DIR / "depth-anything-3.tar.gz"
|
||||
with tarfile.open(archive_path, "r:gz") as archive:
|
||||
source = archive.extractfile(
|
||||
"Depth-Anything-3-3d835ec1a5802d64a8b8b15f817a1ab54809bfe4/"
|
||||
|
||||
67
tests/test_prepare_vendor.py
Normal file
67
tests/test_prepare_vendor.py
Normal file
@@ -0,0 +1,67 @@
|
||||
import hashlib
|
||||
import importlib.util
|
||||
import io
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
|
||||
PROJECT_ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def load_prepare_vendor():
|
||||
specification = importlib.util.spec_from_file_location(
|
||||
"snapform_prepare_vendor",
|
||||
PROJECT_ROOT / "prepare_vendor.py",
|
||||
)
|
||||
module = importlib.util.module_from_spec(specification)
|
||||
specification.loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
||||
class PrepareVendorTest(unittest.TestCase):
|
||||
def test_downloads_and_verifies_artifact(self):
|
||||
prepare = load_prepare_vendor()
|
||||
content = b"locked artifact"
|
||||
artifact = {
|
||||
"filename": "artifact.tar.gz",
|
||||
"url": "https://example.invalid/artifact.tar.gz",
|
||||
"sha256": hashlib.sha256(content).hexdigest(),
|
||||
}
|
||||
with tempfile.TemporaryDirectory() as directory, patch.object(
|
||||
prepare.urllib.request,
|
||||
"urlopen",
|
||||
return_value=io.BytesIO(content),
|
||||
):
|
||||
path = prepare.download_artifact(artifact, Path(directory))
|
||||
self.assertEqual(path.read_bytes(), content)
|
||||
|
||||
def test_rejects_hash_mismatch_without_leaving_partial_file(self):
|
||||
prepare = load_prepare_vendor()
|
||||
artifact = {
|
||||
"filename": "artifact.tar.gz",
|
||||
"url": "https://example.invalid/artifact.tar.gz",
|
||||
"sha256": hashlib.sha256(b"expected").hexdigest(),
|
||||
}
|
||||
with tempfile.TemporaryDirectory() as directory, patch.object(
|
||||
prepare.urllib.request,
|
||||
"urlopen",
|
||||
return_value=io.BytesIO(b"unexpected"),
|
||||
):
|
||||
destination = Path(directory)
|
||||
with self.assertRaisesRegex(RuntimeError, "SHA-256 mismatch"):
|
||||
prepare.download_artifact(artifact, destination)
|
||||
self.assertFalse((destination / artifact["filename"]).exists())
|
||||
self.assertFalse(
|
||||
(destination / f"{artifact['filename']}.part").exists()
|
||||
)
|
||||
|
||||
def test_rejects_unknown_platform(self):
|
||||
prepare = load_prepare_vendor()
|
||||
with self.assertRaisesRegex(ValueError, "Unsupported platform"):
|
||||
prepare.prepare(["windows-arm64"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user