containers / ramalama

The goal of RamaLama is to make working with AI boring.
MIT License
272 stars 47 forks source link

Use shutil.which to find huggingface-cli #469

Closed rhatdan closed 2 days ago

rhatdan commented 2 days ago

Summary by Sourcery

Enhancements:

sourcery-ai[bot] commented 2 days ago

Reviewer's Guide by Sourcery

The PR improves the detection of the huggingface-cli tool by using Python's shutil.which() function instead of attempting to execute the CLI tool. This change provides a more efficient and standard way to check for the presence of executables in the system PATH.

Class diagram for huggingface-cli detection update

classDiagram
    class HuggingfaceCLIUtil {
        +is_huggingface_cli_available() bool
    }
    note for HuggingfaceCLIUtil "Updated to use shutil.which for CLI detection"

File-Level Changes

Change Details Files
Replace command execution with shutil.which() for checking huggingface-cli availability
  • Replace try-except block with direct path checking
  • Use shutil.which() to locate the executable in PATH
  • Update error message to use perror() function
  • Simplify control flow with if-else statement
ramalama/huggingface.py

Tips and commands #### Interacting with Sourcery - **Trigger a new review:** Comment `@sourcery-ai review` on the pull request. - **Continue discussions:** Reply directly to Sourcery's review comments. - **Generate a GitHub issue from a review comment:** Ask Sourcery to create an issue from a review comment by replying to it. - **Generate a pull request title:** Write `@sourcery-ai` anywhere in the pull request title to generate a title at any time. - **Generate a pull request summary:** Write `@sourcery-ai summary` anywhere in the pull request body to generate a PR summary at any time. You can also use this command to specify where the summary should be inserted. #### Customizing Your Experience Access your [dashboard](https://app.sourcery.ai) to: - Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others. - Change the review language. - Add, remove or edit custom review instructions. - Adjust other review settings. #### Getting Help - [Contact our support team](mailto:support@sourcery.ai) for questions or feedback. - Visit our [documentation](https://docs.sourcery.ai) for detailed guides and information. - Keep in touch with the Sourcery team by following us on [X/Twitter](https://x.com/SourceryAI), [LinkedIn](https://www.linkedin.com/company/sourcery-ai/) or [GitHub](https://github.com/sourcery-ai).