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

Improve jupyter repr and __repr__ for Flyte models #2647

Merged

Conversation

thomasjpfan
Copy link
Member

Why are the changes needed?

Improves jupyter repr for flytekit.models.

What changes were proposed in this pull request?

This PR adds a _repr_html_ that generically renders any flytekit.model. Internally it uses _repr_idl_yaml_like that renders any flyteidl as a yaml like repr.

How was this patch tested?

I added a simple unit test.

Screenshots

This PR

Screenshot 2024-08-02 at 10 25 00 PM

Current

Screenshot 2024-08-02 at 10 26 28 PM

Signed-off-by: Thomas J. Fan <thomasjpfan@gmail.com>
Signed-off-by: Thomas J. Fan <thomasjpfan@gmail.com>
pingsutw
pingsutw previously approved these changes Aug 3, 2024
@@ -40,6 +44,29 @@ def from_flyte_idl(cls, idl_object):
pass


def _repr_idl_yaml_like(idl, indent=0) -> str:
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not make this the default repr

Copy link
Member Author

Choose a reason for hiding this comment

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

I wanted to make it the default, but I saw the current repr strips away the newlines:

literal_str = re.sub(r"\s+", " ", str(self.to_flyte_idl())).strip()

Was there a reason for making it all one line?

Copy link
Contributor

Choose a reason for hiding this comment

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

i don't think so, not a good one anyways. feel free to overwrite. the reason likely was logging platforms (cloudwatch logs, splunk, grafana, etc) don't render logs with new lines well. but i don't know how much this could matter for python. that's more of a backend issue.

Signed-off-by: Thomas J. Fan <thomasjpfan@gmail.com>
Signed-off-by: Thomas J. Fan <thomasjpfan@gmail.com>
…ve_repr_jupyter

Signed-off-by: Thomas J. Fan <thomasjpfan@gmail.com>
Signed-off-by: Thomas J. Fan <thomasjpfan@gmail.com>
Signed-off-by: Thomas J. Fan <thomasjpfan@gmail.com>
Signed-off-by: Thomas J. Fan <thomasjpfan@gmail.com>
@thomasjpfan thomasjpfan changed the title Improve jupyter repr for Flyte models Improve jupyter repr and __repr__ for Flyte models Aug 21, 2024
wild-endeavor
wild-endeavor previously approved these changes Aug 21, 2024
type_str = type(self).__name__
return f"[Flyte Serialized object: Type: <{type_str}> Value: <{literal_str}>]"
return f"Flyte Serialized object ({type_str}):" + os.linesep + str_repr
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we add a few more tests to cover the different types of literals (collections, maps, etc)? These are useful especially in flyteremote when debugging.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added more tests in 21372e4

Signed-off-by: Thomas J. Fan <thomasjpfan@gmail.com>
…ve_repr_jupyter

Signed-off-by: Thomas J. Fan <thomasjpfan@gmail.com>
Copy link

codecov bot commented Aug 27, 2024

Codecov Report

Attention: Patch coverage is 73.07692% with 7 lines in your changes missing coverage. Please review.

Project coverage is 80.51%. Comparing base (83b90fa) to head (f12a555).
Report is 6 commits behind head on master.

Files Patch % Lines
flytekit/models/common.py 73.07% 5 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2647      +/-   ##
==========================================
+ Coverage   78.69%   80.51%   +1.81%     
==========================================
  Files         187      286      +99     
  Lines       19257    23763    +4506     
  Branches     4029     3814     -215     
==========================================
+ Hits        15155    19132    +3977     
- Misses       3404     3928     +524     
- Partials      698      703       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@eapolinario eapolinario merged commit 28cf620 into flyteorg:master Aug 27, 2024
101 of 103 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.

5 participants