16 # optional dependencies
41 buildPythonPackage rec {
46 disabled = pythonOlder "3.8";
48 src = fetchFromGitHub {
49 owner = "huggingface";
51 rev = "refs/tags/v${version}";
52 hash = "sha256-/3lHJdsNblKb6xX03OluSCApMK3EXJbRLboBk8CjobE=";
55 build-system = [ setuptools ];
68 optional-dependencies = {
88 pythonImportsCheck = [ "diffusers" ];
90 # it takes a few hours
93 passthru.tests.pytest = diffusers.overridePythonAttrs { doCheck = true; };
105 ] ++ optional-dependencies.torch;
109 # This pytest hook mocks and catches attempts at accessing the network
110 # tests that try to access the network will raise, get caught, be marked as skipped and tagged as xfailed.
111 # cf. python3Packages.shap
112 conftestSkipNetworkErrors = writeText "conftest.py" ''
113 from _pytest.runner import pytest_runtest_makereport as orig_pytest_runtest_makereport
116 class NetworkAccessDeniedError(RuntimeError): pass
117 def deny_network_access(*a, **kw):
118 raise NetworkAccessDeniedError
120 urllib3.connection.HTTPSConnection._new_conn = deny_network_access
122 def pytest_runtest_makereport(item, call):
123 tr = orig_pytest_runtest_makereport(item, call)
124 if call.excinfo is not None and call.excinfo.type is NetworkAccessDeniedError:
125 tr.outcome = 'skipped'
126 tr.wasxfail = "reason: Requires network access."
132 cat ${conftestSkipNetworkErrors} >> tests/conftest.py
135 pytestFlagsArray = [ "tests/" ];
139 # depends on current working directory
140 "test_deprecate_stacklevel"
141 # fails due to precision of floating point numbers
142 "test_model_cpu_offload_forward_pass"
143 # tries to run ruff which we have intentionally removed from nativeCheckInputs
144 "test_is_copy_consistent"
146 ++ lib.optionals (pythonAtLeast "3.12") [
148 # RuntimeError: Dynamo is not supported on Python 3.12+
149 "test_from_save_pretrained_dynamo"
153 description = "State-of-the-art diffusion models for image and audio generation in PyTorch";
154 mainProgram = "diffusers-cli";
155 homepage = "https://github.com/huggingface/diffusers";
156 changelog = "https://github.com/huggingface/diffusers/releases/tag/${lib.removePrefix "refs/tags/" src.rev}";
157 license = licenses.asl20;
158 maintainers = with maintainers; [ natsukium ];