Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Bring consistency to download and upload APIs #574

Merged
merged 13 commits into from
Jan 5, 2022
23 changes: 22 additions & 1 deletion src/huggingface_hub/hf_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,15 @@ def create_repo(
if repo_type not in REPO_TYPES:
raise ValueError("Invalid repo type")

if "/" in name:
if organization is not None:
if organization != name.split("/")[1]:
raise ValueError(
f"Both a `name` with an organization and an `organization` were passed in that do not align ({name}, {organization}). Please ensure these align to the same organization"
)
else:
name, organization = name.split("/")

json = {"name": name, "organization": organization, "private": private}
if repo_type is not None:
json["type"] = repo_type
Expand Down Expand Up @@ -891,6 +900,15 @@ def delete_repo(
if repo_type not in REPO_TYPES:
raise ValueError("Invalid repo type")

if "/" in name:
if organization is not None:
if organization != name.split("/")[1]:
raise ValueError(
f"Both a `name` with an organization and an `organization` were passed in that do not align ({name}, {organization}). Please ensure these align to the same organization"
)
else:
name, organization = name.split("/")

json = {"name": name, "organization": organization}
if repo_type is not None:
json["type"] = repo_type
Expand Down Expand Up @@ -1185,7 +1203,10 @@ def get_full_repo_name(
otherwise.
"""
if organization is None:
username = self.whoami(token=token)["name"]
if "/" in model_id:
username = model_id.split("/")[0]
else:
username = self.whoami(token=token)["name"]
return f"{username}/{model_id}"
else:
return f"{organization}/{model_id}"
Expand Down