Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare for 0.17 #1540

Merged
merged 5 commits into from
Jul 5, 2023
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
12 changes: 6 additions & 6 deletions .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.11"]
python-version: ["3.8", "3.11"]
test_name:
[
"Repository only",
"Everything else",
"torch",
]
include:
- python-version: "3.11" # LFS not ran on 3.7
- python-version: "3.11" # LFS not ran on 3.8
test_name: "lfs"
- python-version: "3.7"
- python-version: "3.8"
test_name: "fastai" # fastai not supported on 3.11 -> test it on 3.10
- python-version: "3.10"
test_name: "fastai"
- python-version: "3.7"
- python-version: "3.8"
test_name: "tensorflow" # Tensorflow not supported on 3.11 -> test it on 3.10
- python-version: "3.10"
test_name: "tensorflow"
Expand Down Expand Up @@ -131,14 +131,14 @@ jobs:
build-windows:
# (almost) Duplicate config compared to `build-ubuntu` but running on Windows.
# Please make sure to keep it updated as well.
# Lighter version of the tests with only 1 test suite running on Python3.7.
# Lighter version of the tests with only 1 test suite running on Python3.8.
runs-on: windows-latest
env:
DISABLE_SYMLINKS_IN_WINDOWS_TESTS: 1
strategy:
fail-fast: false
matrix:
python-version: ["3.7"]
python-version: ["3.8"]

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion docs/source/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ rendered properly in your Markdown viewer.

Before you start, you will need to setup your environment by installing the appropriate packages.

`huggingface_hub` is tested on **Python 3.7+**.
`huggingface_hub` is tested on **Python 3.8+**.

## Install with pip

Expand Down
4 changes: 1 addition & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def get_version() -> str:
"tqdm>=4.42.1",
"pyyaml>=5.1",
"typing-extensions>=3.7.4.3", # to be able to import TypeAlias
"importlib_metadata;python_version<'3.8'",
"packaging>=20.9",
]

Expand Down Expand Up @@ -108,7 +107,7 @@ def get_version() -> str:
"console_scripts": ["huggingface-cli=huggingface_hub.commands.huggingface_cli:main"],
"fsspec.specs": "hf=huggingface_hub.HfFileSystem",
},
python_requires=">=3.7.0",
python_requires=">=3.8.0",
install_requires=install_requires,
classifiers=[
"Intended Audience :: Developers",
Expand All @@ -118,7 +117,6 @@ def get_version() -> str:
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
Expand Down
2 changes: 1 addition & 1 deletion src/huggingface_hub/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
from typing import TYPE_CHECKING


__version__ = "0.16.0.dev0"
__version__ = "0.17.0.dev0"

# Alphabetical order of definitions is ensured in tests
# WARNING: any comment added in this dictionary definition will be lost when
Expand Down
3 changes: 1 addition & 2 deletions src/huggingface_hub/_commit_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from dataclasses import dataclass, field
from itertools import groupby
from pathlib import Path, PurePosixPath
from typing import TYPE_CHECKING, Any, BinaryIO, Dict, Iterable, Iterator, List, Optional, Tuple, Union
from typing import TYPE_CHECKING, Any, BinaryIO, Dict, Iterable, Iterator, List, Literal, Optional, Tuple, Union

from tqdm.contrib.concurrent import thread_map

Expand All @@ -28,7 +28,6 @@
validate_hf_hub_args,
)
from .utils import tqdm as hf_tqdm
from .utils._typing import Literal


if TYPE_CHECKING:
Expand Down
3 changes: 1 addition & 2 deletions src/huggingface_hub/_snapshot_download.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
from pathlib import Path
from typing import Dict, List, Optional, Union
from typing import Dict, List, Literal, Optional, Union

from tqdm.auto import tqdm as base_tqdm
from tqdm.contrib.concurrent import thread_map
Expand All @@ -15,7 +15,6 @@
from .hf_api import HfApi
from .utils import filter_repo_objects, logging, validate_hf_hub_args
from .utils import tqdm as hf_tqdm
from .utils._typing import Literal


logger = logging.get_logger(__name__)
Expand Down
4 changes: 1 addition & 3 deletions src/huggingface_hub/_webhooks_payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Contains data structures to parse the webhooks payload."""
from typing import List, Optional
from typing import List, Literal, Optional

from pydantic import BaseModel

from .utils._typing import Literal


# This is an adaptation of the ReportV3 interface implemented in moon-landing. V0, V1 and V2 have been ignored as they
# are not in used anymore. To keep in sync when format is updated in
Expand Down
3 changes: 1 addition & 2 deletions src/huggingface_hub/community.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
"""
from dataclasses import dataclass
from datetime import datetime
from typing import List, Optional
from typing import List, Literal, Optional

from .constants import REPO_TYPE_MODEL
from .utils import parse_datetime
from .utils._typing import Literal


DiscussionStatus = Literal["open", "closed", "merged", "draft"]
Expand Down
4 changes: 2 additions & 2 deletions src/huggingface_hub/file_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from functools import partial
from hashlib import sha256
from pathlib import Path
from typing import Any, BinaryIO, Dict, Generator, Optional, Tuple, Union
from typing import Any, BinaryIO, Dict, Generator, Literal, Optional, Tuple, Union
from urllib.parse import quote, urlparse

import requests
Expand Down Expand Up @@ -64,7 +64,7 @@
)
from .utils._headers import _http_user_agent
from .utils._runtime import _PY_VERSION # noqa: F401 # for backward compatibility
from .utils._typing import HTTP_METHOD_T, Literal
from .utils._typing import HTTP_METHOD_T


logger = logging.get_logger(__name__)
Expand Down
19 changes: 17 additions & 2 deletions src/huggingface_hub/hf_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,22 @@
from functools import wraps
from itertools import islice
from pathlib import Path
from typing import Any, BinaryIO, Callable, Dict, Iterable, Iterator, List, Optional, Tuple, TypeVar, Union, overload
from typing import (
Any,
BinaryIO,
Callable,
Dict,
Iterable,
Iterator,
List,
Literal,
Optional,
Tuple,
TypedDict,
TypeVar,
Union,
overload,
)
from urllib.parse import quote

import requests
Expand Down Expand Up @@ -99,7 +114,7 @@
from .utils._deprecation import (
_deprecate_arguments,
)
from .utils._typing import CallableT, Literal, TypedDict
from .utils._typing import CallableT
from .utils.endpoint_helpers import (
AttributeDictionary,
DatasetFilter,
Expand Down
2 changes: 1 addition & 1 deletion src/huggingface_hub/inference/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
Dict,
Iterable,
List,
Literal,
Optional,
Union,
overload,
Expand Down Expand Up @@ -80,7 +81,6 @@
get_session,
hf_raise_for_status,
)
from huggingface_hub.utils._typing import Literal


if TYPE_CHECKING:
Expand Down
2 changes: 1 addition & 1 deletion src/huggingface_hub/inference/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
Generator,
Iterable,
List,
Literal,
Optional,
Set,
Union,
Expand All @@ -46,7 +47,6 @@
is_numpy_available,
is_pillow_available,
)
from ..utils._typing import Literal
from ._text_generation import (
TextGenerationStreamResponse,
)
Expand Down
2 changes: 1 addition & 1 deletion src/huggingface_hub/inference/_generated/_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
AsyncIterable,
Dict,
List,
Literal,
Optional,
Union,
overload,
Expand Down Expand Up @@ -61,7 +62,6 @@
from huggingface_hub.utils import (
build_hf_headers,
)
from huggingface_hub.utils._typing import Literal

from .._common import _async_yield_from, _import_aiohttp

Expand Down
4 changes: 1 addition & 3 deletions src/huggingface_hub/inference/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import TYPE_CHECKING, List

from ..utils._typing import TypedDict
from typing import TYPE_CHECKING, List, TypedDict


if TYPE_CHECKING:
Expand Down
18 changes: 9 additions & 9 deletions src/huggingface_hub/inference_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from .constants import INFERENCE_ENDPOINT
from .hf_api import HfApi
from .utils import build_hf_headers, get_session, is_pillow_available, logging, validate_hf_hub_args
from .utils._deprecation import _deprecate_method


logger = logging.get_logger(__name__)
Expand Down Expand Up @@ -90,15 +91,14 @@ class InferenceApi:
"""

@validate_hf_hub_args
# TODO: add deprecation starting from version v0.16.0 so that we can proactively adapt external scripts.
# @_deprecate_method(
# version="0.18.0",
# message=(
# "`InferenceApi` client is deprecated in favor of the more feature-complete `InferenceClient`. Check out"
# " this guide to learn how to convert your script to use it:"
# " https://huggingface.co/docs/huggingface_hub/guides/inference#legacy-inferenceapi-client."
# ),
# )
@_deprecate_method(
version="0.19.0",
message=(
"`InferenceApi` client is deprecated in favor of the more feature-complete `InferenceClient`. Check out"
" this guide to learn how to convert your script to use it:"
" https://huggingface.co/docs/huggingface_hub/guides/inference#legacy-inferenceapi-client."
),
)
def __init__(
self,
repo_id: str,
Expand Down
3 changes: 1 addition & 2 deletions src/huggingface_hub/lfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@
from math import ceil
from os.path import getsize
from pathlib import Path
from typing import TYPE_CHECKING, BinaryIO, Dict, Iterable, List, Optional, Tuple
from typing import TYPE_CHECKING, BinaryIO, Dict, Iterable, List, Optional, Tuple, TypedDict

from requests.auth import HTTPBasicAuth

from huggingface_hub.constants import ENDPOINT, HF_HUB_ENABLE_HF_TRANSFER, REPO_TYPES_URL_PREFIXES
from huggingface_hub.utils import get_session

from .utils import get_token_to_send, hf_raise_for_status, http_backoff, logging, validate_hf_hub_args
from .utils._typing import TypedDict
from .utils.sha import sha256, sha_fileobj


Expand Down
3 changes: 1 addition & 2 deletions src/huggingface_hub/repocard.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import re
from pathlib import Path
from typing import Any, Dict, Optional, Type, Union
from typing import Any, Dict, Literal, Optional, Type, Union

import requests
import yaml
Expand All @@ -21,7 +21,6 @@

from .constants import REPOCARD_NAME
from .utils import EntryNotFoundError, SoftTemporaryDirectory, validate_hf_hub_args
from .utils._typing import Literal
from .utils.logging import get_logger


Expand Down
3 changes: 1 addition & 2 deletions src/huggingface_hub/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import time
from contextlib import contextmanager
from pathlib import Path
from typing import Callable, Dict, Iterator, List, Optional, Tuple, Union
from typing import Callable, Dict, Iterator, List, Optional, Tuple, TypedDict, Union
from urllib.parse import urlparse

from huggingface_hub.constants import REPO_TYPES_URL_PREFIXES, REPOCARD_NAME
Expand All @@ -22,7 +22,6 @@
tqdm,
validate_hf_hub_args,
)
from .utils._typing import TypedDict


logger = logging.get_logger(__name__)
Expand Down
3 changes: 1 addition & 2 deletions src/huggingface_hub/utils/_cache_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@
from collections import defaultdict
from dataclasses import dataclass
from pathlib import Path
from typing import Dict, FrozenSet, List, Optional, Set, Union
from typing import Dict, FrozenSet, List, Literal, Optional, Set, Union

from ..constants import HUGGINGFACE_HUB_CACHE
from . import logging
from ._typing import Literal


logger = logging.get_logger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion src/huggingface_hub/utils/_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def backend_factory() -> requests.Session:
return _get_session_from_cache(thread_ident=threading.get_ident())


@lru_cache(maxsize=128) # default value for Python>=3.8. Let's keep the same for Python3.7
@lru_cache
def _get_session_from_cache(thread_ident: int) -> requests.Session:
"""
Create a new session per thread using global factory. Using LRU cache (maxsize 128) to avoid memory leaks when
Expand Down
13 changes: 3 additions & 10 deletions src/huggingface_hub/utils/_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Check presence of installed packages at runtime."""
import importlib.metadata
import platform
import sys
from typing import Any, Dict

import packaging.version

from .. import __version__, constants


_PY_VERSION: str = sys.version.split()[0].rstrip("+")

if packaging.version.Version(_PY_VERSION) < packaging.version.Version("3.8.0"):
import importlib_metadata # type: ignore
else:
import importlib.metadata as importlib_metadata # type: ignore


_package_versions = {}

_CANDIDATES = {
Expand Down Expand Up @@ -65,9 +58,9 @@
_package_versions[candidate_name] = "N/A"
for name in package_names:
try:
_package_versions[candidate_name] = importlib_metadata.version(name)
_package_versions[candidate_name] = importlib.metadata.version(name)
break
except importlib_metadata.PackageNotFoundError:
except importlib.metadata.PackageNotFoundError:
pass


Expand Down
Loading