Repository: huggingface/huggingface_hub
Pull request #621 (2022-01-24 11:56:29)

[docs] Add `other` to licenses
cc @Pierrci

osanseviero: What's the use case of this? Doesn't it go against the goal to standardize the licensing? (My worry is people exploiting this one)

Patch:
diff --git a/docs/hub/endpoints.md b/docs/hub/endpoints.md
index ab5d2318..c531682a 100644
--- a/docs/hub/endpoints.md
+++ b/docs/hub/endpoints.md
@@ -24,9 +24,7 @@ We have open endpoints that you can use to retrieve information from the Hub as
 | /api/repos/delete    DELETE                                                  | Delete a repository. It's a model repo by default.   -         type: Type of repo (datasets or spaces; model by default).   - name: Name of repo.   - organization: Name of organization.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              | `delete_repo()`                        | ```headers = { "authorization" :  "Bearer $token" }```  ```json= {"type":"type", "name":"name", "organization":"organization"}```                                     |                                                     |
 | /api/repos/{type}/{repo_id}/settings   PUT                                   | Update repo visibility.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                | `update_repo_visibility()`             | ```headers = { "authorization" :  "Bearer $token" }```  ```json= {"private":"private"}```                                                                             |                                                     |
 | /api/{type}/{repo_id}/    upload/{revision}/{path_in_repo}    POST           | Upload a file to a specific repository.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                | `upload_file()`                        | ```headers = { "authorization" :  "Bearer $token" }```  ```"data"="bytestream"```                                                                                     |                                                     |
-| /api/login    POST                                                           | Login user and obtain authentication token.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            | `login(username, password)`            | ```json = { "username" :  "username", "password": "password" }```                                                                                                   
 | /api/whoami    GET                                                           | Get username and organizations the user belongs to.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | `whoami(token)`                        | ```headers = { "authorization" :  "Bearer $token" }```                                                                                                                |                                                     |
-| /api/logout                    POST                                          | Log out user.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          | `logout(token)`                        | ```headers = { "authorization" :  "Bearer $token" }```                                                                                                                |                                                     |
 
 ## Webhook
 
diff --git a/docs/hub/model-repos.md b/docs/hub/model-repos.md
index 1f47fe0c..dc7fa593 100644
--- a/docs/hub/model-repos.md
+++ b/docs/hub/model-repos.md
@@ -292,6 +292,9 @@ The Unlicense	| `unlicense`
 zLib License	| `zlib`
 Open Data Commons Public Domain Dedication and License | `pddl`
 Lesser General Public License For Linguistic Resources | `lgpl-lr`
+Other	| `other`
+
+In case of `license: other` please add the license's text to a `LICENSE` file inside your repo (or contact us to add the license you use to this list).
 
 ## Why is it useful to calculate the carbon emissions of my model?
 
diff --git a/setup.py b/setup.py
index a2ddf10e..91d3c55e 100644
--- a/setup.py
+++ b/setup.py
@@ -34,6 +34,7 @@ extras["tensorflow"] = [
 extras["testing"] = [
     "pytest",
     "datasets",
+    "soundfile",
 ]
 
 extras["quality"] = [
diff --git a/src/huggingface_hub/constants.py b/src/huggingface_hub/constants.py
index 4c938633..8f40922b 100644
--- a/src/huggingface_hub/constants.py
+++ b/src/huggingface_hub/constants.py
@@ -33,14 +33,19 @@ HUGGINGFACE_CO_URL_TEMPLATE = ENDPOINT + "/{repo_id}/resolve/{revision}/{filenam
 
 REPO_TYPE_DATASET = "dataset"
 REPO_TYPE_SPACE = "space"
-REPO_TYPES = [None, REPO_TYPE_DATASET, REPO_TYPE_SPACE]
+REPO_TYPE_MODEL = "model"
+REPO_TYPES = [None, REPO_TYPE_MODEL, REPO_TYPE_DATASET, REPO_TYPE_SPACE]
 SPACES_SDK_TYPES = ["gradio", "streamlit", "static"]
 
 REPO_TYPES_URL_PREFIXES = {
     REPO_TYPE_DATASET: "datasets/",
     REPO_TYPE_SPACE: "spaces/",
 }
-REPO_TYPES_MAPPING = {"datasets": REPO_TYPE_DATASET, "spaces": REPO_TYPE_SPACE}
+REPO_TYPES_MAPPING = {
+    "datasets": REPO_TYPE_DATASET,
+    "spaces": REPO_TYPE_SPACE,
+    "models": REPO_TYPE_MODEL,
+}
 
 
 # default cache
diff --git a/src/huggingface_hub/hf_api.py b/src/huggingface_hub/hf_api.py
index 0ec2bc5f..a2054a7f 100644
--- a/src/huggingface_hub/hf_api.py
+++ b/src/huggingface_hub/hf_api.py
@@ -880,7 +880,7 @@ class HfApi:
         """
         Get the list of files in a given repo.
         """
-        if repo_type is None:
+        if repo_type is None or repo_type == "model":
             info = self.model_info(
                 repo_id, revision=revision, token=token, timeout=timeout
             )
@@ -977,7 +977,7 @@ class HfApi:
         Params:
             private: Whether the model repo should be private (requires a paid huggingface.co account)
 
-            repo_type: Set to "dataset" or "space" if creating a dataset or space, default is model
+            repo_type: Set to :obj:`"dataset"` or :obj:`"space"` if uploading to a dataset or space, :obj:`None` or :obj:`"model"` if uploading to a model. Default is :obj:`None`.
 
             exist_ok: Do not raise an error if repo already exists
 
@@ -1039,17 +1039,17 @@ class HfApi:
         json = {"name": name, "organization": organization, "private": private}
         if repo_type is not None:
             json["type"] = repo_type
-            if repo_type == "space":
-                if space_sdk is None:
-                    raise ValueError(
-                        "No space_sdk provided. `create_repo` expects space_sdk to be one of "
-                        f"{SPACES_SDK_TYPES} when repo_type is 'space'`"
-                    )
-                if space_sdk not in SPACES_SDK_TYPES:
-                    raise ValueError(
-                        f"Invalid space_sdk. Please choose one of {SPACES_SDK_TYPES}."
-                    )
-                json["sdk"] = space_sdk
+        if repo_type == "space":
+            if space_sdk is None:
+                raise ValueError(
+                    "No space_sdk provided. `create_repo` expects space_sdk to be one of "
+                    f"{SPACES_SDK_TYPES} when repo_type is 'space'`"
+                )
+            if space_sdk not in SPACES_SDK_TYPES:
+                raise ValueError(
+                    f"Invalid space_sdk. Please choose one of {SPACES_SDK_TYPES}."
+                )
+            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'."
@@ -1234,7 +1234,7 @@ class HfApi:
                 Authentication token, obtained with :function:`HfApi.login` method. Will default to the stored token.
 
             repo_type (``str``, Optional):
-                Set to :obj:`"dataset"` or :obj:`"space"` if uploading to a dataset or space, :obj:`None` if uploading to a model. Default is :obj:`None`.
+                Set to :obj:`"dataset"` or :obj:`"space"` if uploading to a dataset or space, :obj:`None` or :obj:`"model"` if uploading to a model. Default is :obj:`None`.
 
             revision (``str``, Optional):
                 The git revision to commit from. Defaults to the :obj:`"main"` branch.
@@ -1370,7 +1370,7 @@ class HfApi:
                 Authentication token, obtained with :function:`HfApi.login` method. Will default to the stored token.
 
             repo_type (``str``, Optional):
-                Set to :obj:`"dataset"` or :obj:`"space"` if the file is in a dataset or space repository, :obj:`None` if in a model. Default is :obj:`None`.
+                Set to :obj:`"dataset"` or :obj:`"space"` if the file is in a dataset or space, :obj:`None` or :obj:`"model"` if in a model. Default is :obj:`None`.
 
             revision (``str``, Optional):
                 The git revision to commit from. Defaults to the :obj:`"main"` branch.


Test patch:
diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml
index 981ff13d..5e64a27f 100644
--- a/.github/workflows/python-tests.yml
+++ b/.github/workflows/python-tests.yml
@@ -34,6 +34,7 @@ jobs:
 
       - name: Install dependencies
         run: |
+          sudo apt install -y libsndfile1-dev
           pip install --upgrade pip
           pip install .[testing]
 
diff --git a/tests/test_hf_api.py b/tests/test_hf_api.py
index 51ec9e69..b2ac9fd8 100644
--- a/tests/test_hf_api.py
+++ b/tests/test_hf_api.py
@@ -28,6 +28,7 @@ import requests
 from huggingface_hub.commands.user import _login
 from huggingface_hub.constants import (
     REPO_TYPE_DATASET,
+    REPO_TYPE_MODEL,
     REPO_TYPE_SPACE,
     SPACES_SDK_TYPES,
 )
@@ -165,6 +166,23 @@ class HfApiEndpointsTest(HfApiCommonTestWithLogin):
         self.assertFalse(res["private"])
         self._api.delete_repo(name=REPO_NAME, token=self._token)
 
+    def test_create_update_and_delete_model_repo(self):
+        REPO_NAME = repo_name("crud")
+        self._api.create_repo(
+            name=REPO_NAME, token=self._token, repo_type=REPO_TYPE_MODEL
+        )
+        res = self._api.update_repo_visibility(
+            name=REPO_NAME, token=self._token, private=True, repo_type=REPO_TYPE_MODEL
+        )
+        self.assertTrue(res["private"])
+        res = self._api.update_repo_visibility(
+            name=REPO_NAME, token=self._token, private=False, repo_type=REPO_TYPE_MODEL
+        )
+        self.assertFalse(res["private"])
+        self._api.delete_repo(
+            name=REPO_NAME, token=self._token, repo_type=REPO_TYPE_MODEL
+        )
+
     def test_create_update_and_delete_dataset_repo(self):
         DATASET_REPO_NAME = dataset_repo_name("crud")
         self._api.create_repo(