From 19f19184fea43021ef1b6c6081e56c2778b38966 Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Tue, 19 Nov 2024 22:20:40 +0100 Subject: [PATCH] Support huggingface-cli older than 0.25.0, like on Fedora 40 and 41 Currently, on Fedora 40 and 41, pulling a model from Hugging Face fails with: $ ramalama pull huggingface://afrideva/Tiny-Vicuna-1B-GGUF/tiny-vicuna-1b.q2_k.gguf usage: huggingface-cli [] huggingface-cli: error: argument {env,login,whoami,logout,repo,upload, download,lfs-enable-largefiles,lfs-multipart-upload,scan-cache, delete-cache,tag}: invalid choice: 'version' (choose from 'env', 'login', 'whoami', 'logout', 'repo', 'upload', 'download', 'lfs-enable-largefiles', 'lfs-multipart-upload', 'scan-cache', 'delete-cache', 'tag') Error: Command '['huggingface-cli', 'version']' returned non-zero exit status 2. This is because the 'huggingface-cli version' command is a recent addition in version 0.25.0 [1], and it's not present in any stable Fedora release [2]. Therefore, it might be worth using a slightly different signature to detect the presence of huggingface-cli - one that isn't bound to a huggingface-cli version and is used elsewhere in the code. [1] huggingface_hub commit ebac1b2a1aa4a9f4 https://github.com/huggingface/huggingface_hub/commit/ebac1b2a1aa4a9f4 https://github.com/huggingface/huggingface_hub/issues/2441 [2] https://src.fedoraproject.org/rpms/python-huggingface-hub Fixes: 5749154b1e21b802 ("Replace huggingface-cli with a simple ...") Signed-off-by: Debarshi Ray --- ramalama/huggingface.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/ramalama/huggingface.py b/ramalama/huggingface.py index 50318c97..5ca1b1b1 100644 --- a/ramalama/huggingface.py +++ b/ramalama/huggingface.py @@ -1,6 +1,6 @@ import os import urllib.request -from ramalama.common import run_cmd, exec_cmd, download_file, verify_checksum +from ramalama.common import available, run_cmd, exec_cmd, download_file, verify_checksum from ramalama.model import Model missing_huggingface = """ @@ -13,10 +13,9 @@ def is_huggingface_cli_available(): """Check if huggingface-cli is available on the system.""" - try: - run_cmd(["huggingface-cli", "version"]) + if available("huggingface-cli"): return True - except FileNotFoundError: + else: print("huggingface-cli not found. Some features may be limited.\n" + missing_huggingface) return False