Skip to content

Commit a7ca03a

Browse files
Replace flake8 with ruff and update black (#2279)
* before running make style * remove left overs from flake8 * finish * make fix-copies * final fix * more fixes
1 parent f5ccffe commit a7ca03a

File tree

164 files changed

+391
-443
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

164 files changed

+391
-443
lines changed

.github/workflows/pr_quality.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ jobs:
2727
pip install .[quality]
2828
- name: Check quality
2929
run: |
30-
black --check --preview examples tests src utils scripts
31-
isort --check-only examples tests src utils scripts
32-
flake8 examples tests src utils scripts
30+
black --check examples tests src utils scripts
31+
ruff examples tests src utils scripts
3332
doc-builder style src/diffusers docs/source --max_len 119 --check_only --path_to_docs docs/source
3433
3534
check_repository_consistency:

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,6 @@ tags
169169

170170
# dependencies
171171
/transformers
172+
173+
# ruff
174+
.ruff_cache

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ Follow these steps to start contributing ([supported Python versions](https://gi
177177
$ make style
178178
```
179179

180-
🧨 Diffusers also uses `flake8` and a few custom scripts to check for coding mistakes. Quality
180+
🧨 Diffusers also uses `ruff` and a few custom scripts to check for coding mistakes. Quality
181181
control runs in CI, however you can also run the same checks with:
182182

183183
```bash

Makefile

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ modified_only_fixup:
99
$(eval modified_py_files := $(shell python utils/get_modified_files.py $(check_dirs)))
1010
@if test -n "$(modified_py_files)"; then \
1111
echo "Checking/fixing $(modified_py_files)"; \
12-
black --preview $(modified_py_files); \
13-
isort $(modified_py_files); \
14-
flake8 $(modified_py_files); \
12+
black $(modified_py_files); \
13+
ruff $(modified_py_files); \
1514
else \
1615
echo "No library .py files were modified"; \
1716
fi
@@ -41,9 +40,8 @@ repo-consistency:
4140
# this target runs checks on all files
4241

4342
quality:
44-
black --check --preview $(check_dirs)
45-
isort --check-only $(check_dirs)
46-
flake8 $(check_dirs)
43+
black --check $(check_dirs)
44+
ruff $(check_dirs)
4745
doc-builder style src/diffusers docs/source --max_len 119 --check_only --path_to_docs docs/source
4846
python utils/check_doc_toc.py
4947

@@ -57,8 +55,8 @@ extra_style_checks:
5755
# this target runs checks on all files and potentially modifies some of them
5856

5957
style:
60-
black --preview $(check_dirs)
61-
isort $(check_dirs)
58+
black $(check_dirs)
59+
ruff $(check_dirs) --fix
6260
${MAKE} autogenerate_code
6361
${MAKE} extra_style_checks
6462

docs/source/en/conceptual/contribution.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ Follow these steps to start contributing ([supported Python versions](https://gi
177177
$ make style
178178
```
179179

180-
🧨 Diffusers also uses `flake8` and a few custom scripts to check for coding mistakes. Quality
180+
🧨 Diffusers also uses `ruff` and a few custom scripts to check for coding mistakes. Quality
181181
control runs in CI, however you can also run the same checks with:
182182

183183
```bash

docs/source/en/optimization/fp16.mdx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ torch.set_grad_enabled(False)
210210
n_experiments = 2
211211
unet_runs_per_experiment = 50
212212

213+
213214
# load inputs
214215
def generate_inputs():
215216
sample = torch.randn(2, 4, 64, 64).half().cuda()
@@ -288,6 +289,8 @@ pipe = StableDiffusionPipeline.from_pretrained(
288289

289290
# use jitted unet
290291
unet_traced = torch.jit.load("unet_traced.pt")
292+
293+
291294
# del pipe.unet
292295
class TracedUNet(torch.nn.Module):
293296
def __init__(self):

examples/community/bit_diffusion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from typing import Optional, Tuple, Union
22

33
import torch
4+
from einops import rearrange, reduce
45

56
from diffusers import DDIMScheduler, DDPMScheduler, DiffusionPipeline, ImagePipelineOutput, UNet2DConditionModel
67
from diffusers.schedulers.scheduling_ddim import DDIMSchedulerOutput
78
from diffusers.schedulers.scheduling_ddpm import DDPMSchedulerOutput
8-
from einops import rearrange, reduce
99

1010

1111
BITS = 8

examples/community/checkpoint_merger.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
if is_safetensors_available():
1111
import safetensors.torch
1212

13+
from huggingface_hub import snapshot_download
14+
1315
from diffusers import DiffusionPipeline, __version__
1416
from diffusers.schedulers.scheduling_utils import SCHEDULER_CONFIG_NAME
1517
from diffusers.utils import CONFIG_NAME, DIFFUSERS_CACHE, ONNX_WEIGHTS_NAME, WEIGHTS_NAME
16-
from huggingface_hub import snapshot_download
1718

1819

1920
class CheckpointMergerPipeline(DiffusionPipeline):

examples/community/clip_guided_stable_diffusion.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import torch
55
from torch import nn
66
from torch.nn import functional as F
7+
from torchvision import transforms
8+
from transformers import CLIPFeatureExtractor, CLIPModel, CLIPTextModel, CLIPTokenizer
79

810
from diffusers import (
911
AutoencoderKL,
@@ -14,8 +16,6 @@
1416
UNet2DConditionModel,
1517
)
1618
from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion import StableDiffusionPipelineOutput
17-
from torchvision import transforms
18-
from transformers import CLIPFeatureExtractor, CLIPModel, CLIPTextModel, CLIPTokenizer
1919

2020

2121
class MakeCutouts(nn.Module):

examples/community/composable_stable_diffusion.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
from typing import Callable, List, Optional, Union
1717

1818
import torch
19+
from packaging import version
20+
from transformers import CLIPFeatureExtractor, CLIPTextModel, CLIPTokenizer
1921

2022
from diffusers import DiffusionPipeline
2123
from diffusers.configuration_utils import FrozenDict
@@ -29,8 +31,6 @@
2931
PNDMScheduler,
3032
)
3133
from diffusers.utils import is_accelerate_available
32-
from packaging import version
33-
from transformers import CLIPFeatureExtractor, CLIPTextModel, CLIPTokenizer
3434

3535
from ...utils import deprecate, logging
3636
from . import StableDiffusionPipelineOutput

0 commit comments

Comments
 (0)