Skip to content

fix: missing friendly ImportError for m alora add-readme without [hf] #855

@planetf1

Description

@planetf1

Summary

m alora add-readme crashes with a raw ModuleNotFoundError when huggingface_hub is not installed, rather than the friendly install hint used by every other CLI command.

Steps to reproduce

pip install "mellea[cli]"  # without [hf]
m alora add-readme data.jsonl --basemodel gpt2 --name myorg/mymodel

Actual output:

ModuleNotFoundError: No module named 'huggingface_hub'

Expected output (consistent with m alora train, m serve, etc.):

ImportError: The 'm alora' command requires extra dependencies.
Please install them with: pip install "mellea[hf]"

Root cause

cli/alora/commands.py:155 imports huggingface_hub directly inside the function body without a guard:

def alora_add_readme(...):
    from huggingface_hub import HfFolder, create_repo, upload_file  # no try/except

All other commands lazy-import their heavy dependencies with a try/except ImportError block pointing to the correct extra. This one was missed.

Found during

Code review and isolated-environment testing of PR #789, which introduced the friendly import error pattern across the rest of the CLI.

Fix

Wrap the huggingface_hub import in alora_add_readme with the same guard pattern used elsewhere:

try:
    from huggingface_hub import HfFolder, create_repo, upload_file
except ImportError as e:
    raise ImportError(
        "The 'm alora' command requires extra dependencies. "
        'Please install them with: pip install "mellea[hf]"'
    ) from e

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions