Skip to content

Commit

Permalink
Update formatting tooling (#1323)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Wauplin authored Feb 7, 2023
1 parent a4b1b33 commit b1fd1a4
Show file tree
Hide file tree
Showing 81 changed files with 890 additions and 2,123 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/python-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ jobs:
run: |
pip install --upgrade pip
pip install .[dev]
- run: black --check tests src
- run: isort --check-only tests src
- run: flake8 tests src
- run: black --check tests src contrib
- run: ruff tests src contrib
- run: python utils/check_contrib_list.py
- run: python utils/check_static_imports.py

Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,6 @@ dmypy.json
.idea/

.DS_Store

# Ruff
.ruff_cache
30 changes: 4 additions & 26 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,10 @@ repos:
- id: check-case-conflict
- id: check-merge-conflict
- repo: https://github.com/psf/black
rev: 22.3.0
rev: 23.1.0
hooks:
- id: black
- repo: https://github.com/pycqa/flake8
rev: 4.0.1
- repo: https://github.com/charliermarsh/ruff-pre-commit # https://github.com/charliermarsh/ruff#usage
rev: 'v0.0.243'
hooks:
- id: flake8
types: [file, python]
- repo: https://github.com/PyCQA/isort
rev: 5.10.1
hooks:
- id: isort
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.981
hooks:
- id: mypy
# taken from https://github.com/pre-commit/mirrors-mypy/issues/33#issuecomment-735449356
args: [src, --config-file=pyproject.toml]
pass_filenames: false
# Same list of dependencies as in `setup.py`
additional_dependencies:
[
"types-PyYAML",
"types-requests",
"types-simplejson",
"types-toml",
"types-tqdm",
"types-urllib3",
]
- id: ruff
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ Follow these steps to start contributing:
$ make test
```

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

Expand All @@ -181,7 +181,7 @@ Follow these steps to start contributing:
$ make style
```

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

```bash
Expand Down Expand Up @@ -223,7 +223,7 @@ Follow these steps to start contributing:
too! So everyone can see the changes in the Pull request, work in your local
branch and push the changes to your fork. They will automatically appear in
the pull request.

8. Once your changes have been approved, one of the project maintainers will
merge your pull request for you.

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

Note that if the token is not find, the related tests are skipped.
Note that if the token is not find, the related tests are skipped.
7 changes: 3 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ check_dirs := contrib src tests utils setup.py

quality:
black --check $(check_dirs)
isort --check-only $(check_dirs)
flake8 $(check_dirs)
ruff $(check_dirs)
mypy src
python utils/check_contrib_list.py
python utils/check_static_imports.py

style:
black $(check_dirs)
isort $(check_dirs)
ruff $(check_dirs) --fix
python utils/check_contrib_list.py --update
python utils/check_static_imports.py --update

Expand Down Expand Up @@ -62,4 +61,4 @@ contrib_%:
contrib: ${CONTRIB_JOBS};
contrib_clear: ${CONTRIB_CLEAR_JOBS}; echo "Successful contrib tests."
contrib_setup: ${CONTRIB_SETUP_JOBS}; echo "Successful contrib setup."
contrib_test: ${CONTRIB_TEST_JOBS}; echo "Successful contrib tests."
contrib_test: ${CONTRIB_TEST_JOBS}; echo "Successful contrib tests."
11 changes: 2 additions & 9 deletions contrib/sentence_transformers/test_sentence_transformers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pytest

from sentence_transformers import SentenceTransformer, util

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


@pytest.mark.xfail(
reason=(
"Production endpoint is hardcoded in sentence_transformers when pushing to Hub."
)
)
def test_push_to_hub(
multi_qa_model: SentenceTransformer, repo_name: str, cleanup_repo: None
) -> None:
@pytest.mark.xfail(reason="Production endpoint is hardcoded in sentence_transformers when pushing to Hub.")
def test_push_to_hub(multi_qa_model: SentenceTransformer, repo_name: str, cleanup_repo: None) -> None:
multi_qa_model.save_to_hub(repo_name)
3 changes: 2 additions & 1 deletion contrib/spacy/test_spacy.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from spacy_huggingface_hub import push

from huggingface_hub import delete_repo, hf_hub_download, model_info
from huggingface_hub.utils import HfHubHTTPError
from spacy_huggingface_hub import push

from ..utils import production_endpoint

Expand Down
5 changes: 1 addition & 4 deletions contrib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ def test_push_to_hub():

patchers = (
[patch(target + ".ENDPOINT", PROD_ENDPOINT) for target in ENDPOINT_TARGETS]
+ [
patch(target + ".HUGGINGFACE_CO_URL_TEMPLATE", PROD_URL_TEMPLATE)
for target in URL_TEMPLATE_TARGETS
]
+ [patch(target + ".HUGGINGFACE_CO_URL_TEMPLATE", PROD_URL_TEMPLATE) for target in URL_TEMPLATE_TARGETS]
+ [patch.object(api, "endpoint", PROD_URL_TEMPLATE)]
)

Expand Down
16 changes: 14 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
[tool.black]
line-length = 88
line-length = 119
target_version = ['py37', 'py38', 'py39', 'py310']
preview = true

[tool.mypy]
ignore_missing_imports = true
no_implicit_optional = true
scripts_are_modules = true
scripts_are_modules = true

[tool.ruff]
# Ignored rules:
# "E501" -> line length violation
# "F821" -> undefined named in type annotation (e.g. Literal["something"])
ignore = ["E501", "F821"]
select = ["E", "F", "I", "W"]
line-length = 119

[tool.ruff.isort]
lines-after-imports = 2
known-first-party = ["huggingface_hub"]
56 changes: 1 addition & 55 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,57 +1,3 @@
[isort]
default_section = FIRSTPARTY
ensure_newline_before_comments = True
force_grid_wrap = 0
include_trailing_comma = True
known_first_party = huggingface_hub
known_third_party =
absl
conllu
datasets
elasticsearch
fairseq
faiss-cpu
fastprogress
fire
fugashi
git
graphviz
h5py
matplotlib
nltk
numpy
packaging
pandas
pydot
PIL
psutil
pytest
pytorch_lightning
rouge_score
sacrebleu
seqeval
sklearn
streamlit
tensorboardX
tensorflow
tensorflow_datasets
timeout_decorator
torch
torchtext
torchvision
torch_xla
tqdm

line_length = 88
lines_after_imports = 2
multi_line_output = 3
use_parentheses = True

[flake8]
exclude = .git,__pycache__,old,build,dist,.venv*
ignore = B028, E203, E501, E741, W503
max-line-length = 88

[tool:pytest]
# -Werror::FutureWarning -> test fails if FutureWarning is thrown
# -s -> logs are not captured
Expand All @@ -61,4 +7,4 @@ max-line-length = 88
addopts = -Werror::FutureWarning --log-cli-level=INFO -sv --durations=0
env =
HUGGINGFACE_CO_STAGING=1
DISABLE_SYMLINKS_IN_WINDOWS_TESTS=1
DISABLE_SYMLINKS_IN_WINDOWS_TESTS=1
23 changes: 5 additions & 18 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ def get_version() -> str:
extras["tensorflow"] = ["tensorflow", "pydot", "graphviz"]

extras["testing"] = extras["cli"] + [
"isort>=5.5.4",
"jedi",
"Jinja2",
"pytest",
Expand All @@ -64,10 +63,8 @@ def get_version() -> str:
]

extras["quality"] = [
"black==22.3",
"flake8>=3.8.3",
"flake8-bugbear",
"isort>=5.5.4",
"black~=23.1",
"ruff>=0.0.241",
"mypy==0.982",
]

Expand All @@ -81,26 +78,16 @@ def get_version() -> str:
version=get_version(),
author="Hugging Face, Inc.",
author_email="[email protected]",
description=(
"Client library to download and publish models, datasets and other repos on the"
" huggingface.co hub"
),
description="Client library to download and publish models, datasets and other repos on the huggingface.co hub",
long_description=open("README.md", "r", encoding="utf-8").read(),
long_description_content_type="text/markdown",
keywords=(
"model-hub machine-learning models natural-language-processing deep-learning"
" pytorch pretrained-models"
),
keywords="model-hub machine-learning models natural-language-processing deep-learning pytorch pretrained-models",
license="Apache",
url="https://github.com/huggingface/huggingface_hub",
package_dir={"": "src"},
packages=find_packages("src"),
extras_require=extras,
entry_points={
"console_scripts": [
"huggingface-cli=huggingface_hub.commands.huggingface_cli:main"
]
},
entry_points={"console_scripts": ["huggingface-cli=huggingface_hub.commands.huggingface_cli:main"]},
python_requires=">=3.7.0",
install_requires=install_requires,
classifiers=[
Expand Down
Loading

0 comments on commit b1fd1a4

Please sign in to comment.