Skip to content

Commit

Permalink
Cleanup quality (huggingface#21493)
Browse files Browse the repository at this point in the history
* Remove mentions of flake8/isort

* Clean up inits

* Deall with all other inits

* Last special rule for dummy files
  • Loading branch information
sgugger authored Feb 7, 2023
1 parent 571fa58 commit 67d0748
Show file tree
Hide file tree
Showing 220 changed files with 26 additions and 832 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,7 @@ tags
*.lock

# DS_Store (MacOS)
.DS_Store
.DS_Store

# ruff
.ruff_cache
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ You'll need **[Python 3.7]((https://github.com/huggingface/transformers/blob/mai
For more information about tests, check out the
[Testing](https://huggingface.co/docs/transformers/testing) guide.

🤗 Transformers relies on `black` and `isort` to format its source code
🤗 Transformers relies on `black` and `ruff` to format its source code
consistently. After you make changes, apply automatic style corrections and code verifications
that can't be automated in one go with:

Expand All @@ -199,7 +199,7 @@ You'll need **[Python 3.7]((https://github.com/huggingface/transformers/blob/mai
$ make style
```

🤗 Transformers also uses `flake8` and a few custom scripts to check for coding mistakes. Quality
🤗 Transformers also uses `ruff` and a few custom scripts to check for coding mistakes. Quality
controls are run by the CI, but you can run the same checks with:

```bash
Expand Down
2 changes: 1 addition & 1 deletion docs/source/en/add_new_model.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Along the way, you'll:
- get insights into open-source best practices
- understand the design principles behind one of the most popular deep learning libraries
- learn how to efficiently test large models
- learn how to integrate Python utilities like `black`, `isort`, and `make fix-copies` to ensure clean and readable code
- learn how to integrate Python utilities like `black`, `ruff`, and `make fix-copies` to ensure clean and readable code

A Hugging Face team member will be available to help you along the way so you'll never be alone. 🤗 ❤️

Expand Down
4 changes: 2 additions & 2 deletions docs/source/en/pr_checks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ If you're interested in building or previewing the documentation locally, take a

## Code and documentation style

Code formatting is applied to all the source files, the examples and the tests using `black` and `isort`. We also have a custom tool taking care of the formatting of docstrings and `rst` files (`utils/style_doc.py`), as well as the order of the lazy imports performed in the Transformers `__init__.py` files (`utils/custom_init_isort.py`). All of this can be launched by executing
Code formatting is applied to all the source files, the examples and the tests using `black` and `ruff`. We also have a custom tool taking care of the formatting of docstrings and `rst` files (`utils/style_doc.py`), as well as the order of the lazy imports performed in the Transformers `__init__.py` files (`utils/custom_init_isort.py`). All of this can be launched by executing

```bash
make style
```

The CI checks those have been applied inside the `ci/circleci: check_code_quality` check. It also runs `flake8`, that will have a basic look at your code and will complain if it finds an undefined variable, or one that is not used. To run that check locally, use
The CI checks those have been applied inside the `ci/circleci: check_code_quality` check. It also runs `ruff`, that will have a basic look at your code and will complain if it finds an undefined variable, or one that is not used. To run that check locally, use

```bash
make quality
Expand Down
4 changes: 2 additions & 2 deletions docs/source/es/pr_checks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ Si estás interesado en compilar u obtener una vista previa de la documentación

## Estilo de código y documentación.

El formato de código se aplica a todos los archivos fuente, los ejemplos y las pruebas utilizando `black` e `isort`. También tenemos una herramienta personalizada que se ocupa del formato de los _docstrings_ y archivos `rst` (`utils/style_doc.py`), así como del orden de las importaciones _lazy_ realizadas en los archivos `__init__.py` de Transformers (`utils /custom_init_isort.py`). Todo esto se puede probar ejecutando
El formato de código se aplica a todos los archivos fuente, los ejemplos y las pruebas utilizando `black` e `ruff`. También tenemos una herramienta personalizada que se ocupa del formato de los _docstrings_ y archivos `rst` (`utils/style_doc.py`), así como del orden de las importaciones _lazy_ realizadas en los archivos `__init__.py` de Transformers (`utils /custom_init_isort.py`). Todo esto se puede probar ejecutando

```bash
make style
```

CI verifica que se hayan aplicado dentro de la verificación `ci/circleci: check_code_quality`. También se ejecuta `flake8`, que hará una verificación básica a tu código y te hará saber si encuentra una variable no definida, o una que no se usa. Para ejecutar esa verificación localmente, usa
CI verifica que se hayan aplicado dentro de la verificación `ci/circleci: check_code_quality`. También se ejecuta `ruff`, que hará una verificación básica a tu código y te hará saber si encuentra una variable no definida, o una que no se usa. Para ejecutar esa verificación localmente, usa

```bash
make quality
Expand Down
2 changes: 1 addition & 1 deletion docs/source/it/add_new_model.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ sarai l'artefice di un importante contributo open-source a 🤗 Transformers. Du
- ottenere più comprensione delle best practices in open-source
- capire i principi di design di una della librerie NLP più popolari
- capire come efficientemente testare complessi modelli NLP
- capire come integrare utilit Python come `black`, `isort`, `make fix-copies` in una libreria per garantire sempre di avere un codice leggibile e pulito
- capire come integrare utilit Python come `black`, `ruff`, `make fix-copies` in una libreria per garantire sempre di avere un codice leggibile e pulito

Siamo anche contenti se vuoi aggiungere un modello che non può essere trovato nella cartella “calls-for-model-addition”.
Le seguenti sezioni spiegano in dettaglio come aggiungere un nuovo modello. Può anche essere molto utile controllare modelli
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# flake8: noqa
from .configuration_bert_masked import MaskedBertConfig
from .modeling_bert_masked import (
MaskedBertForMultipleChoice,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# flake8: noqa
from .binarizer import MagnitudeBinarizer, ThresholdBinarizer, TopKBinarizer
from .masked_nn import MaskedLinear
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ ignore = ["E501", "E741", "W605"]
select = ["E", "F", "I", "W"]
line-length = 119

# Ignore import violations in all `__init__.py` files.
[tool.ruff.per-file-ignores]
"__init__.py" = ["E402", "F401", "F403", "F811"]
"src/transformers/file_utils.py" = ["F401"]
"src/transformers/utils/dummy_*.py" = ["F401"]

[tool.ruff.isort]
lines-after-imports = 2
known-first-party = ["transformers"]
4 changes: 0 additions & 4 deletions src/transformers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# flake8: noqa
# There's no way to ignore "F401 '...' imported but unused" warnings in this
# module, but to preserve other warnings. So, don't check this module at all.

# Copyright 2020 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
4 changes: 0 additions & 4 deletions src/transformers/data/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# flake8: noqa
# There's no way to ignore "F401 '...' imported but unused" warnings in this
# module, but to preserve other warnings. So, don't check this module at all.

# Copyright 2020 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
4 changes: 0 additions & 4 deletions src/transformers/data/datasets/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# flake8: noqa
# There's no way to ignore "F401 '...' imported but unused" warnings in this
# module, but to preserve other warnings. So, don't check this module at all.

# Copyright 2020 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
4 changes: 0 additions & 4 deletions src/transformers/data/metrics/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# coding=utf-8
# Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team.
# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Expand Down
4 changes: 0 additions & 4 deletions src/transformers/data/processors/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# flake8: noqa
# There's no way to ignore "F401 '...' imported but unused" warnings in this
# module, but to preserve other warnings. So, don't check this module at all.

# Copyright 2020 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
4 changes: 0 additions & 4 deletions src/transformers/file_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# flake8: noqa
# There's no way to ignore "F401 '...' imported but unused" warnings in this
# module, but to preserve other warnings. So, don't check this module at all.

# Copyright 2020 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
4 changes: 0 additions & 4 deletions src/transformers/generation/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# flake8: noqa
# There's no way to ignore "F401 '...' imported but unused" warnings in this
# module, but to preserve other warnings. So, don't check this module at all.

# Copyright 2022 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
4 changes: 0 additions & 4 deletions src/transformers/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# flake8: noqa
# There's no way to ignore "F401 '...' imported but unused" warnings in this
# module, but to preserve other warnings. So, don't check this module at all.

# Copyright 2020 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
4 changes: 0 additions & 4 deletions src/transformers/models/albert/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# flake8: noqa
# There's no way to ignore "F401 '...' imported but unused" warnings in this
# module, but to preserve other warnings. So, don't check this module at all.

# Copyright 2020 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
5 changes: 0 additions & 5 deletions src/transformers/models/altclip/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# flake8: noqa
# There's no way to ignore "F401 '...' imported but unused" warnings in this
# module, but to preserve other warnings. So, don't check this module at all.

# Copyright 2020 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -17,7 +13,6 @@
# limitations under the License.
from typing import TYPE_CHECKING

# rely on isort to merge the imports
from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tokenizers_available, is_torch_available


Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# flake8: noqa
# There's no way to ignore "F401 '...' imported but unused" warnings in this
# module, but to preserve other warnings. So, don't check this module at all.

# Copyright 2021 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
4 changes: 0 additions & 4 deletions src/transformers/models/auto/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# flake8: noqa
# There's no way to ignore "F401 '...' imported but unused" warnings in this
# module, but to preserve other warnings. So, don't check this module at all.

# Copyright 2020 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
4 changes: 0 additions & 4 deletions src/transformers/models/bart/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# flake8: noqa
# There's no way to ignore "F401 '...' imported but unused" warnings in this
# module, but to preserve other warnings. So, don't check this module at all.

# Copyright 2020 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
4 changes: 0 additions & 4 deletions src/transformers/models/barthez/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# flake8: noqa
# There's no way to ignore "F401 '...' imported but unused" warnings in this
# module, but to preserve other warnings. So, don't check this module at all.

# Copyright 2020 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
4 changes: 0 additions & 4 deletions src/transformers/models/bartpho/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# flake8: noqa
# There's no way to ignore "F401 '...' imported but unused" warnings in this
# module, but to preserve other warnings. So, don't check this module at all.

# Copyright 2021 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
4 changes: 0 additions & 4 deletions src/transformers/models/beit/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# flake8: noqa
# There's no way to ignore "F401 '...' imported but unused" warnings in this
# module, but to preserve other warnings. So, don't check this module at all.

# Copyright 2021 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
4 changes: 0 additions & 4 deletions src/transformers/models/bert/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# flake8: noqa
# There's no way to ignore "F401 '...' imported but unused" warnings in this
# module, but to preserve other warnings. So, don't check this module at all.

# Copyright 2020 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
4 changes: 0 additions & 4 deletions src/transformers/models/bert_generation/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# flake8: noqa
# There's no way to ignore "F401 '...' imported but unused" warnings in this
# module, but to preserve other warnings. So, don't check this module at all.

# Copyright 2020 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
4 changes: 0 additions & 4 deletions src/transformers/models/bert_japanese/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# flake8: noqa
# There's no way to ignore "F401 '...' imported but unused" warnings in this
# module, but to preserve other warnings. So, don't check this module at all.

# Copyright 2020 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
4 changes: 0 additions & 4 deletions src/transformers/models/bertweet/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# flake8: noqa
# There's no way to ignore "F401 '...' imported but unused" warnings in this
# module, but to preserve other warnings. So, don't check this module at all.

# Copyright 2020 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
4 changes: 0 additions & 4 deletions src/transformers/models/big_bird/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# flake8: noqa
# There's no way to ignore "F401 '...' imported but unused" warnings in this
# module, but to preserve other warnings. So, don't check this module at all.

# Copyright 2021 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
4 changes: 0 additions & 4 deletions src/transformers/models/bigbird_pegasus/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# flake8: noqa
# There's no way to ignore "F401 '...' imported but unused" warnings in this
# module, but to preserve other warnings. So, don't check this module at all.

# Copyright 2021 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
5 changes: 0 additions & 5 deletions src/transformers/models/biogpt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# flake8: noqa
# There's no way to ignore "F401 '...' imported but unused" warnings in this
# module, but to preserve other warnings. So, don't check this module at all.

# Copyright 2022 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -17,7 +13,6 @@
# limitations under the License.
from typing import TYPE_CHECKING

# rely on isort to merge the imports
from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tokenizers_available, is_torch_available


Expand Down
5 changes: 0 additions & 5 deletions src/transformers/models/bit/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# flake8: noqa
# There's no way to ignore "F401 '...' imported but unused" warnings in this
# module, but to preserve other warnings. So, don't check this module at all.

# Copyright 2022 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -17,7 +13,6 @@
# limitations under the License.
from typing import TYPE_CHECKING

# rely on isort to merge the imports
from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available


Expand Down
4 changes: 0 additions & 4 deletions src/transformers/models/blenderbot/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# flake8: noqa
# There's no way to ignore "F401 '...' imported but unused" warnings in this
# module, but to preserve other warnings. So, don't check this module at all.

# Copyright 2020 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
4 changes: 0 additions & 4 deletions src/transformers/models/blenderbot_small/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# flake8: noqa
# There's no way to ignore "F401 '...' imported but unused" warnings in this
# module, but to preserve other warnings. So, don't check this module at all.

# Copyright 2020 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
4 changes: 0 additions & 4 deletions src/transformers/models/blip/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# flake8: noqa
# There's no way to ignore "F401 '...' imported but unused" warnings in this
# module, but to preserve other warnings. So, don't check this module at all.

# Copyright 2022 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
4 changes: 0 additions & 4 deletions src/transformers/models/bloom/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# flake8: noqa
# There's no way to ignore "F401 '...' imported but unused" warnings in this
# module, but to preserve other warnings. So, don't check this module at all.

# Copyright 2022 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
5 changes: 0 additions & 5 deletions src/transformers/models/bridgetower/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# flake8: noqa
# There's no way to ignore "F401 '...' imported but unused" warnings in this
# module, but to preserve other warnings. So, don't check this module at all.

# Copyright 2023 The Intel Labs Team Authors, The Microsoft Research Team Authors and HuggingFace Inc. team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -17,7 +13,6 @@
# limitations under the License.
from typing import TYPE_CHECKING

# rely on isort to merge the imports
from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available


Expand Down
4 changes: 0 additions & 4 deletions src/transformers/models/byt5/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# flake8: noqa
# There's no way to ignore "F401 '...' imported but unused" warnings in this
# module, but to preserve other warnings. So, don't check this module at all.

# Copyright 2021 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
4 changes: 0 additions & 4 deletions src/transformers/models/camembert/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# flake8: noqa
# There's no way to ignore "F401 '...' imported but unused" warnings in this
# module, but to preserve other warnings. So, don't check this module at all.

# Copyright 2020 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
4 changes: 0 additions & 4 deletions src/transformers/models/canine/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# flake8: noqa
# There's no way to ignore "F401 '...' imported but unused" warnings in this
# module, but to preserve other warnings. So, don't check this module at all.

# Copyright 2020 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
4 changes: 0 additions & 4 deletions src/transformers/models/chinese_clip/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# flake8: noqa
# There's no way to ignore "F401 '...' imported but unused" warnings in this
# module, but to preserve other warnings. So, don't check this module at all.

# Copyright 2022 The OFA-Sys Team Authors and The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
Loading

0 comments on commit 67d0748

Please sign in to comment.