check conversion deps are installed when using refiners.conversion

This commit is contained in:
Laurent 2024-10-14 14:40:15 +00:00 committed by Laureηt
parent 8f31039c4a
commit 9fb8344487

View file

@ -1,3 +1,36 @@
import sys
from importlib import import_module
from importlib.metadata import requires
from packaging.requirements import Requirement
refiners_requires = requires("refiners")
assert refiners_requires is not None
# Some dependencies have different module names than their package names
req_to_module: dict[str, str] = {
"huggingface-hub": "huggingface_hub",
"segment-anything-py": "segment_anything",
}
for dep in refiners_requires:
req = Requirement(dep)
marker = req.marker
if marker is None or not marker.evaluate({"extra": "conversion"}):
continue
module_name = req_to_module.get(req.name, req.name)
try:
import_module(module_name)
except ImportError:
print(
f"Some dependencies are missing: {req.name}. "
"Please install refiners with the `conversion` extra, e.g. `pip install refiners[conversion]`",
file=sys.stderr,
)
sys.exit(1)
from .models import ( from .models import (
autoencoder_sd15, autoencoder_sd15,
autoencoder_sdxl, autoencoder_sdxl,