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
6 changes: 3 additions & 3 deletions src/huggingface_hub/_commit_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from tqdm.contrib.concurrent import thread_map

from .constants import ENDPOINT, HF_HUB_ENABLE_HF_TRANSFER
from . import constants
from .errors import EntryNotFoundError
from .file_download import hf_hub_url
from .lfs import UploadInfo, lfs_upload, post_lfs_batch_info
Expand Down Expand Up @@ -432,7 +432,7 @@ def _wrapped_lfs_upload(batch_action) -> None:
except Exception as exc:
raise RuntimeError(f"Error while uploading '{operation.path_in_repo}' to the Hub.") from exc

if HF_HUB_ENABLE_HF_TRANSFER:
if constants.HF_HUB_ENABLE_HF_TRANSFER:
logger.debug(f"Uploading {len(filtered_actions)} LFS files to the Hub using `hf_transfer`.")
for action in hf_tqdm(filtered_actions, name="huggingface_hub.lfs_upload"):
_wrapped_lfs_upload(action)
Expand Down Expand Up @@ -506,7 +506,7 @@ def _fetch_upload_modes(
[`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
If the Hub API response is improperly formatted.
"""
endpoint = endpoint if endpoint is not None else ENDPOINT
endpoint = endpoint if endpoint is not None else constants.ENDPOINT

# Fetch upload mode (LFS or regular) chunk by chunk.
upload_modes: Dict[str, UploadMode] = {}
Expand Down
20 changes: 7 additions & 13 deletions src/huggingface_hub/_snapshot_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@
from tqdm.auto import tqdm as base_tqdm
from tqdm.contrib.concurrent import thread_map

from .constants import (
DEFAULT_ETAG_TIMEOUT,
DEFAULT_REVISION,
HF_HUB_CACHE,
HF_HUB_ENABLE_HF_TRANSFER,
REPO_TYPES,
)
from . import constants
from .errors import GatedRepoError, LocalEntryNotFoundError, RepositoryNotFoundError, RevisionNotFoundError
from .file_download import REGEX_COMMIT_HASH, hf_hub_download, repo_folder_name
from .hf_api import DatasetInfo, HfApi, ModelInfo, SpaceInfo
Expand Down Expand Up @@ -40,7 +34,7 @@ def snapshot_download(
library_version: Optional[str] = None,
user_agent: Optional[Union[Dict, str]] = None,
proxies: Optional[Dict] = None,
etag_timeout: float = DEFAULT_ETAG_TIMEOUT,
etag_timeout: float = constants.DEFAULT_ETAG_TIMEOUT,
force_download: bool = False,
token: Optional[Union[bool, str]] = None,
local_files_only: bool = False,
Expand Down Expand Up @@ -137,16 +131,16 @@ def snapshot_download(
if some parameter value is invalid.
"""
if cache_dir is None:
cache_dir = HF_HUB_CACHE
cache_dir = constants.HF_HUB_CACHE
if revision is None:
revision = DEFAULT_REVISION
revision = constants.DEFAULT_REVISION
if isinstance(cache_dir, Path):
cache_dir = str(cache_dir)

if repo_type is None:
repo_type = "model"
if repo_type not in REPO_TYPES:
raise ValueError(f"Invalid repo type: {repo_type}. Accepted repo types are: {str(REPO_TYPES)}")
if repo_type not in constants.REPO_TYPES:
raise ValueError(f"Invalid repo type: {repo_type}. Accepted repo types are: {str(constants.REPO_TYPES)}")

storage_folder = os.path.join(cache_dir, repo_folder_name(repo_id=repo_id, repo_type=repo_type))

Expand Down Expand Up @@ -287,7 +281,7 @@ def _inner_hf_hub_download(repo_file: str):
headers=headers,
)

if HF_HUB_ENABLE_HF_TRANSFER:
if constants.HF_HUB_ENABLE_HF_TRANSFER:
# when using hf_transfer we don't want extra parallelism
# from the one hf_transfer provides
for file in filtered_repo_files:
Expand Down
4 changes: 2 additions & 2 deletions src/huggingface_hub/community.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from datetime import datetime
from typing import List, Literal, Optional, Union

from .constants import REPO_TYPE_MODEL
from . import constants
from .utils import parse_datetime


Expand Down Expand Up @@ -79,7 +79,7 @@ def git_reference(self) -> Optional[str]:
@property
def url(self) -> str:
"""Returns the URL of the discussion on the Hub."""
if self.repo_type is None or self.repo_type == REPO_TYPE_MODEL:
if self.repo_type is None or self.repo_type == constants.REPO_TYPE_MODEL:
return f"{self.endpoint}/{self.repo_id}/discussions/{self.num}"
return f"{self.endpoint}/{self.repo_type}s/{self.repo_id}/discussions/{self.num}"

Expand Down
5 changes: 2 additions & 3 deletions src/huggingface_hub/fastai_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

from packaging import version

from huggingface_hub import snapshot_download
from huggingface_hub.constants import CONFIG_NAME
from huggingface_hub import constants, snapshot_download
from huggingface_hub.hf_api import HfApi
from huggingface_hub.utils import (
SoftTemporaryDirectory,
Expand Down Expand Up @@ -272,7 +271,7 @@ def _save_pretrained_fastai(
if config is not None:
if not isinstance(config, dict):
raise RuntimeError(f"Provided config should be a dict. Got: '{type(config)}'")
path = os.path.join(save_directory, CONFIG_NAME)
path = os.path.join(save_directory, constants.CONFIG_NAME)
with open(path, "w") as f:
json.dump(config, f)

Expand Down
Loading