Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve card metadata format/ordering on load->save #2570

Merged
merged 2 commits into from
Oct 3, 2024

Conversation

hlky
Copy link
Contributor

@hlky hlky commented Sep 26, 2024

This PR ensures the format/ordering of card metadata is preserved on load->save.

Example:

from huggingface_hub import ModelCard

model_card = """---
license: mit
datasets:
- foo
- bar
---

Hello
"""

card = ModelCard(model_card)
card.data.license = "test"
card.content

Currently produces:

---
datasets:
- foo
- bar
license: test
---

Hello

Now:

---
license: test
datasets:
- foo
- bar
---

Hello

Fixes #2564

@hlky hlky force-pushed the preserve-card-metadata-ordering branch from 680d7a5 to 1458a80 Compare October 2, 2024 16:11
@hlky hlky force-pushed the preserve-card-metadata-ordering branch from 1458a80 to a0f1e75 Compare October 2, 2024 17:31
Copy link
Contributor

@Wauplin Wauplin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @hlky for the contribution! Looks good to me now :)

tests/test_repocard.py Outdated Show resolved Hide resolved
@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@hlky hlky force-pushed the preserve-card-metadata-ordering branch from eef6bee to 5b3baf9 Compare October 3, 2024 11:47
@hlky
Copy link
Contributor Author

hlky commented Oct 3, 2024

Tests should be fixed.

@Wauplin
Copy link
Contributor

Wauplin commented Oct 3, 2024

Failed test is unrelated :) Let's merge this!

@Wauplin Wauplin merged commit 1b8e9cf into huggingface:main Oct 3, 2024
15 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Model card metadata format is not preserved when loaded + saved again
3 participants