Skip to content

Commit 802cf4d

Browse files
committed
fix(image): import WanGP from pinned checkout
1 parent 16a2cbe commit 802cf4d

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

combined/prepare_model.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ def send(self, payload: dict[str, object]) -> None:
3838
self._stream.flush()
3939

4040

41+
def _configure_wangp_root() -> Path:
42+
"""Make the pinned WanGP checkout importable from this copied script."""
43+
root = Path(os.environ.get("WANGP_ROOT", "/opt/Wan2GP")).resolve()
44+
if not (root / "shared").is_dir():
45+
raise FileNotFoundError(f"WanGP checkout is missing its shared package: {root}")
46+
root_text = str(root)
47+
if root_text not in sys.path:
48+
sys.path.insert(0, root_text)
49+
return root
50+
51+
4152
def _model_files(runtime: Any, model_type: str) -> list[tuple[str, int, int]]:
4253
"""Mirror WanGP's own pre-load selection, stopping before model loading."""
4354
module = runtime.module
@@ -135,6 +146,7 @@ def _prepare(runtime: Any, model_type: str) -> None:
135146
def main() -> int:
136147
emitter = _Emitter()
137148
request = _read_request()
149+
wangp_root = _configure_wangp_root()
138150
model_type = str(request.get("model_type") or "").strip()
139151
if not model_type:
140152
raise ValueError("model_type is required")
@@ -188,7 +200,7 @@ def observe() -> None:
188200
from shared.api import init
189201

190202
session = init(
191-
root=os.environ.get("WANGP_ROOT", "/opt/Wan2GP"),
203+
root=str(wangp_root),
192204
config_path=os.environ.get("WANGP_CONFIG_PATH"),
193205
output_dir=os.environ.get("WANGP_OUTPUT_DIR"),
194206
console_output=True,

tests/test_prepare_model.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44

55
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
66

7-
from combined.prepare_model import _model_files, _prepare # noqa: E402
7+
from combined.prepare_model import ( # noqa: E402
8+
_configure_wangp_root,
9+
_model_files,
10+
_prepare,
11+
)
812

913

1014
class FakeWanGP:
@@ -45,6 +49,19 @@ def download_models(self, *args, **kwargs):
4549
self.downloads.append((*args, kwargs))
4650

4751

52+
def test_configure_wangp_root_adds_copied_checkout_to_import_path(
53+
tmp_path: Path, monkeypatch
54+
) -> None:
55+
(tmp_path / "shared").mkdir()
56+
monkeypatch.setenv("WANGP_ROOT", str(tmp_path))
57+
monkeypatch.setattr(sys, "path", list(sys.path))
58+
59+
root = _configure_wangp_root()
60+
61+
assert root == tmp_path.resolve()
62+
assert sys.path[0] == str(tmp_path.resolve())
63+
64+
4865
def test_model_files_match_wangp_primary_secondary_and_modules() -> None:
4966
module = FakeWanGP()
5067

0 commit comments

Comments
 (0)