Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate test and prod cache (+ ruff formatter) #1789

Merged
merged 2 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion .github/workflows/python-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ jobs:
run: |
pip install --upgrade pip
pip install .[dev]
- run: ruff tests src contrib
- run: ruff check tests src contrib # linter
- run: ruff format --check tests src contrib # formatter
- run: python utils/check_contrib_list.py
- run: python utils/check_static_imports.py
- run: python utils/generate_async_inference_client.py
Expand Down
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ check_dirs := contrib src tests utils setup.py


quality:
ruff $(check_dirs)
ruff check $(check_dirs) # linter
ruff format --check $(check_dirs) # formatter
mypy src
python utils/check_contrib_list.py
python utils/check_static_imports.py
python utils/generate_async_inference_client.py

style:
ruff --fix $(check_dirs)
ruff check --fix $(check_dirs) # linter
ruff format $(check_dirs) # formatter
python utils/check_contrib_list.py --update
python utils/check_static_imports.py --update
python utils/generate_async_inference_client.py --update
Expand Down
6 changes: 6 additions & 0 deletions src/huggingface_hub/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ def _as_int(value: Optional[str]) -> Optional[int]:
HF_TOKEN_PATH = os.path.join(hf_cache_home, "token")


if _staging_mode:
# In staging mode, we use a different cache to ensure we don't mix up production and staging data or tokens
_staging_home = os.path.join(os.path.expanduser("~"), ".cache", "huggingface_staging")
HUGGINGFACE_HUB_CACHE = os.path.join(_staging_home, "hub")
HF_TOKEN_PATH = os.path.join(_staging_home, "token")

# Here, `True` will disable progress bars globally without possibility of enabling it
# programmatically. `False` will enable them without possibility of disabling them.
# If environment variable is not set (None), then the user is free to enable/disable
Expand Down
19 changes: 1 addition & 18 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from requests.exceptions import HTTPError

import huggingface_hub
from huggingface_hub import HfApi, HfFolder
from huggingface_hub import HfApi
from huggingface_hub.utils import SoftTemporaryDirectory, logging
from huggingface_hub.utils._typing import CallableT

Expand Down Expand Up @@ -44,23 +44,6 @@ def test_cache_dir(self) -> None:
shutil.rmtree(cache_dir, onerror=set_write_permission_and_retry)


@pytest.fixture(autouse=True, scope="session")
def clean_hf_folder_token_for_tests() -> Generator:
"""Clean token stored on machine before all tests and reset it back at the end.

Useful to avoid token deletion when running tests locally.
"""
# Remove registered token
token = HfFolder().get_token()
HfFolder().delete_token()

yield # Run all tests

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


@pytest.fixture(autouse=True)
def disable_symlinks_on_windows_ci(monkeypatch: pytest.MonkeyPatch) -> None:
class FakeSymlinkDict(dict):
Expand Down
Loading