refactor: delete network_utils.py (~60 lines)

The CivitAI function moved to the ComfyUI-USCG-CivitAI companion in this
phase. After Phase 1 (HF VAE) and Phase 2 (Distribution), this was the
only function left. Now the file is empty and removable.

network_utils.py shrunk: 281 (original) -> 189 (Phase 1) -> 60 (Phase 2)
-> 0 (Phase 3, deleted).

Also tidies any dead network_utils references in tests/conftest.py.
This commit is contained in:
Jason Hoku
2026-05-19 18:56:30 -07:00
parent 32d1287059
commit 490cec842f
3 changed files with 1 additions and 81 deletions
-8
View File
@@ -112,14 +112,6 @@ def _install_stubs():
setattr(sys.modules[bare], k, v)
setattr(sys.modules[fq], k, v)
# 2b. Stub network_utils (used by config_builder_node via relative import)
for _nu_name in ("network_utils", f"{_PKG_NAME}.network_utils"):
if _nu_name not in sys.modules:
_nu = types.ModuleType(_nu_name)
sys.modules[_nu_name] = _nu
if not hasattr(sys.modules[_nu_name], "civitai_fetch_by_hash"):
sys.modules[_nu_name].civitai_fetch_by_hash = lambda *a, **kw: None
# 3. Pre-register the package itself
if _PKG_NAME not in sys.modules:
pkg_stub = types.ModuleType(_PKG_NAME)
-54
View File
@@ -1,54 +0,0 @@
# ==============================================================================
# NETWORK UTILS - Outbound network requests centralized here.
#
# External services contacted:
# 1. CivitAI API (civitai.com/api/v1) - model/LoRA metadata lookup
#
# (HuggingFace Remote VAE was moved to the ComfyUI-USCG-RemoteVAE companion
# plugin in 2026-05-19. See remote_vae.py for the facade.
# Distribution system was moved to the ComfyUI-USCG-Distributed companion
# plugin in 2026-05-19. See distribution.py for the facade.)
# ==============================================================================
import json
import os
import urllib.request
import urllib.error
import urllib.parse
# =============================================================================
# 1. CIVITAI API — Model/LoRA metadata lookup
# Target: civitai.com/api/v1 (ONLY)
# =============================================================================
CIVITAI_API_BASE = "https://civitai.com/api/v1"
CIVITAI_TIMEOUT = 10 # seconds
CIVITAI_USER_AGENT = "ComfyUI-ConfigBuilder"
def civitai_fetch_by_hash(hash_value):
"""
Fetch model version info from CivitAI API using a file hash.
Network call: GET https://civitai.com/api/v1/model-versions/by-hash/{hash}
Timeout: 10 seconds
Returns: Parsed JSON dict on success, None on any error.
"""
api_url = f"{CIVITAI_API_BASE}/model-versions/by-hash/{hash_value}"
try:
req = urllib.request.Request(
api_url,
headers={"User-Agent": CIVITAI_USER_AGENT}
)
with urllib.request.urlopen(req, timeout=CIVITAI_TIMEOUT) as response:
if response.status == 200:
return json.loads(response.read().decode("utf-8"))
else:
return None
except urllib.error.HTTPError:
return None
except Exception as e:
print(f"[NetworkUtils] ⚠️ CivitAI lookup failed: {e}")
return None
+1 -19
View File
@@ -163,23 +163,7 @@ _GEN_ORCH_DEPS = {
},
}
# network_utils.py uses only stdlib — always load the real module and register
# it under both the bare name and the package-qualified name. This ensures the
# relative import `from .network_utils import huggingface_vae_decode, ...` in
# remote_vae.py resolves correctly regardless of what pytest has pre-loaded.
import importlib.util as _ilu # imported here; re-used below for gen_orch and remote_vae
_NETWORK_UTILS_FQ = f"{_PKG_NAME}.network_utils"
_NU_PATH = os.path.join(_NODE_ROOT, "network_utils.py")
_nu_spec = _ilu.spec_from_file_location(_NETWORK_UTILS_FQ, _NU_PATH,
submodule_search_locations=[])
_nu_spec.submodule_search_locations = None
_nu_mod = _ilu.module_from_spec(_nu_spec)
_nu_mod.__package__ = _PKG_NAME
# Unconditionally replace any prior stub — we need the real attributes.
sys.modules[_NETWORK_UTILS_FQ] = _nu_mod
sys.modules["network_utils"] = _nu_mod
setattr(sys.modules[_PKG_NAME], "network_utils", _nu_mod)
_nu_spec.loader.exec_module(_nu_mod)
import importlib.util as _ilu # used below for gen_orch, remote_vae, distribution, civitai
for _bare, _attrs in _GEN_ORCH_DEPS.items():
_fq = f"{_PKG_NAME}.{_bare}"
@@ -213,8 +197,6 @@ if "generation_orchestrator" not in sys.modules:
# Pre-load the real remote_vae module so that test_remote_vae_facade.py gets
# the actual functions (is_remote_vae_available, get_endpoint_names,
# _companion_decode) rather than the lightweight stub registered above.
# remote_vae.py uses `from .network_utils import ...`; we satisfy that via the
# network_utils stub already registered in sys.modules.
_RV_PATH = os.path.join(_NODE_ROOT, "remote_vae.py")
_RV_FQ = f"{_PKG_NAME}.remote_vae"
_rv_spec = _ilu.spec_from_file_location(_RV_FQ, _RV_PATH,