Skip to content

Commit

Permalink
Add autocomplete + tests + type checking (#1041)
Browse files Browse the repository at this point in the history
* Add autocomplete + tests + type checking

* add isort as a dev dependency

* also reorder attributes definition for readability

* add types for mypy

* add simplejson types

* do not raise on follow imports with mypy in CI

* remove unused mypy plugins

* more readable code generation ?

* Move static import formatter to a separate util and add it to makefile

* add check to workflow

* pragma no cover in init.py
  • Loading branch information
Wauplin authored Sep 12, 2022
1 parent b9d8617 commit be0e648
Show file tree
Hide file tree
Showing 6 changed files with 455 additions and 141 deletions.
29 changes: 17 additions & 12 deletions .github/workflows/python-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,20 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install dependencies
run: |
pip install --upgrade pip
pip install .[dev]
- run: black --check tests src
- run: isort --check-only tests src
- run: flake8 tests src
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install dependencies
run: |
pip install --upgrade pip
pip install .[dev]
- run: black --check tests src
- run: isort --check-only tests src
- run: flake8 tests src
- run: python utils/check_static_imports.py

# Run type checking at least on huggingface_hub root file to check all modules
# that can be lazy-loaded actually exist.
- run: mypy src/huggingface_hub/__init__.py --follow-imports=silent
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
.PHONY: quality style test


check_dirs := tests src setup.py
check_dirs := tests src utils setup.py


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

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

test:
HUGGINGFACE_CO_STAGING=1 pytest -sv ./tests/
Expand Down
9 changes: 6 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,21 @@ def get_version() -> str:
extras["tensorflow"] = ["tensorflow", "pydot", "graphviz"]

extras["testing"] = [
"datasets",
"isort>=5.5.4",
"jedi",
"Jinja2",
"pytest",
"pytest-cov",
"datasets",
"soundfile",
"Jinja2",
]

extras["quality"] = [
"black==22.3",
"isort>=5.5.4",
"flake8>=3.8.3",
"flake8-bugbear",
"isort>=5.5.4",
"mypy",
]

extras["all"] = extras["testing"] + extras["quality"]
Expand Down
Loading

0 comments on commit be0e648

Please # to comment.