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

MNT deprecate imports from snapshot_download #880

Merged
merged 3 commits into from
Jun 6, 2022
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
20 changes: 11 additions & 9 deletions src/huggingface_hub/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,18 @@ def __getattr__(name):
if name in submodules:
return importlib.import_module(f"{package_name}.{name}")
elif name in attr_to_modules:
submod = importlib.import_module(f"{package_name}.{attr_to_modules[name]}")
submod_path = f"{package_name}.{attr_to_modules[name]}"
submod = importlib.import_module(submod_path)
attr = getattr(submod, name)

# If the attribute lives in a file (module) with the same
# name as the attribute, ensure that the attribute and *not*
# the module is accessible on the package.
if name == attr_to_modules[name]:
warnings.warn(
_LazyImportWarning(
"Module attribute and module have same "
f"name: `{name}`; will likely cause conflicts "
"when accessing attribute."
)
)
return getattr(submod, name)
pkg = sys.modules[package_name]
pkg.__dict__[name] = attr

return attr
else:
raise AttributeError(f"No {package_name} attribute {name}")

Expand Down
14 changes: 14 additions & 0 deletions src/huggingface_hub/snapshot_download.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# TODO: remove in 0.11

import warnings


warnings.warn(
"snapshot_download.py has been made private and will no longer be available from"
" version 0.11. Please use `from huggingface_hub import snapshot_download` to"
" import the only public function in this module. Other members of the file may be"
" changed without a deprecation notice.",
FutureWarning,
)

from ._snapshot_download import * # noqa
9 changes: 9 additions & 0 deletions tests/test_snapshot_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import time
import unittest

import pytest

import requests
from huggingface_hub import HfApi, Repository, snapshot_download
from huggingface_hub.hf_api import HfFolder
Expand Down Expand Up @@ -357,3 +359,10 @@ def test_download_model_with_ignore_regex(self):

def test_download_model_with_ignore_regex_list(self):
self.check_download_model_with_regex(["*.git*", "*.pt"], allow=False)


def test_snapshot_download_import():
with pytest.warns(FutureWarning, match="has been made private"):
from huggingface_hub.snapshot_download import snapshot_download as x # noqa

assert x is snapshot_download