Skip to content

Commit

Permalink
💄 style
Browse files Browse the repository at this point in the history
  • Loading branch information
nateraw committed Oct 28, 2021
1 parent d6c573b commit 1f36461
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
10 changes: 7 additions & 3 deletions src/huggingface_hub/commands/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
from typing import List, Union

from huggingface_hub.commands import BaseHuggingfaceCLICommand
from huggingface_hub.constants import REPO_TYPES, REPO_TYPES_URL_PREFIXES, SPACES_SDK_TYPES
from huggingface_hub.constants import (
REPO_TYPES,
REPO_TYPES_URL_PREFIXES,
SPACES_SDK_TYPES,
)
from huggingface_hub.hf_api import HfApi, HfFolder
from requests.exceptions import HTTPError

Expand Down Expand Up @@ -69,7 +73,7 @@ def register_subcommand(parser: ArgumentParser):
"--organization", type=str, help="Optional: organization namespace."
)
repo_create_parser.add_argument(
"--spaces_sdk",
"--space_sdk",
type=str,
help='Optional: Hugging Face Spaces SDK type. Required when --type is set to "space".',
choices=SPACES_SDK_TYPES,
Expand Down Expand Up @@ -269,7 +273,7 @@ def run(self):
token=token,
organization=self.args.organization,
repo_type=self.args.type,
spaces_sdk=self.args.spaces_sdk,
space_sdk=self.args.space_sdk,
)
except HTTPError as e:
print(e)
Expand Down
2 changes: 1 addition & 1 deletion src/huggingface_hub/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
REPO_TYPE_DATASET = "dataset"
REPO_TYPE_SPACE = "space"
REPO_TYPES = [None, REPO_TYPE_DATASET, REPO_TYPE_SPACE]
SPACES_SDK_TYPES = ["gradio", "streamlit"]
SPACES_SDK_TYPES = ["gradio", "streamlit", "static"]

REPO_TYPES_URL_PREFIXES = {
REPO_TYPE_DATASET: "datasets/",
Expand Down
22 changes: 14 additions & 8 deletions src/huggingface_hub/hf_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ def create_repo(
repo_type: Optional[str] = None,
exist_ok=False,
lfsmultipartthresh: Optional[int] = None,
spaces_sdk: Optional[str] = None,
space_sdk: Optional[str] = None,
) -> str:
"""
HuggingFace git-based system, used for models, datasets, and spaces.
Expand All @@ -686,7 +686,7 @@ def create_repo(
lfsmultipartthresh: Optional: internal param for testing purposes.
spaces_sdk: Choice of SDK to use if repo_type is "space". Can be "streamlit" or "gradio".
space_sdk: Choice of SDK to use if repo_type is "space". Can be "streamlit", "gradio", or "static".
Returns:
URL to the newly created repo.
Expand Down Expand Up @@ -717,16 +717,21 @@ def create_repo(
if repo_type is not None:
json["type"] = repo_type
if repo_type == "space":
if spaces_sdk is None:
if space_sdk is None:
raise ValueError(
"No spaces_sdk provided. `create_repo` expects spaces_sdk to be one of "
"No space_sdk provided. `create_repo` expects space_sdk to be one of "
f"{SPACES_SDK_TYPES} when repo_type is 'space'`"
)
if spaces_sdk not in SPACES_SDK_TYPES:
if space_sdk not in SPACES_SDK_TYPES:
raise ValueError(
f"Invalid spaces_sdk. Please choose one of {SPACES_SDK_TYPES}."
f"Invalid space_sdk. Please choose one of {SPACES_SDK_TYPES}."
)
json["sdk"] = spaces_sdk
json["sdk"] = space_sdk
if space_sdk is not None and repo_type != "space":
warnings.warn(
"Ignoring provided space_sdk because repo_type is not 'space'."
)

if lfsmultipartthresh is not None:
json["lfsmultipartthresh"] = lfsmultipartthresh
r = requests.post(
Expand Down Expand Up @@ -841,7 +846,8 @@ def update_repo_visibility(
path_prefix += REPO_TYPES_URL_PREFIXES[repo_type]

path = "{}{}/{}/settings".format(path_prefix, namespace, name)
json = {"private": private}
# HACK - hard coded recently added 'gated' param for now. Decide how to deal with this in the future.
json = {"private": private, "gated": False}

r = requests.put(
path,
Expand Down
10 changes: 5 additions & 5 deletions tests/test_hf_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,27 +161,27 @@ def test_create_update_and_delete_dataset_repo(self):

@unittest.skip("skipped while spaces in beta")
def test_create_update_and_delete_space_repo(self):
with pytest.raises(ValueError, match=r"No spaces_sdk provided.*"):
with pytest.raises(ValueError, match=r"No space_sdk provided.*"):
self._api.create_repo(
token=self._token,
name=SPACE_REPO_NAME,
repo_type=REPO_TYPE_SPACE,
spaces_sdk=None,
space_sdk=None,
)
with pytest.raises(ValueError, match=r"Invalid spaces_sdk.*"):
with pytest.raises(ValueError, match=r"Invalid space_sdk.*"):
self._api.create_repo(
token=self._token,
name=SPACE_REPO_NAME,
repo_type=REPO_TYPE_SPACE,
spaces_sdk="asdfasdf",
space_sdk="asdfasdf",
)

for sdk in SPACES_SDK_TYPES:
self._api.create_repo(
name=SPACE_REPO_NAME,
token=self._token,
repo_type=REPO_TYPE_SPACE,
spaces_sdk=sdk,
space_sdk=sdk,
)
res = self._api.update_repo_visibility(
name=SPACE_REPO_NAME,
Expand Down

0 comments on commit 1f36461

Please sign in to comment.