-
Notifications
You must be signed in to change notification settings - Fork 552
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
Feature: switch visibility with update_repo_settings #2537 #2541
Feature: switch visibility with update_repo_settings #2537 #2541
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @WizKnight! thank you for working on this 🤗 I left some comments and I think they are still other references of update_repo_visibility
in other files and docs to update
Hey @hanouticelina :), changes were added in the recent commit. |
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @WizKnight! thanks a lot for this iteration! 😄 I left a small comment and there is also this one that needs to be addressed.
I just realized that update_repo_visibility()
is used in other tests in tests/test_file_download.py
and tests/test_snapshot_download.py
. Could you replace update_repo_visibility()
with update_repo_settings()
in those files as well?
The failing test seems unrelated, I'll take a look
For deprecated methods, we have a So in the case of the deprecate use of it here, you can do @expect_deprecation("update_repo_visibility")
def test_download_private_model(self):
self.api.update_repo_visibility(repo_id=self.repo_id, private=True) (+ adapt the import) (sorry it's the kind of undocumentated things...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @WizKnight! Here are a few changes I'd make in addition to @hanouticelina's comment above :)
src/huggingface_hub/hf_api.py
Outdated
@@ -3625,10 +3633,13 @@ def update_repo_settings( | |||
# Build headers | |||
headers = self._build_hf_headers(token=token) | |||
|
|||
# Preparing the JSON payload for the PUT request | |||
payload = {"gated": gated, "private": private} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prepare the payload in 2 steps:
payload: Dict = {}
if gated is not None:
if gated not in ["auto", "manual", False]:
raise ValueError(f"Invalid gated status, must be one of 'auto', 'manual', or False. Got '{gated}'.")
payload["gated"] = gated
if private is not None:
payload["private"] = private
The advantage of doing so is that adding a new parameter will just be a matter of adding a new if
statement. Also, it makes it easier to log/print the payload value in case of debugging an issue. Doing a {key: value for key, value in payload.items() if value is not None}
is not wrong per-se but makes it slightly less readable and less debuggable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was planning on a similar approach, but I opted for the dictionary comprehension {key: value for key, value in payload.items() if value is not None}
to make the code more efficient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sometimes readibility / maintenance is more important than efficiency :)
docs/source/en/guides/repository.md
Outdated
|
||
```py | ||
>>> from huggingface_hub import HfApi | ||
|
||
>>> api = HfApi() | ||
>>> api.update_repo_settings(repo_id=repo_id, gated="auto") # Set automatic gating for a model | ||
>>> api.update_repo_settings(repo_id=repo_id, gated="auto", private=True) # Set automatic gating and visibility for a model |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would structure the documentation as such:
## Change repository settings
(...) current content
### Update visibility
(...) current content + update example
### Setup gated access
(...) current content
Setting a repo as gating and setting repo visibility is 2 different topics, even if related to accessibility. Usually either a repo is public, either private, either public and gated. Setting a repo as private and gated is possible but doesn't make sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @WizKnight ! thanks again for this 😄 I left two minor comments.
The tests failure comes from the test test_repo_id_no_warning()
which is flagged with the expect_deprecation
decorator and contains also a context manager warnings.catch_warnings
and they both try to capture the same warning.
The FutureWarning
is "consumed" by pytest.warns
in the expect_deprecation
decorator, so it never reaches the warnings.catch_warnings
context manager inside the test. This is why the record
list does not contain the FutureWarning
and the test fails.
@Wauplin do we still need this test ? it tests that there is no warnings when passing repo_id
as positional argument into some HfApi functions (create_repo
, delete_repo
, and update_repo_visibility
).
src/huggingface_hub/hf_api.py
Outdated
@@ -3596,14 +3602,16 @@ def update_repo_settings( | |||
The gated release status for the repository. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The gated release status for the repository. | |
The gated status for the repository. If set to `None` (default), the `gated` setting of the repository won't be updated |
src/huggingface_hub/hf_api.py
Outdated
@@ -3596,14 +3602,16 @@ def update_repo_settings( | |||
The gated release status for the repository. | |||
* "auto": The repository is gated, and access requests are automatically approved or denied based on predefined criteria. | |||
* "manual": The repository is gated, and access requests require manual approval. | |||
* False (default): The repository is not gated, and anyone can access it. | |||
* False : The gated status for the repository. If set to `None` (default), the `gated` setting of the repository won't be updated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* False : The gated status for the repository. If set to `None` (default), the `gated` setting of the repository won't be updated. | |
* False : The repository is not gated, and anyone can access it. |
Clearly not needed anymore indeed! Let's just delete it instead of trying to fix the warning capture thingy (we could extend |
Hey @Wauplin and @hanouticelina, so do I remove these HfApi functions ( |
No no, the only thing to do is to remove the test |
Hey @Wauplin I removed the test |
(I've switched the PR as "ready for review". In general @WizKnight you can switch a PR to "ready" as soon as you request someone to review it) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @WizKnight 👋 thanks a lot for this PR! looks good to me 🙂 failing tests are unrelated, let's wait for @Wauplin's final review and we will be good to merge
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good! Thanks for the back and forth @WizKnight @hanouticelina 🤗
Failing test is indeed unrelated. I left minor comments otherwise we are good to merge :)
CI's green, let's merge 🎉 Thanks again @WizKnight 🤗 |
Hey @Wauplin & @hanouticelina , I really appreciate the opportunity!! Thankyou once again🤗 |
This PR enhances the
update_repo_settings
method to provide more control over repository settings, and deprecates theupdate_repo_visibility
method:Key changes:
gated
orprivate
is provided.gated
andprivate
are only included in the request payload if they have non-None values.update_repo_settings
and replaced all references toupdate_repo_visibility
in the documentation.@_deprecate_method
decorator toupdate_repo_visibility
, marking it for removal in v0.29.x.