Skip to content

Commit f98eeff

Browse files
LysandreJikjulien-c
andcommitted
Remove deprecations (#910)
* Remove deprecations * Typo * Update src/huggingface_hub/README.md Co-authored-by: Julien Chaumond <[email protected]> Co-authored-by: Julien Chaumond <[email protected]>
1 parent f21aa5a commit f98eeff

File tree

6 files changed

+33
-341
lines changed

6 files changed

+33
-341
lines changed

src/huggingface_hub/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ programmatic way of creating a repo, deleting it (`⚠️ caution`), pushing a
9797
single file to a repo or listing models from the Hub, you'll find helpers in
9898
`hf_api.py`. Some example functionality available with the `HfApi` class:
9999

100-
* `login()`
100+
* `set_access_token()`
101+
* `unset_access_token()`
101102
* `whoami()`
102-
* `logout()`
103103
* `create_repo()`
104104
* `list_repo_files()`
105105
* `list_repo_objects()`

src/huggingface_hub/_snapshot_download.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from .file_download import REGEX_COMMIT_HASH, hf_hub_download, repo_folder_name
88
from .hf_api import HfApi, HfFolder
99
from .utils import logging
10-
from .utils._deprecation import _deprecate_positional_args
1110

1211

1312
logger = logging.get_logger(__name__)
@@ -39,7 +38,6 @@ def _filter_repo_files(
3938
return filtered_files
4039

4140

42-
@_deprecate_positional_args
4341
def snapshot_download(
4442
repo_id: str,
4543
*,

src/huggingface_hub/commands/user.py

Lines changed: 5 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -168,18 +168,11 @@ def run(self):
168168
_| _| _|_| _|_|_| _|_|_| _|_|_| _| _| _|_|_| _| _| _| _|_|_| _|_|_|_|
169169
170170
To login, `huggingface_hub` now requires a token generated from https://huggingface.co/settings/tokens .
171-
(Deprecated, will be removed in v0.3.0) To login with username and password instead, interrupt with Ctrl+C.
172171
"""
173172
)
174173

175-
try:
176-
token = getpass("Token: ")
177-
_login(self._api, token=token)
178-
179-
except KeyboardInterrupt:
180-
username = input("\rUsername: ")
181-
password = getpass()
182-
_login(self._api, username, password)
174+
token = getpass("Token: ")
175+
_login(self._api, token=token)
183176

184177

185178
class WhoamiCommand(BaseUserCommand):
@@ -208,12 +201,6 @@ def run(self):
208201
exit()
209202
HfFolder.delete_token()
210203
HfApi.unset_access_token()
211-
try:
212-
self._api.logout(token)
213-
except HTTPError as e:
214-
# Logging out with an access token will return a client error.
215-
if not e.response.status_code == 400:
216-
raise e
217204
print("Successfully logged out.")
218205

219206

@@ -304,9 +291,7 @@ def run(self):
304291
NOTEBOOK_LOGIN_TOKEN_HTML_END = """
305292
<b>Pro Tip:</b> If you don't already have one, you can create a dedicated
306293
'notebooks' token with 'write' access, that you can then easily reuse for all
307-
notebooks. <br> <i>Logging in with your username and password is deprecated and
308-
won't be possible anymore in the near future. You can still use them for now by
309-
clicking below.</i> </center>"""
294+
notebooks. </center>"""
310295

311296

312297
def notebook_login():
@@ -328,34 +313,18 @@ def notebook_login():
328313

329314
token_widget = widgets.Password(description="Token:")
330315
token_finish_button = widgets.Button(description="Login")
331-
switch_button = widgets.Button(description="Use password")
332316

333317
login_token_widget = widgets.VBox(
334318
[
335319
widgets.HTML(NOTEBOOK_LOGIN_TOKEN_HTML_START),
336320
token_widget,
337321
token_finish_button,
338322
widgets.HTML(NOTEBOOK_LOGIN_TOKEN_HTML_END),
339-
switch_button,
340323
],
341324
layout=box_layout,
342325
)
343326
display(login_token_widget)
344327

345-
# Deprecated page for login
346-
input_widget = widgets.Text(description="Username:")
347-
password_widget = widgets.Password(description="Password:")
348-
password_finish_button = widgets.Button(description="Login")
349-
350-
login_password_widget = widgets.VBox(
351-
[
352-
widgets.HTML(value=NOTEBOOK_LOGIN_PASSWORD_HTML),
353-
widgets.HBox([input_widget, password_widget]),
354-
password_finish_button,
355-
],
356-
layout=box_layout,
357-
)
358-
359328
# On click events
360329
def login_token_event(t):
361330
token = token_widget.value
@@ -366,35 +335,9 @@ def login_token_event(t):
366335

367336
token_finish_button.on_click(login_token_event)
368337

369-
def login_password_event(t):
370-
username = input_widget.value
371-
password = password_widget.value
372-
# Erase password and clear value to make sure it's not saved in the notebook.
373-
password_widget.value = ""
374-
clear_output()
375-
_login(HfApi(), username=username, password=password)
376-
377-
password_finish_button.on_click(login_password_event)
378-
379-
def switch_event(t):
380-
clear_output()
381-
display(login_password_widget)
382-
383-
switch_button.on_click(switch_event)
384-
385-
386-
def _login(hf_api, username=None, password=None, token=None):
387-
if token is None:
388-
try:
389-
token = hf_api.login(username, password)
390-
except HTTPError as e:
391-
# probably invalid credentials, display error message.
392-
print(e)
393-
print(ANSI.red(e.response.text))
394-
exit(1)
395-
else:
396-
token, name = hf_api._validate_or_retrieve_token(token)
397338

339+
def _login(hf_api, token=None):
340+
token, name = hf_api._validate_or_retrieve_token(token)
398341
hf_api.set_access_token(token)
399342
HfFolder.save_token(token)
400343
print("Login successful")

src/huggingface_hub/file_download.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
)
3535
from .hf_api import HfFolder
3636
from .utils import logging
37-
from .utils._deprecation import _deprecate_positional_args
3837
from .utils._errors import _raise_for_status
3938

4039

@@ -151,7 +150,6 @@ def get_fastcore_version():
151150
REGEX_COMMIT_HASH = re.compile(r"^[0-9a-f]{40}$")
152151

153152

154-
@_deprecate_positional_args
155153
def hf_hub_url(
156154
repo_id: str,
157155
filename: str,
@@ -310,7 +308,6 @@ def filename_to_url(
310308
return url, etag
311309

312310

313-
@_deprecate_positional_args
314311
def http_user_agent(
315312
*,
316313
library_name: Optional[str] = None,
@@ -425,7 +422,6 @@ def _request_with_retry(
425422
return response
426423

427424

428-
@_deprecate_positional_args
429425
def http_get(
430426
url: str,
431427
temp_file: BinaryIO,
@@ -469,7 +465,6 @@ def http_get(
469465
progress.close()
470466

471467

472-
@_deprecate_positional_args
473468
def cached_download(
474469
url: str,
475470
*,
@@ -800,7 +795,6 @@ def repo_folder_name(*, repo_id: str, repo_type: str) -> str:
800795
return REPO_ID_SEPARATOR.join(parts)
801796

802797

803-
@_deprecate_positional_args
804798
def hf_hub_download(
805799
repo_id: str,
806800
filename: str,

0 commit comments

Comments
 (0)