-
Notifications
You must be signed in to change notification settings - Fork 570
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
ENH Deprecate clone_from behavior #952
ENH Deprecate clone_from behavior #952
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.
Very nice! Thanks for this. Could you also add a small test that checks that a warning is raised please?
Here is an example:
huggingface_hub/tests/test_keras_integration.py
Lines 323 to 326 in 1d3637c
with pytest.warns( | |
FutureWarning, | |
match="`task_name` input argument is deprecated. Pass `tags` instead.", | |
): |
The documentation is not available anymore as the PR was closed or merged. |
plot twist: this behavior was used mainly for tests? ✨ so many tests depend on later edit: some |
I added creation of repositories to setups and managed to reduce failing tests to 3, will look for those on why they fail. |
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.
Looks good to me! We should be proactive about reaching out to repositories that have the Repository
set to create the repository when it doesn't exist. I think transformers
does that under the hood, I'll see to change that there. Do we know any other libraries that leverage Repository
to create their repositories on the hub?
maybe @osanseviero knows @LysandreJik 🙂 |
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 a lot for this PR! I think we can merge after two things:
- I think we should revert the changes in the tests as I would not expect changes in existing tests since we're only adding a warning. That way we're sure nothing changes :)
- Once the above is reverted, let's get to green and merge 🔥
src/huggingface_hub/repository.py
Outdated
@@ -655,6 +656,12 @@ def clone_from(self, repo_url: str, use_auth_token: Union[bool, str, None] = Non | |||
" on Hugging Face Hub." | |||
) | |||
else: | |||
warnings.warn( | |||
"Creating a repository through clone_from is deprecated" | |||
"will be removed in v0.10.", |
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.
Maybe let's change this to v0.11., as 0.9 is already the next release, that way we have 2 releases before deprecating
tests/test_repocard.py
Outdated
@@ -204,9 +204,12 @@ def setUpClass(cls): | |||
def setUp(self) -> None: | |||
self.repo_path = Path(tempfile.mkdtemp()) | |||
self.REPO_NAME = repo_name() | |||
url = self._api.create_repo( |
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.
When adding some changes, if you have to change tests, that's a red flag to watch out! As you're just adding a warning, nothing should change in any existing tests. It's ok if current tests depend on clone_from
, I would revert the changes to keep them as they were as we're not changing any behaviour now. We should change the text when actually deprecating this. WDYT?
tests/test_repository.py
Outdated
@@ -140,6 +143,19 @@ def test_clone_from_space(self): | |||
use_auth_token=self._token, | |||
) | |||
|
|||
def test_clone_from_deprecation_warning(self): | |||
"""SKIP CREATION""" |
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 remove this docstring as the name of the test is already great 🔥
tests/test_repository.py
Outdated
WORKING_REPO_DIR, | ||
clone_from=f"{USER}/{uuid.uuid4()}", | ||
use_auth_token=self._token, | ||
repo_type="dataset", |
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.
Nit: feel free to remove repo_type
. The simpler the test the easier to understand, so anything not strictly needed I would remove
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 did it because there was two of those tests, one was for model repository and one was for dataset 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.
I think that given the behaviour you're changing is ok to just cover one case
@LysandreJik @merveenoyan quick recap of 3rd party libraries with 🟡 Adapter Transformers (note they pin to be below 0.8) cc @calpt, pointer is at https://github.com/adapter-hub/adapter-transformers/blob/master/src/transformers/utils/hub.py#L1014. So this won't break as they pin the version, but we should update this nevertheless to either create the repo before or use the non-git-based methods |
Hey @merveenoyan, we will likely do a release next week. There were some very minor changes to be done in the PR before merging, would be great if we could merge the PR some time early *next week. |
@osanseviero I created a new branch from 1bec939 I'm testing atm. Once it's done I'll merge to this branch and ask you to review. |
@merveenoyan I'm finally getting back to you ! PR has been merged and you can now use this decorator to deprecate arguments and this one to test it. Hope it will be easy from now on and sorry for the delay ! 😬 |
@Wauplin I feel like it's best if I just close this PR and start from scratch instead of rewinding and rebasing things 😅 |
Yes indeed, sorry for the mess |
@Wauplin in this case, so for this one, is it the best if I manually edit tests? or would decorating tests only work? |
@merveenoyan Indeed we don't have a decorator for deprecating a specific usage of a valid argument (I don't even know how we could do such a decorator 😁 ). However you can still use the decorator in the tests. Cherry-picking this commit should solve your problem merveenoyan@19e82fc. |
…ected_deprecation_in_tests Clone from deprecation add expected deprecation in tests
@Wauplin as said by Simon, def _inner_decorator(test_function: Callable) -> Callable:
@wraps(test_function)
def _inner_test_function(*args, **kwargs):
with pytest.warns(FutureWarning, match=f".*'{function_name}'.*"):
return test_function(*args, **kwargs)
return _inner_test_function I will have to edit the tests myself or we can change the |
In theory I think if there is still an issue it less in a typo or something 😕 I'm having a quick look at it. |
Seems like:
I can't really make the changes directly because it's on a fork 😕 |
Codecov Report
@@ Coverage Diff @@
## main #952 +/- ##
===========================================
+ Coverage 60.27% 81.44% +21.17%
===========================================
Files 31 31
Lines 3421 3423 +2
===========================================
+ Hits 2062 2788 +726
+ Misses 1359 635 -724
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
🥳 |
Solves #905.