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

Invert deprecation for create_repo #912

Merged
merged 2 commits into from
Jun 16, 2022
Merged
Changes from all commits
Commits
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
40 changes: 39 additions & 1 deletion src/huggingface_hub/hf_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
SPACES_SDK_TYPES,
)
from .utils import logging
from .utils._deprecation import _deprecate_positional_args
from .utils._errors import _raise_for_status, _raise_with_request_id
from .utils._fixes import JSONDecodeError
from .utils.endpoint_helpers import (
Expand All @@ -55,6 +56,40 @@
logger = logging.get_logger(__name__)


# TODO: remove after deprecation period is over (v0.10)
def _validate_repo_id_deprecation(repo_id, name, organization):
"""Returns (name, organization) from the input."""
if repo_id and not name and organization:
# this means the user had passed name as positional, now mapped to
# repo_id and is passing organization as well. This wouldn't be an
# issue if they pass everything as kwarg. So we switch the parameters
# here:
repo_id, name = name, repo_id

if not (repo_id or name):
raise ValueError(
"No name provided. Please pass `repo_id` with a valid repository name."
)

if repo_id and (name or organization):
raise ValueError(
"Only pass `repo_id` and leave deprecated `name` and "
"`organization` to be None."
)
elif name or organization:
warnings.warn(
"`name` and `organization` input arguments are deprecated and "
"will be removed in v0.10. Pass `repo_id` instead.",
FutureWarning,
)
else:
if "/" in repo_id:
organization, name = repo_id.split("/")
else:
organization, name = None, repo_id
return name, organization


def repo_type_and_id_from_hf_id(
hf_id: str, hub_url: Optional[str] = None
) -> Tuple[Optional[str], Optional[str], str]:
Expand Down Expand Up @@ -1294,15 +1329,18 @@ def list_repo_files(
)
return [f.rfilename for f in repo_info.siblings]

@_deprecate_positional_args
def create_repo(
self,
repo_id: str = None,
*,
token: Optional[str] = None,
organization: Optional[str] = None,
private: Optional[bool] = None,
repo_type: Optional[str] = None,
exist_ok: Optional[bool] = False,
space_sdk: Optional[str] = None,
name: Optional[str] = None,
) -> str:
"""Create an empty repo on the HuggingFace Hub.

Expand Down Expand Up @@ -1334,7 +1372,7 @@ def create_repo(
Returns:
`str`: URL to the newly created repo.
"""
organization, name = repo_id.split("/") if "/" in repo_id else (None, repo_id)
name, organization = _validate_repo_id_deprecation(repo_id, name, organization)

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

Expand Down