mirror of
https://github.com/finegrain-ai/refiners.git
synced 2024-11-21 13:48:46 +00:00
check conversion deps are installed when using refiners.conversion
This commit is contained in:
parent
8f31039c4a
commit
9b19272d75
|
@ -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,
|
||||||
|
|
Loading…
Reference in a new issue