Skip to content

Fix evaluate-cli import error with huggingface-hub 1.0.0 - #2

Open
tonycoder-hub wants to merge 1 commit into
mainfrom
cursor/fix-huggingface-hub-1-0-compat-464e
Open

Fix evaluate-cli import error with huggingface-hub 1.0.0#2
tonycoder-hub wants to merge 1 commit into
mainfrom
cursor/fix-huggingface-hub-1-0-compat-464e

Conversation

@tonycoder-hub

Copy link
Copy Markdown
Owner

Fixes the remaining huggingface_hub>=1.0.0 incompatibility reported in huggingface#712.

Background

The HfFolder crash from the original report was already fixed by huggingface#701 and shipped in 0.4.6, but main is still not importable end-to-end under huggingface-hub>=1.0.0. huggingface_hub removed the git-based Repository class in v1.0.0, and src/evaluate/commands/evaluate_cli.py imports it at module scope:

>>> import evaluate.commands.evaluate_cli
ImportError: cannot import name 'Repository' from 'huggingface_hub'

So the evaluate-cli console script fails to start on any recent huggingface_hub.

Changes

  • src/evaluate/commands/evaluate_cli.py: drop the Repository import and replace repo.git_add() / git_commit() / git_push() with the same plain-git subprocess call that already clones the Space, factored out into a small run_git helper. This keeps the local checkout, the auth model, and the printed instructions exactly as they were, and works on both huggingface-hub 0.x and 1.x.
  • setup.py: raise the huggingface-hub floor from >=0.7.0 to >=0.10.0, the first release that ships huggingface_hub.utils.build_hf_headers (used in evaluate/utils/file_utils.py). No upper bound is needed now that the code works with 1.x.
  • setup.py: add cookiecutter to TESTS_REQUIRE so the CLI module can be imported by the test suite (it is otherwise only in the template extra, which CI does not install).
  • tests/test_evaluate_cli.py: new regression test.

Tests

The new test deletes huggingface_hub.Repository before importing the CLI, so it reproduces the 1.0.0 failure regardless of which huggingface_hub version is installed, and it pins down the git command sequence used to push the generated template.

python -m pytest tests/test_evaluate_cli.py tests/test_file_utils.py tests/test_hub.py tests/test_load.py tests/test_metric.py tests/test_save.py -q
  • Before the fix: tests/test_evaluate_cli.py errors with ImportError: cannot import name 'Repository' from 'huggingface_hub'.
  • After the fix: 49 passed, 2 skipped.

black, isort and flake8 are clean on the changed files (the pre-existing flake8 warnings in module.py, file_utils.py and logging.py are untouched).

Out of scope

.github/hub/push_evaluations_to_hub.py also uses Repository, but that CI script is already covered by the open PR huggingface#732, so it is left alone here.

Open in WebOpen in Cursor

huggingface_hub removed the git-based `Repository` class in v1.0.0, so
`from huggingface_hub import HfApi, Repository, create_repo` raises an
ImportError and the `evaluate-cli` entry point cannot start at all.

Replace the `Repository` add/commit/push calls with the same plain git
subprocess helper that is already used to clone the Space, which keeps the
local checkout and the printed instructions valid and works on both
huggingface-hub 0.x and 1.x.

Also raise the huggingface-hub floor to the version that first shipped
`huggingface_hub.utils.build_hf_headers`, and add cookiecutter to the test
extra so the CLI can be imported in CI.

Co-authored-by: Tony Coder <407243179@qq.com>
@tonycoder-hub
tonycoder-hub marked this pull request as ready for review August 17, 2026 09:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants