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
27 changes: 26 additions & 1 deletion src/huggingface_hub/hf_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,17 @@ def create_repo(
else:
raise ValueError("Invalid token passed!")

checked_name = repo_type_and_id_from_hf_id(name)
name = checked_name[2]

if organization is None:
organization = checked_name[1]
elif organization != checked_name[1]:
raise ValueError(
f"""Passed `organization` and `name` organization are not the same ({organization}, {checked_name[1]}).
Please either include the organization in only `name` or the `organization` parameter, such as `api.create_repo({checked_name[0]}, organization={organization})` or `api.create_repo({checked_name[1]}/{checked_name[2]})`"""
)
Comment on lines +828 to +831
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice


if repo_type not in REPO_TYPES:
raise ValueError("Invalid repo type")

Expand Down Expand Up @@ -888,6 +899,17 @@ def delete_repo(
else:
raise ValueError("Invalid token passed!")

checked_name = repo_type_and_id_from_hf_id(name)
name = checked_name[2]

if organization is None:
organization = checked_name[1]
elif organization != checked_name[1]:
raise ValueError(
f"""Passed `organization` and `name` organization are not the same ({organization}, {checked_name[1]}).
Please either include the organization in only `name` or the `organization` parameter, such as `api.create_repo({checked_name[0]}, organization={organization})` or `api.create_repo({checked_name[1]}/{checked_name[2]})`"""
)

if repo_type not in REPO_TYPES:
raise ValueError("Invalid repo type")

Expand Down Expand Up @@ -1185,7 +1207,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