From 1aa664a3f1eb3cd804af625001026f6913c3f65c Mon Sep 17 00:00:00 2001 From: merveenoyan Date: Thu, 21 Jul 2022 18:35:07 +0200 Subject: [PATCH 01/24] deprecate clone_from behavior --- src/huggingface_hub/repository.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/huggingface_hub/repository.py b/src/huggingface_hub/repository.py index df597278dd..fb068c26a1 100644 --- a/src/huggingface_hub/repository.py +++ b/src/huggingface_hub/repository.py @@ -655,6 +655,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.", + FutureWarning, + ) + self.client.create_repo( repo_id=repo_id, token=token, From 5c78379537f4f8e8989493c0ab0b42d65fcfccf9 Mon Sep 17 00:00:00 2001 From: merveenoyan Date: Thu, 21 Jul 2022 18:38:13 +0200 Subject: [PATCH 02/24] added warnings import --- src/huggingface_hub/repository.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/huggingface_hub/repository.py b/src/huggingface_hub/repository.py index fb068c26a1..217cf49029 100644 --- a/src/huggingface_hub/repository.py +++ b/src/huggingface_hub/repository.py @@ -9,7 +9,7 @@ from pathlib import Path from typing import Callable, Dict, Iterator, List, Optional, Tuple, Union from urllib.parse import urlparse - +import warnings from tqdm.auto import tqdm from huggingface_hub.constants import REPO_TYPES_URL_PREFIXES, REPOCARD_NAME From ccbd5838c6474efcfa9fea170826fd6a8f8702b0 Mon Sep 17 00:00:00 2001 From: merveenoyan Date: Thu, 21 Jul 2022 18:39:29 +0200 Subject: [PATCH 03/24] make style --- src/huggingface_hub/repository.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/huggingface_hub/repository.py b/src/huggingface_hub/repository.py index 217cf49029..c8c3c09bb8 100644 --- a/src/huggingface_hub/repository.py +++ b/src/huggingface_hub/repository.py @@ -5,11 +5,12 @@ 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 from urllib.parse import urlparse -import warnings + from tqdm.auto import tqdm from huggingface_hub.constants import REPO_TYPES_URL_PREFIXES, REPOCARD_NAME From 1bec93958ec0311141abbe503dabc86c2b5d4e86 Mon Sep 17 00:00:00 2001 From: merveenoyan Date: Thu, 21 Jul 2022 18:57:23 +0200 Subject: [PATCH 04/24] added test --- tests/test_repository.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test_repository.py b/tests/test_repository.py index 511d27212c..ea542e7b3a 100644 --- a/tests/test_repository.py +++ b/tests/test_repository.py @@ -140,6 +140,17 @@ def test_clone_from_space(self): use_auth_token=self._token, ) + def test_clone_from_deprecation_warning(self): + with pytest.raises( + FutureWarning, + match="Creating a repository through clone_from is deprecated*", + ): + 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" From 792af116137daceaff9638976dce4ba7c8b2512b Mon Sep 17 00:00:00 2001 From: merveenoyan Date: Thu, 21 Jul 2022 19:31:15 +0200 Subject: [PATCH 05/24] added repo creation to test setups --- tests/test_repocard.py | 5 ++++- tests/test_snapshot_download.py | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/test_repocard.py b/tests/test_repocard.py index 075d309eed..49405ca22f 100644 --- a/tests/test_repocard.py +++ b/tests/test_repocard.py @@ -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( + repo_id=f"{USER}/{self.REPO_NAME}", token=self._token + ) self.repo = Repository( self.repo_path / self.REPO_NAME, - clone_from=f"{USER}/{self.REPO_NAME}", + clone_from=url, use_auth_token=self._token, git_user="ci", git_email="ci@dummy.com", diff --git a/tests/test_snapshot_download.py b/tests/test_snapshot_download.py index 89714ad3c9..06c15ad000 100644 --- a/tests/test_snapshot_download.py +++ b/tests/test_snapshot_download.py @@ -36,9 +36,10 @@ def setUp(self) -> None: if os.path.exists(REPO_NAME): shutil.rmtree(REPO_NAME, onerror=set_write_permission_and_retry) logger.info(f"Does {REPO_NAME} exist: {os.path.exists(REPO_NAME)}") + url = self._api.create_repo(repo_id=f"{USER}/{REPO_NAME}", token=self._token) repo = Repository( REPO_NAME, - clone_from=f"{USER}/{REPO_NAME}", + clone_from=url, use_auth_token=self._token, git_user="ci", git_email="ci@dummy.com", From da18a5a031acac9a9b80ef15664e05767d655cea Mon Sep 17 00:00:00 2001 From: merveenoyan Date: Thu, 21 Jul 2022 20:10:15 +0200 Subject: [PATCH 06/24] modified test to skip repo creation during setup --- tests/test_repository.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/tests/test_repository.py b/tests/test_repository.py index ea542e7b3a..8b19289982 100644 --- a/tests/test_repository.py +++ b/tests/test_repository.py @@ -81,16 +81,19 @@ def setUp(self): logger.info( f"Does {WORKING_REPO_DIR} exist: {os.path.exists(WORKING_REPO_DIR)}" ) + self.REPO_NAME = repo_name() - self._repo_url = self._api.create_repo( - repo_id=self.REPO_NAME, token=self._token - ) - self._api.upload_file( - path_or_fileobj=BytesIO(b"some initial binary data: \x00\x01"), - path_in_repo="random_file.txt", - repo_id=f"{USER}/{self.REPO_NAME}", - token=self._token, - ) + # skip creation of repository for clone from test + if self.shortDescription() != "SKIP CREATION": + self._repo_url = self._api.create_repo( + repo_id=self.REPO_NAME, token=self._token + ) + self._api.upload_file( + path_or_fileobj=BytesIO(b"some initial binary data: \x00\x01"), + path_in_repo="random_file.txt", + repo_id=f"{USER}/{self.REPO_NAME}", + token=self._token, + ) def tearDown(self): try: @@ -141,6 +144,7 @@ def test_clone_from_space(self): ) def test_clone_from_deprecation_warning(self): + """SKIP CREATION""" with pytest.raises( FutureWarning, match="Creating a repository through clone_from is deprecated*", @@ -149,6 +153,7 @@ def test_clone_from_deprecation_warning(self): WORKING_REPO_DIR, clone_from=f"{USER}/{uuid.uuid4()}", use_auth_token=self._token, + repo_type="dataset", ) def test_clone_from_model(self): From 17deae20602d2966bbcbd9b1cd9e7a42736964cf Mon Sep 17 00:00:00 2001 From: merveenoyan Date: Thu, 21 Jul 2022 20:27:44 +0200 Subject: [PATCH 07/24] fixed remaining of the tests by adding create_repo --- tests/test_repository.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test_repository.py b/tests/test_repository.py index 8b19289982..9bbf129c13 100644 --- a/tests/test_repository.py +++ b/tests/test_repository.py @@ -453,6 +453,11 @@ def test_clone_with_endpoint(self): @retry_endpoint def test_clone_with_repo_name_and_org(self): + self._api.create_repo( + token=self._token, + repo_id=f"valid_org/{self.REPO_NAME}", + repo_type="dataset", + ) clone = Repository( f"{WORKING_REPO_DIR}/{self.REPO_NAME}", clone_from=f"valid_org/{self.REPO_NAME}", @@ -1714,6 +1719,11 @@ def test_clone_with_endpoint(self): @retry_endpoint def test_clone_with_repo_name_and_org(self): + self._api.create_repo( + token=self._token, + repo_id=f"valid_org/{self.REPO_NAME}", + repo_type="dataset", + ) clone = Repository( f"{WORKING_DATASET_DIR}/{self.REPO_NAME}", clone_from=f"valid_org/{self.REPO_NAME}", From a82b09d996acf7fafa3b1ccaafbba3f7b26ffffa Mon Sep 17 00:00:00 2001 From: merveenoyan Date: Fri, 22 Jul 2022 17:14:16 +0200 Subject: [PATCH 08/24] fixed tests --- tests/test_repository.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/tests/test_repository.py b/tests/test_repository.py index 9bbf129c13..bad0d85c9f 100644 --- a/tests/test_repository.py +++ b/tests/test_repository.py @@ -423,9 +423,14 @@ def test_add_commit_push_non_blocking_process_killed(self): @retry_endpoint def test_clone_with_endpoint(self): + repo_url = self._api.create_repo( + repo_id=f"{ENDPOINT_STAGING}/valid_org/{self.REPO_NAME}", + token=self._token, + repo_type="dataset", + ) clone = Repository( f"{WORKING_REPO_DIR}/{self.REPO_NAME}", - clone_from=f"{ENDPOINT_STAGING}/valid_org/{self.REPO_NAME}", + clone_from=repo_url, use_auth_token=self._token, git_user="ci", git_email="ci@dummy.com", @@ -453,14 +458,14 @@ def test_clone_with_endpoint(self): @retry_endpoint def test_clone_with_repo_name_and_org(self): - self._api.create_repo( + repo_url = self._api.create_repo( token=self._token, repo_id=f"valid_org/{self.REPO_NAME}", repo_type="dataset", ) clone = Repository( f"{WORKING_REPO_DIR}/{self.REPO_NAME}", - clone_from=f"valid_org/{self.REPO_NAME}", + clone_from=repo_url, use_auth_token=self._token, git_user="ci", git_email="ci@dummy.com", @@ -520,11 +525,14 @@ def test_clone_with_repo_name_and_user_namespace(self): @retry_endpoint def test_clone_with_repo_name_and_no_namespace(self): + repo_url = self._api.create_repo( + repo_id=self.REPO_NAME, token=self._token, repo_type="dataset" + ) self.assertRaises( OSError, Repository, f"{WORKING_REPO_DIR}/{self.REPO_NAME}", - clone_from=self.REPO_NAME, + clone_from=repo_url, use_auth_token=self._token, git_user="ci", git_email="ci@dummy.com", @@ -1784,11 +1792,14 @@ def test_clone_with_repo_name_and_user_namespace(self): @retry_endpoint def test_clone_with_repo_name_and_no_namespace(self): + repo_url = self._api.create_repo( + repo_id=self.REPO_NAME, token=self._token, repo_type="dataset" + ) self.assertRaises( OSError, Repository, f"{WORKING_DATASET_DIR}/{self.REPO_NAME}", - clone_from=self.REPO_NAME, + clone_from=repo_url, repo_type="dataset", use_auth_token=self._token, git_user="ci", From b871f3d9092fa478bc0b487789ccb7fc048f721e Mon Sep 17 00:00:00 2001 From: merveenoyan Date: Sat, 23 Jul 2022 00:28:20 +0200 Subject: [PATCH 09/24] fixed tests --- tests/test_repository.py | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/tests/test_repository.py b/tests/test_repository.py index bad0d85c9f..3816f17e44 100644 --- a/tests/test_repository.py +++ b/tests/test_repository.py @@ -423,14 +423,9 @@ def test_add_commit_push_non_blocking_process_killed(self): @retry_endpoint def test_clone_with_endpoint(self): - repo_url = self._api.create_repo( - repo_id=f"{ENDPOINT_STAGING}/valid_org/{self.REPO_NAME}", - token=self._token, - repo_type="dataset", - ) clone = Repository( f"{WORKING_REPO_DIR}/{self.REPO_NAME}", - clone_from=repo_url, + clone_from=f"{ENDPOINT_STAGING}/valid_org/{self.REPO_NAME}", use_auth_token=self._token, git_user="ci", git_email="ci@dummy.com", @@ -463,6 +458,7 @@ def test_clone_with_repo_name_and_org(self): repo_id=f"valid_org/{self.REPO_NAME}", repo_type="dataset", ) + clone = Repository( f"{WORKING_REPO_DIR}/{self.REPO_NAME}", clone_from=repo_url, @@ -481,7 +477,7 @@ def test_clone_with_repo_name_and_org(self): Repository( f"{WORKING_REPO_DIR}/{self.REPO_NAME}", - clone_from=f"valid_org/{self.REPO_NAME}", + clone_from=repo_url, use_auth_token=self._token, git_user="ci", git_email="ci@dummy.com", @@ -525,14 +521,11 @@ def test_clone_with_repo_name_and_user_namespace(self): @retry_endpoint def test_clone_with_repo_name_and_no_namespace(self): - repo_url = self._api.create_repo( - repo_id=self.REPO_NAME, token=self._token, repo_type="dataset" - ) self.assertRaises( OSError, Repository, f"{WORKING_REPO_DIR}/{self.REPO_NAME}", - clone_from=repo_url, + clone_from=self.REPO_NAME, use_auth_token=self._token, git_user="ci", git_email="ci@dummy.com", @@ -1792,14 +1785,11 @@ def test_clone_with_repo_name_and_user_namespace(self): @retry_endpoint def test_clone_with_repo_name_and_no_namespace(self): - repo_url = self._api.create_repo( - repo_id=self.REPO_NAME, token=self._token, repo_type="dataset" - ) self.assertRaises( OSError, Repository, - f"{WORKING_DATASET_DIR}/{self.REPO_NAME}", - clone_from=repo_url, + f"{WORKING_REPO_DIR}/{self.REPO_NAME}", + clone_from=self.REPO_NAME, repo_type="dataset", use_auth_token=self._token, git_user="ci", From 8fd2f74d25ab2f8e1bdc50ce26d79968355033b7 Mon Sep 17 00:00:00 2001 From: merveenoyan Date: Mon, 1 Aug 2022 16:29:03 +0200 Subject: [PATCH 10/24] shifted head and added changes on top --- tests/test_repository.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_repository.py b/tests/test_repository.py index ea542e7b3a..d1583bfcd6 100644 --- a/tests/test_repository.py +++ b/tests/test_repository.py @@ -141,7 +141,7 @@ def test_clone_from_space(self): ) def test_clone_from_deprecation_warning(self): - with pytest.raises( + with pytest.warns( FutureWarning, match="Creating a repository through clone_from is deprecated*", ): From c2c61a46c598d55a243cef3c5edac3f41d56fd16 Mon Sep 17 00:00:00 2001 From: merveenoyan Date: Mon, 1 Aug 2022 16:34:04 +0200 Subject: [PATCH 11/24] Revert "shifted head and added changes on top" This reverts commit 8fd2f74d25ab2f8e1bdc50ce26d79968355033b7. --- tests/test_repository.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_repository.py b/tests/test_repository.py index 484a8203d4..ba15106dbd 100644 --- a/tests/test_repository.py +++ b/tests/test_repository.py @@ -144,7 +144,7 @@ def test_clone_from_space(self): ) def test_clone_from_deprecation_warning(self): - with pytest.warns( + with pytest.raises( FutureWarning, match="Creating a repository through clone_from is deprecated*", ): From b179f674e85b30ebd0099c91106ff069cae98890 Mon Sep 17 00:00:00 2001 From: merveenoyan Date: Mon, 1 Aug 2022 16:35:06 +0200 Subject: [PATCH 12/24] Revert "fixed tests" This reverts commit b871f3d9092fa478bc0b487789ccb7fc048f721e. --- tests/test_repository.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/tests/test_repository.py b/tests/test_repository.py index ba15106dbd..3e8e3d65b2 100644 --- a/tests/test_repository.py +++ b/tests/test_repository.py @@ -422,9 +422,14 @@ def test_add_commit_push_non_blocking_process_killed(self): @retry_endpoint def test_clone_with_endpoint(self): + repo_url = self._api.create_repo( + repo_id=f"{ENDPOINT_STAGING}/valid_org/{self.REPO_NAME}", + token=self._token, + repo_type="dataset", + ) clone = Repository( f"{WORKING_REPO_DIR}/{self.REPO_NAME}", - clone_from=f"{ENDPOINT_STAGING}/valid_org/{self.REPO_NAME}", + clone_from=repo_url, use_auth_token=self._token, git_user="ci", git_email="ci@dummy.com", @@ -457,7 +462,6 @@ def test_clone_with_repo_name_and_org(self): repo_id=f"valid_org/{self.REPO_NAME}", repo_type="dataset", ) - clone = Repository( f"{WORKING_REPO_DIR}/{self.REPO_NAME}", clone_from=repo_url, @@ -476,7 +480,7 @@ def test_clone_with_repo_name_and_org(self): Repository( f"{WORKING_REPO_DIR}/{self.REPO_NAME}", - clone_from=repo_url, + clone_from=f"valid_org/{self.REPO_NAME}", use_auth_token=self._token, git_user="ci", git_email="ci@dummy.com", @@ -520,11 +524,14 @@ def test_clone_with_repo_name_and_user_namespace(self): @retry_endpoint def test_clone_with_repo_name_and_no_namespace(self): + repo_url = self._api.create_repo( + repo_id=self.REPO_NAME, token=self._token, repo_type="dataset" + ) self.assertRaises( OSError, Repository, f"{WORKING_REPO_DIR}/{self.REPO_NAME}", - clone_from=self.REPO_NAME, + clone_from=repo_url, use_auth_token=self._token, git_user="ci", git_email="ci@dummy.com", @@ -1784,11 +1791,14 @@ def test_clone_with_repo_name_and_user_namespace(self): @retry_endpoint def test_clone_with_repo_name_and_no_namespace(self): + repo_url = self._api.create_repo( + repo_id=self.REPO_NAME, token=self._token, repo_type="dataset" + ) self.assertRaises( OSError, Repository, - f"{WORKING_REPO_DIR}/{self.REPO_NAME}", - clone_from=self.REPO_NAME, + f"{WORKING_DATASET_DIR}/{self.REPO_NAME}", + clone_from=repo_url, repo_type="dataset", use_auth_token=self._token, git_user="ci", From 7eff5e3e5a507e98b8f2c7a5dfca9d079177d8b5 Mon Sep 17 00:00:00 2001 From: merveenoyan Date: Mon, 1 Aug 2022 16:35:13 +0200 Subject: [PATCH 13/24] Revert "fixed tests" This reverts commit a82b09d996acf7fafa3b1ccaafbba3f7b26ffffa. --- tests/test_repository.py | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/tests/test_repository.py b/tests/test_repository.py index 3e8e3d65b2..010ceaf4f3 100644 --- a/tests/test_repository.py +++ b/tests/test_repository.py @@ -422,14 +422,9 @@ def test_add_commit_push_non_blocking_process_killed(self): @retry_endpoint def test_clone_with_endpoint(self): - repo_url = self._api.create_repo( - repo_id=f"{ENDPOINT_STAGING}/valid_org/{self.REPO_NAME}", - token=self._token, - repo_type="dataset", - ) clone = Repository( f"{WORKING_REPO_DIR}/{self.REPO_NAME}", - clone_from=repo_url, + clone_from=f"{ENDPOINT_STAGING}/valid_org/{self.REPO_NAME}", use_auth_token=self._token, git_user="ci", git_email="ci@dummy.com", @@ -457,14 +452,14 @@ def test_clone_with_endpoint(self): @retry_endpoint def test_clone_with_repo_name_and_org(self): - repo_url = self._api.create_repo( + self._api.create_repo( token=self._token, repo_id=f"valid_org/{self.REPO_NAME}", repo_type="dataset", ) clone = Repository( f"{WORKING_REPO_DIR}/{self.REPO_NAME}", - clone_from=repo_url, + clone_from=f"valid_org/{self.REPO_NAME}", use_auth_token=self._token, git_user="ci", git_email="ci@dummy.com", @@ -524,14 +519,11 @@ def test_clone_with_repo_name_and_user_namespace(self): @retry_endpoint def test_clone_with_repo_name_and_no_namespace(self): - repo_url = self._api.create_repo( - repo_id=self.REPO_NAME, token=self._token, repo_type="dataset" - ) self.assertRaises( OSError, Repository, f"{WORKING_REPO_DIR}/{self.REPO_NAME}", - clone_from=repo_url, + clone_from=self.REPO_NAME, use_auth_token=self._token, git_user="ci", git_email="ci@dummy.com", @@ -1791,14 +1783,11 @@ def test_clone_with_repo_name_and_user_namespace(self): @retry_endpoint def test_clone_with_repo_name_and_no_namespace(self): - repo_url = self._api.create_repo( - repo_id=self.REPO_NAME, token=self._token, repo_type="dataset" - ) self.assertRaises( OSError, Repository, f"{WORKING_DATASET_DIR}/{self.REPO_NAME}", - clone_from=repo_url, + clone_from=self.REPO_NAME, repo_type="dataset", use_auth_token=self._token, git_user="ci", From 684d82235d840bddb3d9fa0021d44ebadd38ee53 Mon Sep 17 00:00:00 2001 From: merveenoyan Date: Mon, 1 Aug 2022 16:35:14 +0200 Subject: [PATCH 14/24] Revert "fixed remaining of the tests by adding create_repo" This reverts commit 17deae20602d2966bbcbd9b1cd9e7a42736964cf. --- tests/test_repository.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/tests/test_repository.py b/tests/test_repository.py index 010ceaf4f3..99d4d340a5 100644 --- a/tests/test_repository.py +++ b/tests/test_repository.py @@ -452,11 +452,6 @@ def test_clone_with_endpoint(self): @retry_endpoint def test_clone_with_repo_name_and_org(self): - self._api.create_repo( - token=self._token, - repo_id=f"valid_org/{self.REPO_NAME}", - repo_type="dataset", - ) clone = Repository( f"{WORKING_REPO_DIR}/{self.REPO_NAME}", clone_from=f"valid_org/{self.REPO_NAME}", @@ -1718,11 +1713,6 @@ def test_clone_with_endpoint(self): @retry_endpoint def test_clone_with_repo_name_and_org(self): - self._api.create_repo( - token=self._token, - repo_id=f"valid_org/{self.REPO_NAME}", - repo_type="dataset", - ) clone = Repository( f"{WORKING_DATASET_DIR}/{self.REPO_NAME}", clone_from=f"valid_org/{self.REPO_NAME}", From d11e62673c943bb1d76df67bca63520cce8f9362 Mon Sep 17 00:00:00 2001 From: merveenoyan Date: Mon, 1 Aug 2022 16:35:16 +0200 Subject: [PATCH 15/24] Revert "modified test to skip repo creation during setup" This reverts commit da18a5a031acac9a9b80ef15664e05767d655cea. --- tests/test_repository.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/tests/test_repository.py b/tests/test_repository.py index 99d4d340a5..ea542e7b3a 100644 --- a/tests/test_repository.py +++ b/tests/test_repository.py @@ -81,19 +81,16 @@ def setUp(self): logger.info( f"Does {WORKING_REPO_DIR} exist: {os.path.exists(WORKING_REPO_DIR)}" ) - self.REPO_NAME = repo_name() - # skip creation of repository for clone from test - if self.shortDescription() != "SKIP CREATION": - self._repo_url = self._api.create_repo( - repo_id=self.REPO_NAME, token=self._token - ) - self._api.upload_file( - path_or_fileobj=BytesIO(b"some initial binary data: \x00\x01"), - path_in_repo="random_file.txt", - repo_id=f"{USER}/{self.REPO_NAME}", - token=self._token, - ) + self._repo_url = self._api.create_repo( + repo_id=self.REPO_NAME, token=self._token + ) + self._api.upload_file( + path_or_fileobj=BytesIO(b"some initial binary data: \x00\x01"), + path_in_repo="random_file.txt", + repo_id=f"{USER}/{self.REPO_NAME}", + token=self._token, + ) def tearDown(self): try: @@ -152,7 +149,6 @@ def test_clone_from_deprecation_warning(self): WORKING_REPO_DIR, clone_from=f"{USER}/{uuid.uuid4()}", use_auth_token=self._token, - repo_type="dataset", ) def test_clone_from_model(self): From 275c757894e49fc604a6133734d963495cff1745 Mon Sep 17 00:00:00 2001 From: merveenoyan Date: Mon, 1 Aug 2022 16:35:18 +0200 Subject: [PATCH 16/24] Revert "added repo creation to test setups" This reverts commit 792af116137daceaff9638976dce4ba7c8b2512b. --- tests/test_repocard.py | 5 +---- tests/test_snapshot_download.py | 3 +-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/tests/test_repocard.py b/tests/test_repocard.py index 49405ca22f..075d309eed 100644 --- a/tests/test_repocard.py +++ b/tests/test_repocard.py @@ -204,12 +204,9 @@ def setUpClass(cls): def setUp(self) -> None: self.repo_path = Path(tempfile.mkdtemp()) self.REPO_NAME = repo_name() - url = self._api.create_repo( - repo_id=f"{USER}/{self.REPO_NAME}", token=self._token - ) self.repo = Repository( self.repo_path / self.REPO_NAME, - clone_from=url, + clone_from=f"{USER}/{self.REPO_NAME}", use_auth_token=self._token, git_user="ci", git_email="ci@dummy.com", diff --git a/tests/test_snapshot_download.py b/tests/test_snapshot_download.py index 06c15ad000..89714ad3c9 100644 --- a/tests/test_snapshot_download.py +++ b/tests/test_snapshot_download.py @@ -36,10 +36,9 @@ def setUp(self) -> None: if os.path.exists(REPO_NAME): shutil.rmtree(REPO_NAME, onerror=set_write_permission_and_retry) logger.info(f"Does {REPO_NAME} exist: {os.path.exists(REPO_NAME)}") - url = self._api.create_repo(repo_id=f"{USER}/{REPO_NAME}", token=self._token) repo = Repository( REPO_NAME, - clone_from=url, + clone_from=f"{USER}/{REPO_NAME}", use_auth_token=self._token, git_user="ci", git_email="ci@dummy.com", From 9c933cad29881c73ee23eb11345bd662d1bfdb26 Mon Sep 17 00:00:00 2001 From: merveenoyan Date: Mon, 1 Aug 2022 16:35:52 +0200 Subject: [PATCH 17/24] reverted changes --- tests/test_repository.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_repository.py b/tests/test_repository.py index ea542e7b3a..d1583bfcd6 100644 --- a/tests/test_repository.py +++ b/tests/test_repository.py @@ -141,7 +141,7 @@ def test_clone_from_space(self): ) def test_clone_from_deprecation_warning(self): - with pytest.raises( + with pytest.warns( FutureWarning, match="Creating a repository through clone_from is deprecated*", ): From f1704e31754c6f878a3650f8bd0be6520196897d Mon Sep 17 00:00:00 2001 From: merveenoyan Date: Mon, 1 Aug 2022 16:38:07 +0200 Subject: [PATCH 18/24] updated version --- src/huggingface_hub/repository.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/huggingface_hub/repository.py b/src/huggingface_hub/repository.py index c8c3c09bb8..9e53ce7425 100644 --- a/src/huggingface_hub/repository.py +++ b/src/huggingface_hub/repository.py @@ -658,7 +658,7 @@ def clone_from(self, repo_url: str, use_auth_token: Union[bool, str, None] = Non else: warnings.warn( "Creating a repository through clone_from is deprecated" - "will be removed in v0.10.", + "will be removed in v0.11.", FutureWarning, ) From 19e82fc73145076eeccb5e3f20c34fb4a3438299 Mon Sep 17 00:00:00 2001 From: Wauplin Date: Thu, 18 Aug 2022 10:27:16 +0200 Subject: [PATCH 19/24] expect deprecation for clone_from in tests --- src/huggingface_hub/repository.py | 4 ++-- tests/test_repocard.py | 8 +++++++- tests/test_repository.py | 6 ++++++ tests/test_snapshot_download.py | 3 ++- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/huggingface_hub/repository.py b/src/huggingface_hub/repository.py index a0b195077f..951ca4dc2b 100644 --- a/src/huggingface_hub/repository.py +++ b/src/huggingface_hub/repository.py @@ -656,8 +656,8 @@ def clone_from(self, repo_url: str, use_auth_token: Union[bool, str, None] = Non ) else: warnings.warn( - "Creating a repository through clone_from is deprecated" - "will be removed in v0.11.", + "Creating a repository through 'clone_from' is" + " deprecated and will be removed in v0.11.", FutureWarning, ) diff --git a/tests/test_repocard.py b/tests/test_repocard.py index 1184a4cf55..0c63020ef0 100644 --- a/tests/test_repocard.py +++ b/tests/test_repocard.py @@ -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 = """ @@ -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() diff --git a/tests/test_repository.py b/tests/test_repository.py index 809724d076..b595101e5f 100644 --- a/tests/test_repository.py +++ b/tests/test_repository.py @@ -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, @@ -444,6 +445,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}", @@ -474,6 +476,7 @@ def test_clone_with_repo_name_and_org(self): self.assertTrue("model.bin" in files) @retry_endpoint + @expect_deprecation("clone_from") def test_clone_with_repo_name_and_user_namespace(self): clone = Repository( f"{WORKING_REPO_DIR}/{self.REPO_NAME}", @@ -518,6 +521,7 @@ def test_clone_with_repo_name_and_no_namespace(self): ) @retry_endpoint + @expect_deprecation("clone_from") def test_clone_with_repo_name_user_and_no_auth_token(self): # Create repo Repository( @@ -1705,6 +1709,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}", @@ -1799,6 +1804,7 @@ 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( diff --git a/tests/test_snapshot_download.py b/tests/test_snapshot_download.py index 89714ad3c9..f7a14c44a8 100644 --- a/tests/test_snapshot_download.py +++ b/tests/test_snapshot_download.py @@ -12,7 +12,7 @@ from huggingface_hub.utils import logging from .testing_constants import ENDPOINT_STAGING, TOKEN, USER -from .testing_utils import retry_endpoint, set_write_permission_and_retry +from .testing_utils import expect_deprecation, retry_endpoint, set_write_permission_and_retry logger = logging.get_logger(__name__) @@ -32,6 +32,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) From f5351f7bd06296897875a0b5334cbdd4fb60f06a Mon Sep 17 00:00:00 2001 From: merveenoyan Date: Mon, 29 Aug 2022 14:41:52 +0200 Subject: [PATCH 20/24] make style --- tests/test_snapshot_download.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_snapshot_download.py b/tests/test_snapshot_download.py index 080147a3ec..63069482fd 100644 --- a/tests/test_snapshot_download.py +++ b/tests/test_snapshot_download.py @@ -12,7 +12,6 @@ from huggingface_hub.utils import logging from .testing_constants import ENDPOINT_STAGING, TOKEN, USER - from .testing_utils import ( expect_deprecation, retry_endpoint, From d05d083d5b07e5c1129725ef14b5e746bb39294e Mon Sep 17 00:00:00 2001 From: Lucain Date: Mon, 29 Aug 2022 17:13:52 +0200 Subject: [PATCH 21/24] Update tests/test_repository.py --- tests/test_repository.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_repository.py b/tests/test_repository.py index b595101e5f..14614a5200 100644 --- a/tests/test_repository.py +++ b/tests/test_repository.py @@ -141,7 +141,7 @@ def test_clone_from_space(self): def test_clone_from_deprecation_warning(self): with pytest.warns( FutureWarning, - match="Creating a repository through clone_from is deprecated*", + match="Creating a repository through 'clone_from' is deprecated*", ): Repository( WORKING_REPO_DIR, From 12b47cd82bf50ffa59e807dcde35fdadba0a3c73 Mon Sep 17 00:00:00 2001 From: Lucain Date: Mon, 29 Aug 2022 17:42:17 +0200 Subject: [PATCH 22/24] Update tests/test_repository.py --- tests/test_repository.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_repository.py b/tests/test_repository.py index 14614a5200..11eb81467e 100644 --- a/tests/test_repository.py +++ b/tests/test_repository.py @@ -476,7 +476,6 @@ def test_clone_with_repo_name_and_org(self): self.assertTrue("model.bin" in files) @retry_endpoint - @expect_deprecation("clone_from") def test_clone_with_repo_name_and_user_namespace(self): clone = Repository( f"{WORKING_REPO_DIR}/{self.REPO_NAME}", From 0e82e9ecd79f9b22d0be82b58a5094d53f0f16e9 Mon Sep 17 00:00:00 2001 From: merveenoyan Date: Mon, 29 Aug 2022 20:08:33 +0200 Subject: [PATCH 23/24] fixed tests --- tests/test_repository.py | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/tests/test_repository.py b/tests/test_repository.py index b595101e5f..017192b05f 100644 --- a/tests/test_repository.py +++ b/tests/test_repository.py @@ -137,17 +137,14 @@ def test_clone_from_space(self): repo_type="space", use_auth_token=self._token, ) - + + @expect_deprecation("clone_from") def test_clone_from_deprecation_warning(self): - with pytest.warns( - FutureWarning, - match="Creating a repository through clone_from is deprecated*", - ): - Repository( - WORKING_REPO_DIR, - clone_from=f"{USER}/{uuid.uuid4()}", - use_auth_token=self._token, - ) + 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( @@ -415,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}", @@ -476,7 +474,6 @@ def test_clone_with_repo_name_and_org(self): self.assertTrue("model.bin" in files) @retry_endpoint - @expect_deprecation("clone_from") def test_clone_with_repo_name_and_user_namespace(self): clone = Repository( f"{WORKING_REPO_DIR}/{self.REPO_NAME}", @@ -521,7 +518,6 @@ def test_clone_with_repo_name_and_no_namespace(self): ) @retry_endpoint - @expect_deprecation("clone_from") def test_clone_with_repo_name_user_and_no_auth_token(self): # Create repo Repository( @@ -540,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, @@ -1806,7 +1802,6 @@ 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}", From 801c56054fb7233cf4e05a61f538c562e420635a Mon Sep 17 00:00:00 2001 From: merveenoyan Date: Mon, 29 Aug 2022 20:17:06 +0200 Subject: [PATCH 24/24] make style --- tests/test_repository.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_repository.py b/tests/test_repository.py index 017192b05f..8870409545 100644 --- a/tests/test_repository.py +++ b/tests/test_repository.py @@ -137,7 +137,7 @@ def test_clone_from_space(self): repo_type="space", use_auth_token=self._token, ) - + @expect_deprecation("clone_from") def test_clone_from_deprecation_warning(self): Repository(