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

MAINT Rendering the model card #94

Merged

Conversation

BenjaminBossan
Copy link
Collaborator

I wanted to discuss with you @skops-dev/maintainers what they think about this refactoring. Right now, the Card.save method performs the whole job of actually generating the ModelCard object. My plan is to simply factor this into a new method, _generate_card, and have the save method call this instead.

The main reason is to separate the concerns, i.e. save is only responsible for saving, not generating. What this affords us is that we can now easily add another method, render, which returns the generated model card as a string. This can, for instance, be used in the tests, as I have shown with one example. Instead of generating the card, storing it in a temp folder, reading it, then checking it, we can now just render the string and check it directly.

Please LMK if you agree and I will finish this PR.

Copy link
Member

@adrinjalali adrinjalali left a comment

Choose a reason for hiding this comment

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

I like this, we can add alternative render options later.

@BenjaminBossan
Copy link
Collaborator Author

I like this, we can add alternative render options later.

Exactly.

Okay, then I'll finish the refactoring.

- Add missing docstrings
- Add entry to changes.rst
- Simplify all tests that can use render
@BenjaminBossan
Copy link
Collaborator Author

@skops-dev/maintainers Ready for review.

@BenjaminBossan BenjaminBossan marked this pull request as ready for review August 11, 2022 12:39
@BenjaminBossan BenjaminBossan changed the title [WIP] Rendering the model card MAINT Rendering the model card Aug 11, 2022
Copy link
Collaborator

@merveenoyan merveenoyan left a comment

Choose a reason for hiding this comment

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

Left nits, thanks a for handling this 🥺👉🏼👈🏼

----------
path: str, or Path
filepath to save your card.
def _generate_card(self) -> ModelCard:
Copy link
Collaborator

Choose a reason for hiding this comment

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

This doesn't really generate the card itself because it already exists, but generates the content to be written. That would be better to go for a better naming IMHO.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, it doesn't generate the skops Card, it generates the modelcards ModelCard object. What would be a better name? I think _generate_content is a bit vague. I'm also not attached to generate, we can also use a plain make or something.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Since it's not a public method we could improve the docstring instead, I guess. Same with the below one.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Happy to improve the docstring. Could you please let me know what I should clarify -- since I made the change, for me it's obvious ;)

Same with the below one.

Which one do you mean?

card.save(path)

def render(self) -> str:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I liked what you did here but it's actually _generate_card that does rendering (with from_template) so I'd call this something else like render_to_str to avoid confusion for future maintainers. Feel free to ignore if you don't agree 🙂

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

but it's actually _generate_card that does rendering (with from_template)

I agree that _generate_card does the heavy lifting, but from a user perspective, it doesn't really matter.

so I'd call this something else like render_to_str to avoid confusion for future maintainers

I did think about render_to_str. IMO the name should be chosen with respect to the users, not so much maintainers, as it'll be a public method. render_to_str makes sense if we plan on adding other outputs and then have render_to_foo. If, instead, we want to support those other formats via arguments (card.render(format="foo")), I'd stick with the terse render. What is the more likely scenario?

Copy link
Member

@adrinjalali adrinjalali left a comment

Choose a reason for hiding this comment

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

I agree with @BenjaminBossan on how the methods are organized here. _generate_card is not something we'd document for users and they should never call it. So from their perspective, there's only render and save.

Comment on lines +415 to 416
card = self._generate_card()
card.save(path)
Copy link
Member

Choose a reason for hiding this comment

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

should this call render?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You mean call self.render and then write the string directly to the file, instead of going through card.save?

Copy link
Member

Choose a reason for hiding this comment

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

yeah that's a good question. I'm wondering if there could be a difference between users calling save and saving the output of render, which wouldn't be ideal I think. WDYT?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

At the moment, both would amount to the same, but who knows what else could be added on the modelcards side in the future. Therefore, I would prefer users to use skops Card.save, which in turn should use ModelCard.save. But if a user wants to call render and save that, I guess we can't prevent them.

Copy link
Member

@adrinjalali adrinjalali left a comment

Choose a reason for hiding this comment

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

LGTM. Merge conflicts though.

I'd wait maybe for @merveenoyan to have a final look.

@BenjaminBossan
Copy link
Collaborator Author

Solved the merge conflict and wait for Merve's verdict.

@adrinjalali
Copy link
Member

Merging this one. @merveenoyan feel free to open an issue or a PR fixing things which need to be fixed when you're back :)

@adrinjalali adrinjalali merged commit e2a3003 into skops-dev:main Aug 16, 2022
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.

3 participants