huggingface_hub
Add token and git credentials to login cli command
#1372
Merged

Add token and git credentials to login cli command #1372

Wauplin merged 2 commits into huggingface:main from silvanocerza:login-args
silvanocerza
silvanocerza2 years ago❤ 2

As of now it's not possible to login in a non interactive shell using huggingface-cli login as it always prompt to input the token. This makes it hard to use the CLI for automation, for example in GitHub Actions.

This PR adds --token and --add-to-git-credential args to huggingface-cli login command.

$ huggingface-cli login --help
usage: huggingface-cli <command> [<args>] login [-h] [--token TOKEN] [--add-to-git-credential]

options:
  -h, --help            show this help message and exit
  --token TOKEN         Token generated from https://huggingface.co/settings/tokens
  --add-to-git-credential
                        Optional: Save token to git credential helper.

Example call:

$ huggingface-cli login --token $HUGGING_FACE_TOKEN --add-to-git-credential
silvanocerza Add token and git credentials to login cli command
3632bf60
Wauplin
Wauplin approved these changes on 2023-03-02
Wauplin2 years ago🚀 1

Nice PR @silvanocerza , thank you for your help!
I made some cosmetic changes but otherwise I think we are good to merge it as soon as the CI is green.

Conversation is marked as resolved
Show resolved
src/huggingface_hub/commands/user.py
47 login_parser.add_argument(
48 "--token",
49 type=str,
50
help="Token generated from https://huggingface.co/settings/tokens"
Wauplin2 years ago
Suggested change
help="Token generated from https://huggingface.co/settings/tokens"
help="Token generated from https://huggingface.co/settings/tokens",
Conversation is marked as resolved
Show resolved
src/huggingface_hub/commands/user.py
52 login_parser.add_argument(
53 "--add-to-git-credential",
54 action="store_true",
55
help="Optional: Save token to git credential helper."
Wauplin2 years ago
Suggested change
help="Optional: Save token to git credential helper."
help="Optional: Save token to git credential helper.",
Conversation is marked as resolved
Show resolved
src/huggingface_hub/commands/user.py
92102class LoginCommand(BaseUserCommand):
93103 def run(self):
94 login()
104
login(self.args.token, self.args.add_to_git_credential)
Wauplin2 years ago
Suggested change
login(self.args.token, self.args.add_to_git_credential)
login(token=self.args.token, add_to_git_credential=self.args.add_to_git_credential)
Wauplin Apply suggestions from code review
f6f39158
HuggingFaceDocBuilderDev
HuggingFaceDocBuilderDev2 years ago (edited 2 years ago)

The documentation is not available anymore as the PR was closed or merged.

Wauplin Wauplin merged 318f1be7 into main 2 years ago
Wauplin
Wauplin2 years ago❤ 1

And it's merged! Thanks for this contribution @silvanocerza. Clean and quick! :)

silvanocerza silvanocerza deleted the login-args branch 2 years ago
julien-c
julien-c2 years ago❤ 1

thanks a lot @silvanocerza!

Login to write a write a comment.

Login via GitHub

Reviewers
Assignees
No one assigned
Labels
Milestone