Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/pr_dependency_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
- main
paths:
- "src/diffusers/**.py"
- "tests/**.py"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initially did it to trigger the tests in this PR. Will remove before merging.

push:
branches:
- main
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/pr_torch_dependency_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
- main
paths:
- "src/diffusers/**.py"
- "tests/**.py"
push:
branches:
- main
Expand All @@ -26,7 +27,7 @@ jobs:
- name: Install dependencies
run: |
pip install -e .
pip install torch torchvision torchaudio pytest
pip install torch pytest
- name: Check for soft dependencies
run: |
pytest tests/others/test_dependencies.py
9 changes: 6 additions & 3 deletions src/diffusers/pipelines/consisid/consisid_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
import numpy as np
import torch
from PIL import Image, ImageOps
from torchvision.transforms import InterpolationMode
from torchvision.transforms.functional import normalize, resize

from ...utils import get_logger, load_image
from ...utils import get_logger, is_torchvision_available, load_image


if is_torchvision_available():
from torchvision.transforms import InterpolationMode
from torchvision.transforms.functional import normalize, resize


logger = get_logger(__name__)
Expand Down
43 changes: 37 additions & 6 deletions tests/others/test_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@
# limitations under the License.

import inspect
import unittest
from importlib import import_module

import pytest

class DependencyTester(unittest.TestCase):

class TestDependencies:
def test_diffusers_import(self):
try:
import diffusers # noqa: F401
except ImportError:
assert False
import diffusers # noqa: F401

def test_backend_registration(self):
import diffusers
Expand Down Expand Up @@ -52,3 +50,36 @@ def test_pipeline_imports(self):
if hasattr(diffusers.pipelines, cls_name):
pipeline_folder_module = ".".join(str(cls_module.__module__).split(".")[:3])
_ = import_module(pipeline_folder_module, str(cls_name))

def test_pipeline_module_imports(self):
"""Import every pipeline submodule whose dependencies are satisfied,
to catch unguarded optional-dep imports (e.g., torchvision).

Uses inspect.getmembers to discover classes that the lazy loader can
actually resolve (same self-filtering as test_pipeline_imports), then
imports the full module path instead of truncating to the folder level.
"""
import diffusers
import diffusers.pipelines

failures = []
all_classes = inspect.getmembers(diffusers, inspect.isclass)

for cls_name, cls_module in all_classes:
if not hasattr(diffusers.pipelines, cls_name):
continue
if "dummy_" in cls_module.__module__:
continue

full_module_path = cls_module.__module__
try:
import_module(full_module_path)
except ImportError as e:
failures.append(f"{full_module_path}: {e}")
except Exception:
# Non-import errors (e.g., missing config) are fine; we only
# care about unguarded import statements.
pass

if failures:
pytest.fail("Unguarded optional-dependency imports found:\n" + "\n".join(failures))
Loading