Skip to content

Commit 3d4bc4c

Browse files
authored
include repo_id in the card usage. (#284)
1 parent 7dbc786 commit 3d4bc4c

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

kernels/src/kernels/cli/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ def create_and_upload_card(args):
356356
)
357357

358358
updated_card = _update_kernel_card_usage(
359-
kernel_card=kernel_card, local_path=kernel_dir
359+
kernel_card=kernel_card, local_path=kernel_dir, repo_id=args.repo_id
360360
)
361361
updated_card = _update_kernel_card_available_funcs(
362362
kernel_card=kernel_card, local_path=kernel_dir

kernels/tests/test_kernel_card.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import tempfile
22
from pathlib import Path
33
from dataclasses import dataclass
4+
from unittest.mock import patch
45

56
import pytest
67

@@ -273,3 +274,23 @@ def test_create_and_upload_card_custom_description(mock_kernel_dir):
273274
card_content = card_path.read_text()
274275

275276
assert custom_desc in card_content
277+
278+
279+
def test_create_and_upload_card_usage_with_repo_id(mock_kernel_dir):
280+
"""Test that usage code snippet includes the provided repo_id."""
281+
with tempfile.TemporaryDirectory() as tmpdir:
282+
card_path = Path(tmpdir) / "README.md"
283+
284+
args = CardArgs(
285+
kernel_dir=str(mock_kernel_dir),
286+
card_path=str(card_path),
287+
repo_id="my-org/my-kernel",
288+
)
289+
290+
with patch("huggingface_hub.ModelCard.push_to_hub"):
291+
create_and_upload_card(args)
292+
293+
card_content = card_path.read_text()
294+
295+
assert "## How to use" in card_content
296+
assert 'get_kernel("my-org/my-kernel")' in card_content

0 commit comments

Comments
 (0)