Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
43 lines
1.5 KiB
Python
43 lines
1.5 KiB
Python
"""Best-effort pre-fetch of the SeFi-Image source at install time.
|
|
|
|
ComfyUI-Manager runs this after cloning the pack. It's only an optimization —
|
|
nodes.py fetches the same source lazily on first use if this didn't run.
|
|
"""
|
|
|
|
import io
|
|
import os
|
|
import shutil
|
|
import tarfile
|
|
import tempfile
|
|
import urllib.request
|
|
|
|
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
VENDOR_DIR = os.path.join(HERE, "SeFi-Image")
|
|
TARBALL = "https://codeload.github.com/jmliu206/SeFi-Image/tar.gz/refs/heads/main"
|
|
|
|
|
|
def main():
|
|
if os.path.isdir(os.path.join(VENDOR_DIR, "sefi")):
|
|
print("[SeFi-Image] source already present, skipping fetch")
|
|
return
|
|
tmp = tempfile.mkdtemp(prefix="sefi_dl_")
|
|
try:
|
|
print("[SeFi-Image] fetching model inference source...")
|
|
data = urllib.request.urlopen(TARBALL, timeout=120).read()
|
|
with tarfile.open(fileobj=io.BytesIO(data), mode="r:gz") as tf:
|
|
tf.extractall(tmp)
|
|
roots = [d for d in os.listdir(tmp) if os.path.isdir(os.path.join(tmp, d))]
|
|
src = os.path.join(tmp, roots[0])
|
|
if os.path.isdir(VENDOR_DIR):
|
|
shutil.rmtree(VENDOR_DIR, ignore_errors=True)
|
|
shutil.move(src, VENDOR_DIR)
|
|
print("[SeFi-Image] source ready at", VENDOR_DIR)
|
|
except Exception as exc: # noqa: BLE001 - best effort, nodes.py retries lazily
|
|
print("[SeFi-Image] pre-fetch skipped (will retry at runtime):", exc)
|
|
finally:
|
|
shutil.rmtree(tmp, ignore_errors=True)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|