Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/source/en/package_reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -2927,8 +2927,8 @@ $ hf repos create [OPTIONS] REPO_ID
* `--token TEXT`: A User Access Token generated from https://huggingface.co/settings/tokens.
* `--exist-ok / --no-exist-ok`: Do not raise an error if repo already exists. [default: no-exist-ok]
* `--resource-group-id TEXT`: Resource group in which to create the repo. Resource groups is only available for Enterprise Hub organizations.
* `--flavor TEXT`: Space hardware flavor (e.g. 'cpu-basic', 't4-medium', 'l4x4'). Only for Spaces.
* `--storage TEXT`: Space persistent storage tier ('small', 'medium', or 'large'). Only for Spaces.
* `--flavor [cpu-basic|cpu-upgrade|cpu-performance|cpu-xl|sprx8|zero-a10g|t4-small|t4-medium|l4x1|l4x4|l40sx1|l40sx4|l40sx8|a10g-small|a10g-large|a10g-largex2|a10g-largex4|a100-large|a100x4|a100x8|h200|h200x2|h200x4|h200x8|inf2x6]`: Space hardware flavor (e.g. 'cpu-basic', 't4-medium', 'l4x4'). Only for Spaces.
* `--storage [small|medium|large]`: Space persistent storage tier ('small', 'medium', or 'large'). Only for Spaces.
* `--sleep-time INTEGER`: Seconds of inactivity before the Space is put to sleep. Use -1 to disable. Only for Spaces.
* `-s, --secrets TEXT`: Set secret environment variables. E.g. --secrets SECRET=value or `--secrets HF_TOKEN` to pass your Hugging Face token.
* `--secrets-file TEXT`: Read in a file of secret environment variables.
Expand Down Expand Up @@ -3033,8 +3033,8 @@ $ hf repos duplicate [OPTIONS] FROM_ID [TO_ID]
* `--protected`: Whether to make the Space protected (Spaces only). Ignored if the repo already exists.
* `--token TEXT`: A User Access Token generated from https://huggingface.co/settings/tokens.
* `--exist-ok / --no-exist-ok`: Do not raise an error if repo already exists. [default: no-exist-ok]
* `--flavor TEXT`: Space hardware flavor (e.g. 'cpu-basic', 't4-medium', 'l4x4'). Only for Spaces.
* `--storage TEXT`: Space persistent storage tier ('small', 'medium', or 'large'). Only for Spaces.
* `--flavor [cpu-basic|cpu-upgrade|cpu-performance|cpu-xl|sprx8|zero-a10g|t4-small|t4-medium|l4x1|l4x4|l40sx1|l40sx4|l40sx8|a10g-small|a10g-large|a10g-largex2|a10g-largex4|a100-large|a100x4|a100x8|h200|h200x2|h200x4|h200x8|inf2x6]`: Space hardware flavor (e.g. 'cpu-basic', 't4-medium', 'l4x4'). Only for Spaces.
* `--storage [small|medium|large]`: Space persistent storage tier ('small', 'medium', or 'large'). Only for Spaces.
* `--sleep-time INTEGER`: Seconds of inactivity before the Space is put to sleep. Use -1 to disable. Only for Spaces.
* `-s, --secrets TEXT`: Set secret environment variables. E.g. --secrets SECRET=value or `--secrets HF_TOKEN` to pass your Hugging Face token.
* `--secrets-file TEXT`: Read in a file of secret environment variables.
Expand Down
4 changes: 2 additions & 2 deletions src/huggingface_hub/_inference_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def client(self) -> "InferenceClient":

return InferenceClient(
model=self.url,
token=self._token, # type: ignore[arg-type] # boolean token shouldn't be possible. In practice it's ok.
token=self._token, # type: ignore # boolean token shouldn't be possible. In practice it's ok.
)

@property
Expand All @@ -183,7 +183,7 @@ def async_client(self) -> "AsyncInferenceClient":

return AsyncInferenceClient(
model=self.url,
token=self._token, # type: ignore[arg-type] # boolean token shouldn't be possible. In practice it's ok.
token=self._token, # type: ignore # boolean token shouldn't be possible. In practice it's ok.
)

def wait(self, timeout: Optional[int] = None, refresh_every: int = 5) -> "InferenceEndpoint":
Expand Down
2 changes: 1 addition & 1 deletion src/huggingface_hub/_oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def greet_json(request: Request):
) from e
session_secret = (constants.OAUTH_CLIENT_SECRET or "") + "-v1"
app.add_middleware(
SessionMiddleware, # type: ignore[arg-type]
SessionMiddleware, # type: ignore
secret_key=hashlib.sha256(session_secret.encode()).hexdigest(),
same_site="none",
https_only=True,
Expand Down
2 changes: 1 addition & 1 deletion src/huggingface_hub/_upload_large_folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ def _build_hacky_operation(item: JOB_ITEM_T) -> HackyCommitOperationAdd:
if metadata.sha256 is None:
raise ValueError("sha256 must have been computed by now!")
operation.upload_info = UploadInfo(sha256=bytes.fromhex(metadata.sha256), size=metadata.size, sample=sample)
operation._upload_mode = metadata.upload_mode # type: ignore[assignment]
operation._upload_mode = metadata.upload_mode # type: ignore
operation._should_ignore = metadata.should_ignore
operation._remote_oid = metadata.remote_oid
return operation
Expand Down
24 changes: 12 additions & 12 deletions src/huggingface_hub/cli/_cli_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@
import time
from enum import Enum
from pathlib import Path
from typing import TYPE_CHECKING, Annotated, Any, Callable, Literal, Optional, Sequence, Union, cast
from typing import TYPE_CHECKING, Annotated, Any, Callable, Literal, Optional, Sequence, TypeVar, Union, cast

import click
import typer
from typer.core import TyperCommand, TyperGroup

from huggingface_hub import __version__, constants
from huggingface_hub.utils import ANSI, get_session, hf_raise_for_status, installation_method, logging, tabulate
Expand Down Expand Up @@ -77,6 +78,7 @@ def generate_epilog(examples: list[str], docs_anchor: Optional[str] = None) -> s

TOPIC_T = Union[Literal["main", "help"], str]
FallbackHandlerT = Callable[[list[str], set[str]], Optional[int]]
ExpandPropertyT = TypeVar("ExpandPropertyT", bound=str)


def _format_epilog_no_indent(epilog: Optional[str], ctx: click.Context, formatter: click.HelpFormatter) -> None:
Expand All @@ -90,7 +92,7 @@ def _format_epilog_no_indent(epilog: Optional[str], ctx: click.Context, formatte
_ALIAS_SPLIT = re.compile(r"\s*\|\s*")


class HFCliTyperGroup(typer.core.TyperGroup):
class HFCliTyperGroup(TyperGroup):
"""
Typer Group that:
- lists commands alphabetically within sections.
Expand Down Expand Up @@ -223,7 +225,7 @@ def _rewrite_repo_type_prefix(cmd: click.Command, args: list[str]) -> None:
# Apply all rewrites and append --type once.
for arg_index, new_value in rewrites:
args[arg_index] = new_value
args.extend(["--type", inferred_type]) # type: ignore[list-item]
args.extend(["--type", inferred_type]) # type: ignore

def get_command(self, ctx: click.Context, cmd_name: str) -> Optional[click.Command]:
# Try exact match first
Expand Down Expand Up @@ -321,21 +323,21 @@ def format_commands(self, ctx: click.Context, formatter: click.HelpFormatter) ->
return FallbackTyperGroup


def HFCliCommand(topic: TOPIC_T, examples: Optional[list[str]] = None) -> type[typer.core.TyperCommand]:
def HFCliCommand(topic: TOPIC_T, examples: Optional[list[str]] = None) -> type[TyperCommand]:
def format_epilog(self: click.Command, ctx: click.Context, formatter: click.HelpFormatter) -> None:
_format_epilog_no_indent(self.epilog, ctx, formatter)

return type(
f"TyperCommand{topic.capitalize()}",
(typer.core.TyperCommand,),
(TyperCommand,),
{"topic": topic, "examples": examples or [], "format_epilog": format_epilog},
)


class HFCliApp(typer.Typer):
"""Custom Typer app for Hugging Face CLI."""

def command( # type: ignore[override]
def command( # type: ignore
self,
name: Optional[str] = None,
*,
Expand Down Expand Up @@ -375,9 +377,7 @@ def _inner(func: Callable[..., Any]) -> Callable[..., Any]:
return _inner


def typer_factory(
help: str, epilog: Optional[str] = None, cls: Optional[type[typer.core.TyperGroup]] = None
) -> "HFCliApp":
def typer_factory(help: str, epilog: Optional[str] = None, cls: Optional[type[TyperGroup]] = None) -> "HFCliApp":
"""Create a Typer app with consistent settings.

Args:
Expand Down Expand Up @@ -687,10 +687,10 @@ def api_object_to_dict(info: Any) -> dict[str, Any]:
return {k: _serialize_value(v) for k, v in dataclasses.asdict(info).items() if v is not None}


def make_expand_properties_parser(valid_properties: list[str]):
def make_expand_properties_parser(valid_properties: Sequence[ExpandPropertyT]):
"""Create a callback to parse and validate comma-separated expand properties."""

def _parse_expand_properties(value: Optional[str]) -> Optional[list[str]]:
def _parse_expand_properties(value: Optional[str]) -> Optional[list[ExpandPropertyT]]:
if value is None:
return None
properties = [p.strip() for p in value.split(",")]
Expand All @@ -699,7 +699,7 @@ def _parse_expand_properties(value: Optional[str]) -> Optional[list[str]]:
raise typer.BadParameter(
f"Invalid expand property: '{prop}'. Valid values are: {', '.join(valid_properties)}"
)
return properties
return [cast(ExpandPropertyT, prop) for prop in properties]

return _parse_expand_properties

Expand Down
9 changes: 4 additions & 5 deletions src/huggingface_hub/cli/buckets.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ def list_cmd(

if is_file_mode:
_list_files(
argument=argument, # type: ignore[arg-type]
argument=argument, # type: ignore
human_readable=human_readable,
as_tree=as_tree,
recursive=recursive,
Expand Down Expand Up @@ -960,8 +960,7 @@ def cp(
raise typer.BadParameter("Stdin upload requires a bucket destination.")

if src_is_stdin and dst_is_bucket:
assert dst is not None
_, prefix = _parse_bucket_path(dst)
_, prefix = _parse_bucket_path(dst) # type: ignore
if prefix == "" or prefix.endswith("/"):
raise typer.BadParameter("Stdin upload requires a full destination path including filename.")

Expand Down Expand Up @@ -1022,7 +1021,7 @@ def cp(

elif src_is_stdin:
# Upload from stdin
bucket_id, remote_path = _parse_bucket_path(dst) # type: ignore[arg-type]
bucket_id, remote_path = _parse_bucket_path(dst) # type: ignore
data = sys.stdin.buffer.read()

if quiet:
Expand All @@ -1041,7 +1040,7 @@ def cp(
if not os.path.isfile(src):
raise typer.BadParameter(f"Source file not found: {src}")

bucket_id, prefix = _parse_bucket_path(dst) # type: ignore[arg-type]
bucket_id, prefix = _parse_bucket_path(dst) # type: ignore

if prefix == "":
remote_path = os.path.basename(src)
Expand Down
6 changes: 3 additions & 3 deletions src/huggingface_hub/cli/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from collections import defaultdict
from dataclasses import dataclass
from enum import Enum
from typing import Annotated, Any, Callable, Dict, List, Mapping, Optional, Tuple
from typing import Annotated, Any, Callable, Dict, List, Mapping, Optional, Tuple, Union

import typer

Expand Down Expand Up @@ -280,7 +280,7 @@ def print_cache_entries_table(
message = "No cached revisions found." if include_revisions else "No cached repositories found."
print(message)
return
table_rows: List[List[str]]
table_rows: List[List[Union[str, int]]]
if include_revisions:
headers = ["ID", "REVISION", "SIZE", "LAST_MODIFIED", "REFS"]
table_rows = [
Expand All @@ -307,7 +307,7 @@ def print_cache_entries_table(
for repo, _ in entries
]

print(tabulate(table_rows, headers=headers)) # type: ignore[arg-type]
print(tabulate(table_rows, headers=headers))

unique_repos = {repo for repo, _ in entries}
repo_count = len(unique_repos)
Expand Down
4 changes: 2 additions & 2 deletions src/huggingface_hub/cli/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def datasets_ls(
search=search,
sort=sort_key,
limit=limit,
expand=expand, # type: ignore[arg-type]
expand=expand, # type: ignore
)
]
print_list_output(results, format=format, quiet=quiet)
Expand All @@ -124,7 +124,7 @@ def datasets_info(
"""Get info about a dataset on the Hub. Output is in JSON format."""
api = get_hf_api(token=token)
try:
info = api.dataset_info(repo_id=dataset_id, revision=revision, expand=expand) # type: ignore[arg-type]
info = api.dataset_info(repo_id=dataset_id, revision=revision, expand=expand) # type: ignore
except RepositoryNotFoundError as e:
raise CLIError(f"Dataset '{dataset_id}' not found.") from e
except RevisionNotFoundError as e:
Expand Down
4 changes: 2 additions & 2 deletions src/huggingface_hub/cli/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ def row_fn(item: dict[str, Any]) -> list[str]:

# Custom template format
if format and format not in ("table", "json"):
_print_output([row_fn(item) for item in items], headers, aliases, format) # type: ignore[arg-type,misc]
_print_output([row_fn(item) for item in items], headers, aliases, format) # type: ignore
else:
output_format = OutputFormat.json if format == "json" else OutputFormat.table
print_list_output(
Expand Down Expand Up @@ -941,7 +941,7 @@ def row_fn(item: dict[str, Any]) -> list[str]:

# Custom template format (e.g. --format '{{.id}} {{.schedule}}')
if format and format not in ("table", "json"):
_print_output([row_fn(item) for item in items], headers, aliases, format) # type: ignore[arg-type,misc]
_print_output([row_fn(item) for item in items], headers, aliases, format) # type: ignore
else:
output_format = OutputFormat.json if format == "json" else OutputFormat.table
print_list_output(
Expand Down
4 changes: 2 additions & 2 deletions src/huggingface_hub/cli/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def models_ls(
num_parameters=num_parameters,
sort=sort_key,
limit=limit,
expand=expand, # type: ignore[arg-type]
expand=expand, # type: ignore
)
]
print_list_output(results, format=format, quiet=quiet)
Expand All @@ -128,7 +128,7 @@ def models_info(
"""Get info about a model on the Hub. Output is in JSON format."""
api = get_hf_api(token=token)
try:
info = api.model_info(repo_id=model_id, revision=revision, expand=expand) # type: ignore[arg-type]
info = api.model_info(repo_id=model_id, revision=revision, expand=expand) # type: ignore
except RepositoryNotFoundError as e:
raise CLIError(f"Model '{model_id}' not found.") from e
except RevisionNotFoundError as e:
Expand Down
15 changes: 8 additions & 7 deletions src/huggingface_hub/cli/repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import typer

from huggingface_hub import SpaceHardware, SpaceStorage
from huggingface_hub.errors import CLIError, HfHubHTTPError, RepositoryNotFoundError, RevisionNotFoundError
from huggingface_hub.utils import ANSI

Expand Down Expand Up @@ -91,15 +92,15 @@ class GatedChoices(str, enum.Enum):
),
]
SpaceHardwareOpt = Annotated[
Optional[str],
Optional[SpaceHardware],
typer.Option(
"--flavor",
help="Space hardware flavor (e.g. 'cpu-basic', 't4-medium', 'l4x4'). Only for Spaces.",
),
]

SpaceStorageOpt = Annotated[
Optional[str],
Optional[SpaceStorage],
typer.Option(
"--storage",
help="Space persistent storage tier ('small', 'medium', or 'large'). Only for Spaces.",
Expand Down Expand Up @@ -166,8 +167,8 @@ def repo_create(
exist_ok=exist_ok,
resource_group_id=resource_group_id,
space_sdk=space_sdk,
space_hardware=hardware, # type: ignore[arg-type]
space_storage=storage, # type: ignore[arg-type]
space_hardware=hardware,
space_storage=storage,
space_sleep_time=sleep_time,
space_secrets=env_map_to_key_value_list(parse_env_map(secrets, secrets_file)),
space_variables=env_map_to_key_value_list(parse_env_map(env, env_file)),
Expand Down Expand Up @@ -219,8 +220,8 @@ def repo_duplicate(
visibility="private" if private else "public" if public else "protected" if protected else None, # type: ignore [arg-type]
token=token,
exist_ok=exist_ok,
space_hardware=hardware, # type: ignore[arg-type]
space_storage=storage, # type: ignore[arg-type]
space_hardware=hardware,
space_storage=storage,
space_sleep_time=sleep_time,
space_secrets=env_map_to_key_value_list(parse_env_map(secrets, secrets_file)),
space_variables=env_map_to_key_value_list(parse_env_map(env, env_file)),
Expand Down Expand Up @@ -294,7 +295,7 @@ def repo_settings(
api = get_hf_api(token=token)
api.update_repo_settings(
repo_id=repo_id,
gated=(gated.value if gated else None), # type: ignore [arg-type]
gated=(None if gated is None else False if gated is GatedChoices.false else gated.value),
visibility="private" if private else "public" if public else "protected" if protected else None, # type: ignore [arg-type]
repo_type=repo_type.value,
)
Expand Down
2 changes: 1 addition & 1 deletion src/huggingface_hub/cli/webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def _parse_watch(values: list[str]) -> list[WebhookWatchedItem]:
kind, name = v.split(":", 1)
if kind not in valid_types:
raise typer.BadParameter(f"Invalid type '{kind}'. Valid types: {', '.join(valid_types)}.")
items.append(WebhookWatchedItem(type=kind, name=name)) # type: ignore[arg-type]
items.append(WebhookWatchedItem(type=kind, name=name)) # type: ignore
return items


Expand Down
8 changes: 4 additions & 4 deletions src/huggingface_hub/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def __strict_setattr__(self: Any, name: str, value: Any) -> None:
# If validation passed, set the attribute
original_setattr(self, name, value)

cls.__setattr__ = __strict_setattr__ # type: ignore[method-assign]
cls.__setattr__ = __strict_setattr__ # type: ignore

if accept_kwargs:
# (optional) Override __init__ to accept arbitrary keyword arguments
Expand Down Expand Up @@ -193,7 +193,7 @@ def __init__(self, *args, **kwargs: Any) -> None:

self.__post_init__(**additional_kwargs)

cls.__init__ = __init__ # type: ignore[method-assign]
cls.__init__ = __init__ # type: ignore

# Define a default __post_init__ if not defined
if not hasattr(cls, "__post_init__"):
Expand Down Expand Up @@ -226,7 +226,7 @@ def __repr__(self) -> str:
return f"{standard_repr[:-1]}, {additional_repr})" if additional_kwargs else standard_repr

if cls.__dataclass_params__.repr is True: # type: ignore [attr-defined]
cls.__repr__ = __repr__ # type: ignore [method-assign]
cls.__repr__ = __repr__ # type: ignore

# List all public methods starting with `validate_` => class validators.
class_validators = []
Expand All @@ -245,7 +245,7 @@ def __repr__(self) -> str:
)
class_validators.append(method)

cls.__class_validators__ = class_validators # type: ignore [attr-defined]
cls.__class_validators__ = class_validators # type: ignore

# Add `validate` method to the class, but first check if it already exists
def validate(self: T) -> None:
Expand Down
2 changes: 1 addition & 1 deletion src/huggingface_hub/file_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -1738,7 +1738,7 @@ def _get_metadata_or_catch_error(
if not (local_files_only or etag is not None or head_error_call is not None):
raise RuntimeError("etag is empty due to uncovered problems")

return (url_to_download, etag, commit_hash, expected_size, xet_file_data, head_error_call) # type: ignore [return-value]
return (url_to_download, etag, commit_hash, expected_size, xet_file_data, head_error_call) # type: ignore


def _raise_on_head_call_error(head_call_error: Exception, force_download: bool, local_files_only: bool) -> NoReturn:
Expand Down
Loading
Loading