text
stringlengths
38
361k
type
stringclasses
1 value
start
int64
156
155k
end
int64
451
418k
depth
int64
0
0
filepath
stringlengths
87
141
parent_class
null
class_index
int64
0
305
class TagCommand: def __init__(self, args: Namespace): self.args = args self.api = HfApi(token=self.args.token) self.repo_id = self.args.repo_id self.repo_type = self.args.repo_type if self.repo_type not in REPO_TYPES: print("Invalid repo --repo-type") exit(1)
class_definition
3,373
3,701
0
/Users/nielsrogge/Documents/python_projecten/huggingface_hub/src/huggingface_hub/commands/tag.py
null
300
class TagCreateCommand(TagCommand): def run(self): print(f"You are about to create tag {ANSI.bold(self.args.tag)} on {self.repo_type} {ANSI.bold(self.repo_id)}") try: self.api.create_tag( repo_id=self.repo_id, tag=self.args.tag, tag_message=self.args.message, revision=self.args.revision, repo_type=self.repo_type, ) except RepositoryNotFoundError: print(f"{self.repo_type.capitalize()} {ANSI.bold(self.repo_id)} not found.") exit(1) except RevisionNotFoundError: print(f"Revision {ANSI.bold(self.args.revision)} not found.") exit(1) except HfHubHTTPError as e: if e.response.status_code == 409: print(f"Tag {ANSI.bold(self.args.tag)} already exists on {ANSI.bold(self.repo_id)}") exit(1) raise e print(f"Tag {ANSI.bold(self.args.tag)} created on {ANSI.bold(self.repo_id)}")
class_definition
3,704
4,740
0
/Users/nielsrogge/Documents/python_projecten/huggingface_hub/src/huggingface_hub/commands/tag.py
null
301
class TagListCommand(TagCommand): def run(self): try: refs = self.api.list_repo_refs( repo_id=self.repo_id, repo_type=self.repo_type, ) except RepositoryNotFoundError: print(f"{self.repo_type.capitalize()} {ANSI.bold(self.repo_id)} not found.") exit(1) except HTTPError as e: print(e) print(ANSI.red(e.response.text)) exit(1) if len(refs.tags) == 0: print("No tags found") exit(0) print(f"Tags for {self.repo_type} {ANSI.bold(self.repo_id)}:") for tag in refs.tags: print(tag.name)
class_definition
4,743
5,428
0
/Users/nielsrogge/Documents/python_projecten/huggingface_hub/src/huggingface_hub/commands/tag.py
null
302
class TagDeleteCommand(TagCommand): def run(self): print(f"You are about to delete tag {ANSI.bold(self.args.tag)} on {self.repo_type} {ANSI.bold(self.repo_id)}") if not self.args.yes: choice = input("Proceed? [Y/n] ").lower() if choice not in ("", "y", "yes"): print("Abort") exit() try: self.api.delete_tag(repo_id=self.repo_id, tag=self.args.tag, repo_type=self.repo_type) except RepositoryNotFoundError: print(f"{self.repo_type.capitalize()} {ANSI.bold(self.repo_id)} not found.") exit(1) except RevisionNotFoundError: print(f"Tag {ANSI.bold(self.args.tag)} not found on {ANSI.bold(self.repo_id)}") exit(1) print(f"Tag {ANSI.bold(self.args.tag)} deleted on {ANSI.bold(self.repo_id)}")
class_definition
5,431
6,287
0
/Users/nielsrogge/Documents/python_projecten/huggingface_hub/src/huggingface_hub/commands/tag.py
null
303
class DeleteFilesSubCommand: def __init__(self, args) -> None: self.args = args self.repo_id: str = args.repo_id self.repo_type: Optional[str] = args.repo_type self.revision: Optional[str] = args.revision self.api: HfApi = HfApi(token=args.token, library_name="huggingface-cli") self.patterns: List[str] = args.patterns self.commit_message: Optional[str] = args.commit_message self.commit_description: Optional[str] = args.commit_description self.create_pr: bool = args.create_pr self.token: Optional[str] = args.token def run(self) -> None: logging.set_verbosity_info() url = self.api.delete_files( delete_patterns=self.patterns, repo_id=self.repo_id, repo_type=self.repo_type, revision=self.revision, commit_message=self.commit_message, commit_description=self.commit_description, create_pr=self.create_pr, ) print(f"Files correctly deleted from repo. Commit: {url}.") logging.set_verbosity_warning()
class_definition
1,559
2,674
0
/Users/nielsrogge/Documents/python_projecten/huggingface_hub/src/huggingface_hub/commands/repo_files.py
null
304
class RepoFilesCommand(BaseHuggingfaceCLICommand): @staticmethod def register_subcommand(parser: _SubParsersAction): repo_files_parser = parser.add_parser("repo-files", help="Manage files in a repo on the Hub") repo_files_parser.add_argument( "repo_id", type=str, help="The ID of the repo to manage (e.g. `username/repo-name`)." ) repo_files_subparsers = repo_files_parser.add_subparsers( help="Action to execute against the files.", required=True, ) delete_subparser = repo_files_subparsers.add_parser( "delete", help="Delete files from a repo on the Hub", ) delete_subparser.set_defaults(func=lambda args: DeleteFilesSubCommand(args)) delete_subparser.add_argument( "patterns", nargs="+", type=str, help="Glob patterns to match files to delete.", ) delete_subparser.add_argument( "--repo-type", choices=["model", "dataset", "space"], default="model", help="Type of the repo to upload to (e.g. `dataset`).", ) delete_subparser.add_argument( "--revision", type=str, help=( "An optional Git revision to push to. It can be a branch name " "or a PR reference. If revision does not" " exist and `--create-pr` is not set, a branch will be automatically created." ), ) delete_subparser.add_argument( "--commit-message", type=str, help="The summary / title / first line of the generated commit." ) delete_subparser.add_argument( "--commit-description", type=str, help="The description of the generated commit." ) delete_subparser.add_argument( "--create-pr", action="store_true", help="Whether to create a new Pull Request for these changes." ) repo_files_parser.add_argument( "--token", type=str, help="A User Access Token generated from https://huggingface.co/settings/tokens", ) repo_files_parser.set_defaults(func=RepoFilesCommand)
class_definition
2,677
4,922
0
/Users/nielsrogge/Documents/python_projecten/huggingface_hub/src/huggingface_hub/commands/repo_files.py
null
305