Skip to content
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

Merged
merged 29 commits into from
Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
1aa664a
deprecate clone_from behavior
merveenoyan Jul 21, 2022
5c78379
added warnings import
merveenoyan Jul 21, 2022
ccbd583
make style
merveenoyan Jul 21, 2022
1bec939
added test
merveenoyan Jul 21, 2022
792af11
added repo creation to test setups
merveenoyan Jul 21, 2022
da18a5a
modified test to skip repo creation during setup
merveenoyan Jul 21, 2022
17deae2
fixed remaining of the tests by adding create_repo
merveenoyan Jul 21, 2022
a82b09d
fixed tests
merveenoyan Jul 22, 2022
b871f3d
fixed tests
merveenoyan Jul 22, 2022
8fd2f74
shifted head and added changes on top
merveenoyan Aug 1, 2022
1953d2a
shifted head and added changes on top
merveenoyan Aug 1, 2022
c2c61a4
Revert "shifted head and added changes on top"
merveenoyan Aug 1, 2022
b179f67
Revert "fixed tests"
merveenoyan Aug 1, 2022
7eff5e3
Revert "fixed tests"
merveenoyan Aug 1, 2022
684d822
Revert "fixed remaining of the tests by adding create_repo"
merveenoyan Aug 1, 2022
d11e626
Revert "modified test to skip repo creation during setup"
merveenoyan Aug 1, 2022
275c757
Revert "added repo creation to test setups"
merveenoyan Aug 1, 2022
9c933ca
reverted changes
merveenoyan Aug 1, 2022
f1704e3
updated version
merveenoyan Aug 1, 2022
79fc043
Merge branch 'main' into clone_from_deprecation
Wauplin Aug 18, 2022
19e82fc
expect deprecation for clone_from in tests
Wauplin Aug 18, 2022
e642740
Merge pull request #1 from huggingface/clone_from_deprecation_add_exp…
merveenoyan Aug 29, 2022
a1898e6
Merge branch 'main' into clone_from_deprecation
merveenoyan Aug 29, 2022
f5351f7
make style
merveenoyan Aug 29, 2022
d05d083
Update tests/test_repository.py
Wauplin Aug 29, 2022
12b47cd
Update tests/test_repository.py
Wauplin Aug 29, 2022
0e82e9e
fixed tests
merveenoyan Aug 29, 2022
30196f4
fixed tests
merveenoyan Aug 29, 2022
801c560
make style
merveenoyan Aug 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/huggingface_hub/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import tempfile
import threading
import time
import warnings
from contextlib import contextmanager
from pathlib import Path
from typing import Callable, Dict, Iterator, List, Optional, Tuple, Union
Expand Down Expand Up @@ -667,6 +668,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 and will be removed in v0.11.",
FutureWarning,
)

self.client.create_repo(
repo_id=repo_id,
token=token,
Expand Down
8 changes: 7 additions & 1 deletion tests/test_repocard.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@
from huggingface_hub.utils import logging

from .testing_constants import ENDPOINT_STAGING, TOKEN, USER
from .testing_utils import repo_name, retry_endpoint, set_write_permission_and_retry
from .testing_utils import (
expect_deprecation,
repo_name,
retry_endpoint,
set_write_permission_and_retry,
)


ROUND_TRIP_MODELCARD_CASE = """
Expand Down Expand Up @@ -198,6 +203,7 @@ def setUpClass(cls):
cls._api.set_access_token(TOKEN)

@retry_endpoint
@expect_deprecation("clone_from")
def setUp(self) -> None:
self.repo_path = Path(tempfile.mkdtemp())
self.REPO_NAME = repo_name()
Expand Down
16 changes: 14 additions & 2 deletions tests/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

from .testing_constants import ENDPOINT_STAGING, TOKEN, USER
from .testing_utils import (
expect_deprecation,
repo_name,
retry_endpoint,
set_write_permission_and_retry,
Expand Down Expand Up @@ -137,6 +138,14 @@ def test_clone_from_space(self):
use_auth_token=self._token,
)

@expect_deprecation("clone_from")
def test_clone_from_deprecation_warning(self):
Repository(
WORKING_REPO_DIR,
clone_from=f"{USER}/{uuid.uuid4()}",
use_auth_token=self._token,
)

def test_clone_from_model(self):
temp_repo_url = self._api.create_repo(
repo_id=f"{self.REPO_NAME}-temp", token=self._token, repo_type="model"
Expand Down Expand Up @@ -403,6 +412,7 @@ def test_add_commit_push_non_blocking_process_killed(self):
self.assertEqual(result.status, -9)

@retry_endpoint
@expect_deprecation("clone_from")
def test_clone_with_endpoint(self):
clone = Repository(
f"{WORKING_REPO_DIR}/{self.REPO_NAME}",
Expand Down Expand Up @@ -433,6 +443,7 @@ def test_clone_with_endpoint(self):
self.assertTrue("model.bin" in files)

@retry_endpoint
@expect_deprecation("clone_from")
def test_clone_with_repo_name_and_org(self):
clone = Repository(
f"{WORKING_REPO_DIR}/{self.REPO_NAME}",
Expand Down Expand Up @@ -525,8 +536,8 @@ def test_clone_with_repo_name_user_and_no_auth_token(self):
)

@retry_endpoint
@expect_deprecation("clone_from")
def test_clone_with_repo_name_org_and_no_auth_token(self):
# Create repo
Repository(
f"{WORKING_REPO_DIR}/{self.REPO_NAME}",
use_auth_token=self._token,
Expand Down Expand Up @@ -1694,6 +1705,7 @@ def test_clone_with_endpoint(self):
self.assertTrue("test.py" in files)

@retry_endpoint
@expect_deprecation("clone_from")
def test_clone_with_repo_name_and_org(self):
clone = Repository(
f"{WORKING_DATASET_DIR}/{self.REPO_NAME}",
Expand Down Expand Up @@ -1788,8 +1800,8 @@ def test_clone_with_repo_name_user_and_no_auth_token(self):
)

@retry_endpoint
@expect_deprecation("clone_from")
def test_clone_with_repo_name_org_and_no_auth_token(self):
# Create repo
Repository(
f"{WORKING_DATASET_DIR}/{self.REPO_NAME}",
clone_from=f"valid_org/{self.REPO_NAME}",
Expand Down
1 change: 1 addition & 0 deletions tests/test_snapshot_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def setUpClass(cls):
cls._api.set_access_token(TOKEN)

@retry_endpoint
@expect_deprecation("clone_from")
def setUp(self) -> None:
if os.path.exists(REPO_NAME):
shutil.rmtree(REPO_NAME, onerror=set_write_permission_and_retry)
Expand Down