in src/huggingface_hub/file_download.py [0:0]
def are_symlinks_supported(cache_dir: Union[str, Path, None] = None) -> bool:
"""Return whether the symlinks are supported on the machine.
Since symlinks support can change depending on the mounted disk, we need to check
on the precise cache folder. By default, the default HF cache directory is checked.
Args:
cache_dir (`str`, `Path`, *optional*):
Path to the folder where cached files are stored.
Returns: [bool] Whether symlinks are supported in the directory.
"""
# Defaults to HF cache
if cache_dir is None:
cache_dir = constants.HF_HUB_CACHE
cache_dir = str(Path(cache_dir).expanduser().resolve()) # make it unique
# Check symlink compatibility only once (per cache directory) at first time use
if cache_dir not in _are_symlinks_supported_in_dir:
_are_symlinks_supported_in_dir[cache_dir] = True
os.makedirs(cache_dir, exist_ok=True)
with SoftTemporaryDirectory(dir=cache_dir) as tmpdir:
src_path = Path(tmpdir) / "dummy_file_src"
src_path.touch()
dst_path = Path(tmpdir) / "dummy_file_dst"
# Relative source path as in `_create_symlink``
relative_src = os.path.relpath(src_path, start=os.path.dirname(dst_path))
try:
os.symlink(relative_src, dst_path)
except OSError:
# Likely running on Windows
_are_symlinks_supported_in_dir[cache_dir] = False
if not constants.HF_HUB_DISABLE_SYMLINKS_WARNING:
message = (
"`huggingface_hub` cache-system uses symlinks by default to"
" efficiently store duplicated files but your machine does not"
f" support them in {cache_dir}. Caching files will still work"
" but in a degraded version that might require more space on"
" your disk. This warning can be disabled by setting the"
" `HF_HUB_DISABLE_SYMLINKS_WARNING` environment variable. For"
" more details, see"
" https://huggingface.co/docs/huggingface_hub/how-to-cache#limitations."
)
if os.name == "nt":
message += (
"\nTo support symlinks on Windows, you either need to"
" activate Developer Mode or to run Python as an"
" administrator. In order to activate developer mode,"
" see this article:"
" https://docs.microsoft.com/en-us/windows/apps/get-started/enable-your-device-for-development"
)
warnings.warn(message)
return _are_symlinks_supported_in_dir[cache_dir]