|
32 | 32 | SPACES_SDK_TYPES, |
33 | 33 | ) |
34 | 34 | from .utils import logging |
| 35 | +from .utils._deprecation import _deprecate_positional_args |
35 | 36 | from .utils._errors import _raise_for_status, _raise_with_request_id |
36 | 37 | from .utils._fixes import JSONDecodeError |
37 | 38 | from .utils.endpoint_helpers import ( |
|
55 | 56 | logger = logging.get_logger(__name__) |
56 | 57 |
|
57 | 58 |
|
| 59 | +# TODO: remove after deprecation period is over (v0.10) |
| 60 | +def _validate_repo_id_deprecation(repo_id, name, organization): |
| 61 | + """Returns (name, organization) from the input.""" |
| 62 | + if repo_id and not name and organization: |
| 63 | + # this means the user had passed name as positional, now mapped to |
| 64 | + # repo_id and is passing organization as well. This wouldn't be an |
| 65 | + # issue if they pass everything as kwarg. So we switch the parameters |
| 66 | + # here: |
| 67 | + repo_id, name = name, repo_id |
| 68 | + |
| 69 | + if not (repo_id or name): |
| 70 | + raise ValueError( |
| 71 | + "No name provided. Please pass `repo_id` with a valid repository name." |
| 72 | + ) |
| 73 | + |
| 74 | + if repo_id and (name or organization): |
| 75 | + raise ValueError( |
| 76 | + "Only pass `repo_id` and leave deprecated `name` and " |
| 77 | + "`organization` to be None." |
| 78 | + ) |
| 79 | + elif name or organization: |
| 80 | + warnings.warn( |
| 81 | + "`name` and `organization` input arguments are deprecated and " |
| 82 | + "will be removed in v0.10. Pass `repo_id` instead.", |
| 83 | + FutureWarning, |
| 84 | + ) |
| 85 | + else: |
| 86 | + if "/" in repo_id: |
| 87 | + organization, name = repo_id.split("/") |
| 88 | + else: |
| 89 | + organization, name = None, repo_id |
| 90 | + return name, organization |
| 91 | + |
| 92 | + |
58 | 93 | def repo_type_and_id_from_hf_id( |
59 | 94 | hf_id: str, hub_url: Optional[str] = None |
60 | 95 | ) -> Tuple[Optional[str], Optional[str], str]: |
@@ -1294,15 +1329,18 @@ def list_repo_files( |
1294 | 1329 | ) |
1295 | 1330 | return [f.rfilename for f in repo_info.siblings] |
1296 | 1331 |
|
| 1332 | + @_deprecate_positional_args |
1297 | 1333 | def create_repo( |
1298 | 1334 | self, |
1299 | 1335 | repo_id: str = None, |
1300 | 1336 | *, |
1301 | 1337 | token: Optional[str] = None, |
| 1338 | + organization: Optional[str] = None, |
1302 | 1339 | private: Optional[bool] = None, |
1303 | 1340 | repo_type: Optional[str] = None, |
1304 | 1341 | exist_ok: Optional[bool] = False, |
1305 | 1342 | space_sdk: Optional[str] = None, |
| 1343 | + name: Optional[str] = None, |
1306 | 1344 | ) -> str: |
1307 | 1345 | """Create an empty repo on the HuggingFace Hub. |
1308 | 1346 |
|
@@ -1334,7 +1372,7 @@ def create_repo( |
1334 | 1372 | Returns: |
1335 | 1373 | `str`: URL to the newly created repo. |
1336 | 1374 | """ |
1337 | | - organization, name = repo_id.split("/") if "/" in repo_id else (None, repo_id) |
| 1375 | + name, organization = _validate_repo_id_deprecation(repo_id, name, organization) |
1338 | 1376 |
|
1339 | 1377 | path = f"{self.endpoint}/api/repos/create" |
1340 | 1378 |
|
|
0 commit comments