Fix evaluate-cli import error with huggingface-hub 1.0.0 - #2
Open
tonycoder-hub wants to merge 1 commit into
Open
Fix evaluate-cli import error with huggingface-hub 1.0.0#2tonycoder-hub wants to merge 1 commit into
evaluate-cli import error with huggingface-hub 1.0.0#2tonycoder-hub wants to merge 1 commit into
Conversation
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
marked this pull request as ready for review
August 17, 2026 09:05
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the remaining
huggingface_hub>=1.0.0incompatibility reported in huggingface#712.Background
The
HfFoldercrash from the original report was already fixed by huggingface#701 and shipped in0.4.6, butmainis still not importable end-to-end underhuggingface-hub>=1.0.0.huggingface_hubremoved the git-basedRepositoryclass in v1.0.0, andsrc/evaluate/commands/evaluate_cli.pyimports it at module scope:So the
evaluate-cliconsole script fails to start on any recenthuggingface_hub.Changes
src/evaluate/commands/evaluate_cli.py: drop theRepositoryimport and replacerepo.git_add()/git_commit()/git_push()with the same plain-git subprocess call that already clones the Space, factored out into a smallrun_githelper. This keeps the local checkout, the auth model, and the printed instructions exactly as they were, and works on bothhuggingface-hub0.x and 1.x.setup.py: raise thehuggingface-hubfloor from>=0.7.0to>=0.10.0, the first release that shipshuggingface_hub.utils.build_hf_headers(used inevaluate/utils/file_utils.py). No upper bound is needed now that the code works with 1.x.setup.py: addcookiecuttertoTESTS_REQUIREso the CLI module can be imported by the test suite (it is otherwise only in thetemplateextra, which CI does not install).tests/test_evaluate_cli.py: new regression test.Tests
The new test deletes
huggingface_hub.Repositorybefore importing the CLI, so it reproduces the 1.0.0 failure regardless of whichhuggingface_hubversion is installed, and it pins down the git command sequence used to push the generated template.tests/test_evaluate_cli.pyerrors withImportError: cannot import name 'Repository' from 'huggingface_hub'.49 passed, 2 skipped.black,isortandflake8are clean on the changed files (the pre-existingflake8warnings inmodule.py,file_utils.pyandlogging.pyare untouched).Out of scope
.github/hub/push_evaluations_to_hub.pyalso usesRepository, but that CI script is already covered by the open PR huggingface#732, so it is left alone here.