Skip to content

Commit 651408a

Browse files
[Styling] stylify using ruff (#27144)
* try to stylify using ruff * might need to remove these changes? * use ruf format andruff check * use isinstance instead of type comparision * use # fmt: skip * use # fmt: skip * nits * soem styling changes * update ci job * nits isinstance * more files update * nits * more nits * small nits * check and format * revert wrong changes * actually use formatter instead of checker * nits * well docbuilder is overwriting this commit * revert notebook changes * try to nuke docbuilder * style * fix feature exrtaction test * remve `indent-width = 4` * fixup * more nits * update the ruff version that we use * style * nuke docbuilder styling * leve the print for detected changes * nits * Remove file I/O Co-authored-by: charliermarsh <[email protected]> * style * nits * revert notebook changes * Add # fmt skip when possible * Add # fmt skip when possible * Fix * More ` # fmt: skip` usage * More ` # fmt: skip` usage * More ` # fmt: skip` usage * NIts * more fixes * fix tapas * Another way to skip * Recommended way * Fix two more fiels * Remove asynch Remove asynch --------- Co-authored-by: charliermarsh <[email protected]>
1 parent acb5b4a commit 651408a

File tree

480 files changed

+868
-1060
lines changed

Some content is hidden

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

480 files changed

+868
-1060
lines changed

.circleci/config.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,10 @@ jobs:
157157
command: pip freeze | tee installed.txt
158158
- store_artifacts:
159159
path: ~/transformers/installed.txt
160-
- run: black --check examples tests src utils
161-
- run: ruff examples tests src utils
160+
- run: ruff check examples tests src utils
161+
- run: ruff format tests src utils --check
162162
- run: python utils/custom_init_isort.py --check_only
163163
- run: python utils/sort_auto_mappings.py --check_only
164-
- run: doc-builder style src/transformers docs/source --max_len 119 --check_only --path_to_docs docs/source
165164
- run: python utils/check_doc_toc.py
166165

167166
check_repository_consistency:

.circleci/create_circleci_config.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
import argparse
1717
import copy
18-
import glob
1918
import os
2019
import random
2120
from dataclasses import dataclass
@@ -239,7 +238,7 @@ def to_dict(self):
239238

240239
py_command = f'import os; fp = open("reports/{self.job_name}/summary_short.txt"); failed = os.linesep.join([x for x in fp.read().split(os.linesep) if x.startswith("ERROR ")]); fp.close(); fp = open("summary_short.txt", "w"); fp.write(failed); fp.close()'
241240
check_test_command += f"$(python3 -c '{py_command}'); "
242-
check_test_command += f'cat summary_short.txt; echo ""; exit -1; '
241+
check_test_command += 'cat summary_short.txt; echo ""; exit -1; '
243242

244243
# Deeal with failed tests
245244
check_test_command += f'elif [ -s reports/{self.job_name}/failures_short.txt ]; '
@@ -249,7 +248,7 @@ def to_dict(self):
249248

250249
py_command = f'import os; fp = open("reports/{self.job_name}/summary_short.txt"); failed = os.linesep.join([x for x in fp.read().split(os.linesep) if x.startswith("FAILED ")]); fp.close(); fp = open("summary_short.txt", "w"); fp.write(failed); fp.close()'
251250
check_test_command += f"$(python3 -c '{py_command}'); "
252-
check_test_command += f'cat summary_short.txt; echo ""; exit -1; '
251+
check_test_command += 'cat summary_short.txt; echo ""; exit -1; '
253252

254253
check_test_command += f'elif [ -s reports/{self.job_name}/stats.txt ]; then echo "All tests pass!"; '
255254

Makefile

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +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 $(modified_py_files); \
13-
ruff $(modified_py_files) --fix; \
12+
ruff check $(modified_py_files) --fix; \
13+
ruff format $(modified_py_files);\
1414
else \
1515
echo "No library .py files were modified"; \
1616
fi
@@ -48,26 +48,24 @@ repo-consistency:
4848
# this target runs checks on all files
4949

5050
quality:
51-
black --check $(check_dirs) setup.py conftest.py
51+
ruff check $(check_dirs) setup.py conftest.py
52+
ruff format --check $(check_dirs) setup.py conftest.py
5253
python utils/custom_init_isort.py --check_only
5354
python utils/sort_auto_mappings.py --check_only
54-
ruff $(check_dirs) setup.py conftest.py
55-
doc-builder style src/transformers docs/source --max_len 119 --check_only --path_to_docs docs/source
5655
python utils/check_doc_toc.py
5756

5857
# Format source code automatically and check is there are any problems left that need manual fixing
5958

6059
extra_style_checks:
6160
python utils/custom_init_isort.py
6261
python utils/sort_auto_mappings.py
63-
doc-builder style src/transformers docs/source --max_len 119 --path_to_docs docs/source
6462
python utils/check_doc_toc.py --fix_and_overwrite
6563

6664
# this target runs checks on all files and potentially modifies some of them
6765

6866
style:
69-
black $(check_dirs) setup.py conftest.py
70-
ruff $(check_dirs) setup.py conftest.py --fix
67+
ruff check $(check_dirs) setup.py conftest.py --fix
68+
ruff format $(check_dirs) setup.py conftest.py
7169
${MAKE} autogenerate_code
7270
${MAKE} extra_style_checks
7371

docs/source/_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
black_avoid_patterns = {
1111
"{processor_class}": "FakeProcessorClass",
1212
"{model_class}": "FakeModelClass",
13-
"{object_class}": "FakeObjectClass",
13+
"{object_class}": "FakeObjectClass",
1414
}

docs/source/en/_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
black_avoid_patterns = {
1111
"{processor_class}": "FakeProcessorClass",
1212
"{model_class}": "FakeModelClass",
13-
"{object_class}": "FakeObjectClass",
13+
"{object_class}": "FakeObjectClass",
1414
}

docs/source/en/tasks/semantic_segmentation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ logits first, and then reshaped to match the size of the labels before you can c
245245
... reduce_labels=False,
246246
... )
247247
... for key, value in metrics.items():
248-
... if type(value) is np.ndarray:
248+
... if isinstance(value, np.ndarray):
249249
... metrics[key] = value.tolist()
250250
... return metrics
251251
```

docs/source/ko/_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
black_avoid_patterns = {
1111
"{processor_class}": "FakeProcessorClass",
1212
"{model_class}": "FakeModelClass",
13-
"{object_class}": "FakeObjectClass",
13+
"{object_class}": "FakeObjectClass",
1414
}

docs/source/ko/tasks/semantic_segmentation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ pip install -q datasets transformers evaluate
242242
... reduce_labels=False,
243243
... )
244244
... for key, value in metrics.items():
245-
... if type(value) is np.ndarray:
245+
... if isinstance(value, np.ndarray):
246246
... metrics[key] = value.tolist()
247247
... return metrics
248248
```

docs/source/pt/_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
black_avoid_patterns = {
1111
"{processor_class}": "FakeProcessorClass",
1212
"{model_class}": "FakeModelClass",
13-
"{object_class}": "FakeObjectClass",
13+
"{object_class}": "FakeObjectClass",
1414
}

examples/flax/text-classification/run_flax_glue.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def __post_init__(self):
212212
if self.validation_file is not None:
213213
extension = self.validation_file.split(".")[-1]
214214
assert extension in ["csv", "json"], "`validation_file` should be a csv or a json file."
215-
self.task_name = self.task_name.lower() if type(self.task_name) == str else self.task_name
215+
self.task_name = self.task_name.lower() if isinstance(self.task_name, str) else self.task_name
216216

217217

218218
def create_train_state(

0 commit comments

Comments
 (0)