Skip to content

Commit e6a7f29

Browse files
committed
Invert deprecation for create_repo
Set to 0.10
1 parent 1544ef5 commit e6a7f29

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

src/huggingface_hub/hf_api.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
SPACES_SDK_TYPES,
3333
)
3434
from .utils import logging
35+
from .utils._deprecation import _deprecate_positional_args
3536
from .utils._errors import _raise_for_status, _raise_with_request_id
3637
from .utils._fixes import JSONDecodeError
3738
from .utils.endpoint_helpers import (
@@ -55,6 +56,40 @@
5556
logger = logging.get_logger(__name__)
5657

5758

59+
# TODO: remove after deprecation period is over (v0.10)
60+
def _validate_repo_id_deprecation(repo_id, name, organization):
61+
"""Returns (name, organization) from the input."""
62+
if repo_id and not name and organization:
63+
# this means the user had passed name as positional, now mapped to
64+
# repo_id and is passing organization as well. This wouldn't be an
65+
# issue if they pass everything as kwarg. So we switch the parameters
66+
# here:
67+
repo_id, name = name, repo_id
68+
69+
if not (repo_id or name):
70+
raise ValueError(
71+
"No name provided. Please pass `repo_id` with a valid repository name."
72+
)
73+
74+
if repo_id and (name or organization):
75+
raise ValueError(
76+
"Only pass `repo_id` and leave deprecated `name` and "
77+
"`organization` to be None."
78+
)
79+
elif name or organization:
80+
warnings.warn(
81+
"`name` and `organization` input arguments are deprecated and "
82+
"will be removed in v0.10. Pass `repo_id` instead.",
83+
FutureWarning,
84+
)
85+
else:
86+
if "/" in repo_id:
87+
organization, name = repo_id.split("/")
88+
else:
89+
organization, name = None, repo_id
90+
return name, organization
91+
92+
5893
def repo_type_and_id_from_hf_id(
5994
hf_id: str, hub_url: Optional[str] = None
6095
) -> Tuple[Optional[str], Optional[str], str]:
@@ -1294,15 +1329,18 @@ def list_repo_files(
12941329
)
12951330
return [f.rfilename for f in repo_info.siblings]
12961331

1332+
@_deprecate_positional_args
12971333
def create_repo(
12981334
self,
12991335
repo_id: str = None,
13001336
*,
13011337
token: Optional[str] = None,
1338+
organization: Optional[str] = None,
13021339
private: Optional[bool] = None,
13031340
repo_type: Optional[str] = None,
13041341
exist_ok: Optional[bool] = False,
13051342
space_sdk: Optional[str] = None,
1343+
name: Optional[str] = None,
13061344
) -> str:
13071345
"""Create an empty repo on the HuggingFace Hub.
13081346
@@ -1334,7 +1372,7 @@ def create_repo(
13341372
Returns:
13351373
`str`: URL to the newly created repo.
13361374
"""
1337-
organization, name = repo_id.split("/") if "/" in repo_id else (None, repo_id)
1375+
name, organization = _validate_repo_id_deprecation(repo_id, name, organization)
13381376

13391377
path = f"{self.endpoint}/api/repos/create"
13401378

0 commit comments

Comments
 (0)