Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
f22d1cb
First draft for a contrib test suite + test for timm contrib
Wauplin Nov 18, 2022
fc1da54
run only Python 3.8
Wauplin Nov 18, 2022
24427d3
Merge branch 'main' into 1190-rfc-add-contrib-test-suite
Wauplin Nov 18, 2022
64185aa
remove commented code
Wauplin Nov 18, 2022
572ca56
Merge branch 'main' into 1190-rfc-add-contrib-test-suite
Wauplin Nov 18, 2022
e4766a7
Merge branch 'main' into 1190-rfc-add-contrib-test-suite
Wauplin Nov 21, 2022
af45cdb
Run contrib tests in separate environments
Wauplin Nov 21, 2022
821aa04
fix ci
Wauplin Nov 21, 2022
2a0d7c6
fix ci again
Wauplin Nov 21, 2022
339af7f
and now ?
Wauplin Nov 21, 2022
68c26b2
stupid me
Wauplin Nov 21, 2022
1eb0a09
this time ?
Wauplin Nov 21, 2022
d4a72e7
Refactor how to run contrib tests locally
Wauplin Nov 22, 2022
aa1ffad
add tests for sentence_transformers
Wauplin Nov 22, 2022
930c29e
amke style
Wauplin Nov 22, 2022
625768d
Update contrib/README.md
Wauplin Nov 23, 2022
7b28a5f
Merge branch 'main' into 1190-rfc-add-contrib-test-suite
Wauplin Nov 23, 2022
987ec8a
Merge branch 'main' into 1190-rfc-add-contrib-test-suite
Wauplin Nov 24, 2022
12aa4ba
ADapt timm tests
Wauplin Nov 24, 2022
173aff8
Include feedback form osanseviero
Wauplin Nov 25, 2022
cd11be8
Merge branch 'main' into 1190-rfc-add-contrib-test-suite
Wauplin Nov 25, 2022
b148848
Merge branch 'main' into 1190-rfc-add-contrib-test-suite
Wauplin Nov 25, 2022
d8ddba6
Merge branch 'main' into 1190-rfc-add-contrib-test-suite
Wauplin Nov 28, 2022
f20ab77
script to check contrib list is accurate
Wauplin Nov 28, 2022
d5949fa
Use [testing] requirements as contrib common dependencies
Wauplin Nov 28, 2022
6cb96e7
add check_contrib_list in github workflow
Wauplin Nov 28, 2022
b299077
code qualiry
Wauplin Nov 28, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/contrib-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Contrib tests

on: workflow_dispatch

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
Comment thread
Wauplin marked this conversation as resolved.
uses: actions/setup-python@v2
with:
python-version: 3.8

# Install huggingface_hub
- name: Install `huggingface_hub`
run: |
pip install --upgrade pip
pip install .

# Install downstream libraries
- name: Install downstream libraries
run: pip install -r contrib/requirements.txt
Comment thread
osanseviero marked this conversation as resolved.
Outdated

# Run tests
- name: Run tests
run: pytest contrib/ -n 4
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.PHONY: quality style test


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


quality:
Expand Down
26 changes: 26 additions & 0 deletions contrib/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Contrib test suite

The contrib folder contains simple end-to-end scripts to test integration of `huggingface_hub` in downstream libraries. The main goal is to proactively notice breaking changes and deprecation warnings.

## Run contrib tests on CI

Contrib tests can be [manually triggered in github](https://github.com/huggingface/huggingface_hub/actions) with the `Contrib tests` workflow.
Comment thread
Wauplin marked this conversation as resolved.
Outdated

Tests are not run in the default test suite (for each PR) as this would slow down development process. The goal is to notice breaking changes, not to avoid them. In particular, it is interesting to trigger it before a release to make sure it will not cause too much friction.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also run them once a week just to check

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cron job added by d5949fa. Will run every week on Saturday midnight.


## Run contrib tests locally

### Install dependencies

```sh
# Create a separate contrib environment
python3 -m venv .venv_contrib
source .venv_contrib/bin/activate

# Install requirements
pip install . # huggingface_hub
pip install -r contrib/requirements.txt

# Run tests !
pytest contrib -n 4
```
57 changes: 57 additions & 0 deletions contrib/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import time
import uuid
from typing import Generator

import pytest

from huggingface_hub import HfFolder, delete_repo


@pytest.fixture(scope="session")
def token() -> str:
# Not critical, only usable on the sandboxed CI instance.
return "hf_94wBhPGp6KrrTH3KDchhKpRxZwd6dmHWLL"


@pytest.fixture(scope="session")
def user() -> str:
return "__DUMMY_TRANSFORMERS_USER__"


@pytest.fixture(autouse=True, scope="session")
def login_as_dummy_user(token: str) -> Generator:
"""Login with dummy user token on machine

Once all tests are completed, set back previous token."""
# Remove registered token
old_token = HfFolder().get_token()
HfFolder().save_token(token)

yield # Run all tests

# Set back token once all tests have passed
if old_token is not None:
HfFolder().save_token(old_token)


@pytest.fixture
def repo_name(request) -> None:
"""
Return a readable pseudo-unique repository name for tests.

Example: "repo-2fe93f-16599646671840"
"""
prefix = request.module.__name__ # example: `test_timm`
id = uuid.uuid4().hex[:6]
ts = int(time.time() * 10e3)
return f"repo-{prefix}-{id}-{ts}"


@pytest.fixture
def cleanup_repo(user: str, repo_name: str) -> None:
"""Delete the repo at the end of the tests.

TODO: Adapt to handle `repo_type` as well
"""
yield # run test
delete_repo(repo_id=f"{user}/{repo_name}")
6 changes: 6 additions & 0 deletions contrib/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pytest
pytest-env
pytest-xdist

# Timm
git+https://github.com/rwightman/pytorch-image-models.git#egg=timm
Comment thread
osanseviero marked this conversation as resolved.
Comment thread
osanseviero marked this conversation as resolved.
10 changes: 10 additions & 0 deletions contrib/test_timm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def test_push_to_hub(repo_name: str, cleanup_repo: None) -> None:
Comment thread
osanseviero marked this conversation as resolved.
Outdated
import timm

# Build a model 🔧
model = timm.create_model("resnet18", pretrained=True, num_classes=4)

# Push it to the 🤗 hub
timm.models.hub.push_to_hf_hub(
model, repo_name, model_config=dict(labels=["a", "b", "c", "d"])
)