Skip to content

update require_read_token#38093

Merged
ydshieh merged 4 commits intomainfrom
fix_require_hub_read_token
May 13, 2025
Merged

update require_read_token#38093
ydshieh merged 4 commits intomainfrom
fix_require_hub_read_token

Conversation

@ydshieh
Copy link
Copy Markdown
Collaborator

@ydshieh ydshieh commented May 12, 2025

What does this PR do?

update require_read_token.

Currently, that decorator only works with function/method, but not for a class. The usage of it on classes will skip all the tests in those classes.

This PR fixes this issue.

@github-actions github-actions Bot marked this pull request as draft May 12, 2025 20:07
@github-actions
Copy link
Copy Markdown
Contributor

Hi 👋, thank you for opening this pull request! The pull request is converted to draft by default. The CI will be paused while the PR is in draft mode. When it is ready for review, please click the Ready for review button (at the bottom of the PR page). This will assign reviewers and trigger CI.

@ydshieh ydshieh marked this pull request as ready for review May 12, 2025 20:07
@HuggingFaceDocBuilderDev
Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Comment on lines +570 to +578
if isinstance(test_case, type):
for attr_name in dir(test_case):
attr = getattr(test_case, attr_name)
if isinstance(attr, types.FunctionType):
if getattr(attr, "__require_read_token__", False):
continue
wrapped = require_read_token(attr)
setattr(test_case, attr_name, wrapped)
return test_case
Copy link
Copy Markdown
Collaborator Author

@ydshieh ydshieh May 13, 2025

Choose a reason for hiding this comment

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

Here dealing with class cases.

It will decorate all of its methods and return itself (TestCase).

Comment on lines +580 to +594
if getattr(test_case, "__require_read_token__", False):
return test_case

return _inner
@functools.wraps(test_case)
def wrapper(*args, **kwargs):
if token is not None:
with patch("huggingface_hub.utils._headers.get_token", return_value=token):
if "test_config" in str(test_case):
breakpoint()
return test_case(*args, **kwargs)
else: # Allow running locally with the default token env variable
return test_case(*args, **kwargs)

wrapper.__require_read_token__ = True
return wrapper
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.

Here for test method/function case

@ydshieh ydshieh marked this pull request as draft May 13, 2025 08:28
@ydshieh ydshieh marked this pull request as ready for review May 13, 2025 09:09
@ydshieh ydshieh changed the title [don't merge yet] update require_read_token update require_read_token May 13, 2025
Copy link
Copy Markdown
Member

@ivarflakstad ivarflakstad left a comment

Choose a reason for hiding this comment

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

LGTM! 👍

@ydshieh ydshieh merged commit 3ad35d0 into main May 13, 2025
21 checks passed
@ydshieh ydshieh deleted the fix_require_hub_read_token branch May 13, 2025 10:07
zucchini-nlp pushed a commit to zucchini-nlp/transformers that referenced this pull request May 14, 2025
* update require_read_token

* new repo

* fix

* fix

---------

Co-authored-by: ydshieh <ydshieh@users.noreply.github.com>
@ydshieh ydshieh mentioned this pull request Jun 9, 2025
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.

3 participants