From e4bd78f3696744137d0d6aee835fc419e2a64508 Mon Sep 17 00:00:00 2001 From: Lucain Pouget Date: Tue, 31 Oct 2023 11:21:56 +0100 Subject: [PATCH 1/2] Separate test and prod cache --- Makefile | 6 ++++-- src/huggingface_hub/constants.py | 6 ++++++ tests/conftest.py | 19 +------------------ 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/Makefile b/Makefile index a03259d778..4a8f63972a 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/src/huggingface_hub/constants.py b/src/huggingface_hub/constants.py index ee1cb98ce6..ea9334dc02 100644 --- a/src/huggingface_hub/constants.py +++ b/src/huggingface_hub/constants.py @@ -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 diff --git a/tests/conftest.py b/tests/conftest.py index 7f3a986387..8c8f09eaa5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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 @@ -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): From f03fb43dcc0c0783f01b96f0d7505daea79f0492 Mon Sep 17 00:00:00 2001 From: Lucain Pouget Date: Tue, 31 Oct 2023 11:25:35 +0100 Subject: [PATCH 2/2] fix quality in github action --- .github/workflows/python-quality.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/python-quality.yml b/.github/workflows/python-quality.yml index 24e3cc2113..037cebf74a 100644 --- a/.github/workflows/python-quality.yml +++ b/.github/workflows/python-quality.yml @@ -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