Skip to content

Commit

Permalink
Add file_hash back to pooch.utils with a warning (#257)
Browse files Browse the repository at this point in the history
Moving this function to pooch.hashes caused crashes downstream. To
prevent these crashes, add a wrapper back to utils that issues a warning
to import from the top-level namespace instead.
  • Loading branch information
leouieda authored Aug 24, 2021
1 parent b9c3c44 commit be3f32d
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions pooch/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from pathlib import Path
from urllib.parse import urlsplit
from contextlib import contextmanager
import warnings

import appdirs
from packaging.version import Version
Expand All @@ -23,6 +24,36 @@
LOGGER.addHandler(logging.StreamHandler())


def file_hash(*args, **kwargs):
"""
WARNING: Importing this function from pooch.utils is DEPRECATED.
Please import from the top-level namespace (`from pooch import file_hash`)
instead, which is fully backwards compatible with pooch >= 0.1.
Examples
--------
>>> fname = "test-file-for-hash.txt"
>>> with open(fname, "w") as f:
... __ = f.write("content of the file")
>>> print(file_hash(fname))
0fc74468e6a9a829f103d069aeb2bb4f8646bad58bf146bb0e3379b759ec4a00
>>> import os
>>> os.remove(fname)
"""
# pylint: disable=import-outside-toplevel
from .hashes import file_hash as new_file_hash

message = """
Importing file_hash from pooch.utils is DEPRECATED. Please import from the
top-level namespace (`from pooch import file_hash`) instead, which is fully
backwards compatible with pooch >= 0.1.
"""
warnings.warn(message, DeprecationWarning)
return new_file_hash(*args, **kwargs)


def get_logger():
r"""
Get the default event logger.
Expand Down

0 comments on commit be3f32d

Please sign in to comment.