Skip to content

Commit b1fd1a4

Browse files
authored
Update formatting tooling (#1323)
* First draft to update tooling * Fixed __init__.py generation * quiet make quality * update pre-commit and contributing guide * set back mypy config * FIX test due to moon-landing wording update
1 parent a4b1b33 commit b1fd1a4

File tree

81 files changed

+890
-2123
lines changed

Some content is hidden

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

81 files changed

+890
-2123
lines changed

.github/workflows/python-quality.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ jobs:
2727
run: |
2828
pip install --upgrade pip
2929
pip install .[dev]
30-
- run: black --check tests src
31-
- run: isort --check-only tests src
32-
- run: flake8 tests src
30+
- run: black --check tests src contrib
31+
- run: ruff tests src contrib
3332
- run: python utils/check_contrib_list.py
3433
- run: python utils/check_static_imports.py
3534

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,6 @@ dmypy.json
132132
.idea/
133133

134134
.DS_Store
135+
136+
# Ruff
137+
.ruff_cache

.pre-commit-config.yaml

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,10 @@ repos:
99
- id: check-case-conflict
1010
- id: check-merge-conflict
1111
- repo: https://github.com/psf/black
12-
rev: 22.3.0
12+
rev: 23.1.0
1313
hooks:
1414
- id: black
15-
- repo: https://github.com/pycqa/flake8
16-
rev: 4.0.1
15+
- repo: https://github.com/charliermarsh/ruff-pre-commit # https://github.com/charliermarsh/ruff#usage
16+
rev: 'v0.0.243'
1717
hooks:
18-
- id: flake8
19-
types: [file, python]
20-
- repo: https://github.com/PyCQA/isort
21-
rev: 5.10.1
22-
hooks:
23-
- id: isort
24-
- repo: https://github.com/pre-commit/mirrors-mypy
25-
rev: v0.981
26-
hooks:
27-
- id: mypy
28-
# taken from https://github.com/pre-commit/mirrors-mypy/issues/33#issuecomment-735449356
29-
args: [src, --config-file=pyproject.toml]
30-
pass_filenames: false
31-
# Same list of dependencies as in `setup.py`
32-
additional_dependencies:
33-
[
34-
"types-PyYAML",
35-
"types-requests",
36-
"types-simplejson",
37-
"types-toml",
38-
"types-tqdm",
39-
"types-urllib3",
40-
]
18+
- id: ruff

CONTRIBUTING.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ Follow these steps to start contributing:
155155
$ make test
156156
```
157157

158-
`hugginface_hub` relies on `black` and `isort` to format its source code
158+
`hugginface_hub` relies on `black` and `ruff` to format its source code
159159
consistently. You can install pre-commit hooks so that these styles are
160160
applied and checked on files that you have touched in each commit:
161161

@@ -181,7 +181,7 @@ Follow these steps to start contributing:
181181
$ make style
182182
```
183183

184-
`huggingface_hub` also uses `flake8` and a few custom scripts to check for coding mistakes. Quality
184+
`huggingface_hub` also uses `ruff` and a few custom scripts to check for coding mistakes. Quality
185185
control runs in CI, however you can also run the same checks with:
186186

187187
```bash
@@ -223,7 +223,7 @@ Follow these steps to start contributing:
223223
too! So everyone can see the changes in the Pull request, work in your local
224224
branch and push the changes to your fork. They will automatically appear in
225225
the pull request.
226-
226+
227227
8. Once your changes have been approved, one of the project maintainers will
228228
merge your pull request for you.
229229

@@ -286,4 +286,4 @@ Fully testing Spaces is not possible on staging. We need to use the production e
286286
the tests locally. The token requires write permission and a credit card must be set on
287287
your account.
288288

289-
Note that if the token is not find, the related tests are skipped.
289+
Note that if the token is not find, the related tests are skipped.

Makefile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@ check_dirs := contrib src tests utils setup.py
66

77
quality:
88
black --check $(check_dirs)
9-
isort --check-only $(check_dirs)
10-
flake8 $(check_dirs)
9+
ruff $(check_dirs)
1110
mypy src
1211
python utils/check_contrib_list.py
1312
python utils/check_static_imports.py
1413

1514
style:
1615
black $(check_dirs)
17-
isort $(check_dirs)
16+
ruff $(check_dirs) --fix
1817
python utils/check_contrib_list.py --update
1918
python utils/check_static_imports.py --update
2019

@@ -62,4 +61,4 @@ contrib_%:
6261
contrib: ${CONTRIB_JOBS};
6362
contrib_clear: ${CONTRIB_CLEAR_JOBS}; echo "Successful contrib tests."
6463
contrib_setup: ${CONTRIB_SETUP_JOBS}; echo "Successful contrib setup."
65-
contrib_test: ${CONTRIB_TEST_JOBS}; echo "Successful contrib tests."
64+
contrib_test: ${CONTRIB_TEST_JOBS}; echo "Successful contrib tests."

contrib/sentence_transformers/test_sentence_transformers.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import pytest
2-
32
from sentence_transformers import SentenceTransformer, util
43

54
from ..utils import production_endpoint
@@ -23,12 +22,6 @@ def test_from_pretrained(multi_qa_model: SentenceTransformer) -> None:
2322
print("Similarity:", util.dot_score(query_embedding, passage_embedding))
2423

2524

26-
@pytest.mark.xfail(
27-
reason=(
28-
"Production endpoint is hardcoded in sentence_transformers when pushing to Hub."
29-
)
30-
)
31-
def test_push_to_hub(
32-
multi_qa_model: SentenceTransformer, repo_name: str, cleanup_repo: None
33-
) -> None:
25+
@pytest.mark.xfail(reason="Production endpoint is hardcoded in sentence_transformers when pushing to Hub.")
26+
def test_push_to_hub(multi_qa_model: SentenceTransformer, repo_name: str, cleanup_repo: None) -> None:
3427
multi_qa_model.save_to_hub(repo_name)

contrib/spacy/test_spacy.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
from spacy_huggingface_hub import push
2+
13
from huggingface_hub import delete_repo, hf_hub_download, model_info
24
from huggingface_hub.utils import HfHubHTTPError
3-
from spacy_huggingface_hub import push
45

56
from ..utils import production_endpoint
67

contrib/utils.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@ def test_push_to_hub():
4141

4242
patchers = (
4343
[patch(target + ".ENDPOINT", PROD_ENDPOINT) for target in ENDPOINT_TARGETS]
44-
+ [
45-
patch(target + ".HUGGINGFACE_CO_URL_TEMPLATE", PROD_URL_TEMPLATE)
46-
for target in URL_TEMPLATE_TARGETS
47-
]
44+
+ [patch(target + ".HUGGINGFACE_CO_URL_TEMPLATE", PROD_URL_TEMPLATE) for target in URL_TEMPLATE_TARGETS]
4845
+ [patch.object(api, "endpoint", PROD_URL_TEMPLATE)]
4946
)
5047

pyproject.toml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
[tool.black]
2-
line-length = 88
2+
line-length = 119
33
target_version = ['py37', 'py38', 'py39', 'py310']
44
preview = true
55

66
[tool.mypy]
77
ignore_missing_imports = true
88
no_implicit_optional = true
9-
scripts_are_modules = true
9+
scripts_are_modules = true
10+
11+
[tool.ruff]
12+
# Ignored rules:
13+
# "E501" -> line length violation
14+
# "F821" -> undefined named in type annotation (e.g. Literal["something"])
15+
ignore = ["E501", "F821"]
16+
select = ["E", "F", "I", "W"]
17+
line-length = 119
18+
19+
[tool.ruff.isort]
20+
lines-after-imports = 2
21+
known-first-party = ["huggingface_hub"]

setup.cfg

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,3 @@
1-
[isort]
2-
default_section = FIRSTPARTY
3-
ensure_newline_before_comments = True
4-
force_grid_wrap = 0
5-
include_trailing_comma = True
6-
known_first_party = huggingface_hub
7-
known_third_party =
8-
absl
9-
conllu
10-
datasets
11-
elasticsearch
12-
fairseq
13-
faiss-cpu
14-
fastprogress
15-
fire
16-
fugashi
17-
git
18-
graphviz
19-
h5py
20-
matplotlib
21-
nltk
22-
numpy
23-
packaging
24-
pandas
25-
pydot
26-
PIL
27-
psutil
28-
pytest
29-
pytorch_lightning
30-
rouge_score
31-
sacrebleu
32-
seqeval
33-
sklearn
34-
streamlit
35-
tensorboardX
36-
tensorflow
37-
tensorflow_datasets
38-
timeout_decorator
39-
torch
40-
torchtext
41-
torchvision
42-
torch_xla
43-
tqdm
44-
45-
line_length = 88
46-
lines_after_imports = 2
47-
multi_line_output = 3
48-
use_parentheses = True
49-
50-
[flake8]
51-
exclude = .git,__pycache__,old,build,dist,.venv*
52-
ignore = B028, E203, E501, E741, W503
53-
max-line-length = 88
54-
551
[tool:pytest]
562
# -Werror::FutureWarning -> test fails if FutureWarning is thrown
573
# -s -> logs are not captured
@@ -61,4 +7,4 @@ max-line-length = 88
617
addopts = -Werror::FutureWarning --log-cli-level=INFO -sv --durations=0
628
env =
639
HUGGINGFACE_CO_STAGING=1
64-
DISABLE_SYMLINKS_IN_WINDOWS_TESTS=1
10+
DISABLE_SYMLINKS_IN_WINDOWS_TESTS=1

0 commit comments

Comments
 (0)