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

Added media_embed config option to control whether media in Jupyter notebooks is embedded #2442

Merged
merged 11 commits into from
Feb 23, 2022

Conversation

mforbes
Copy link
Contributor

@mforbes mforbes commented Jan 8, 2022

Overview: What does this pull request change?

Adds a --embed option to the %%manim magic that will embed the video data.

Resolves #2441, #2416.

Motivation and Explanation: Why and how do your changes improve the library?

Currently video data is embedded only if running on Google's CoLab platform, but there are other use-cases (relocatable notebooks) and this should be customizable.

Links to added or changed documentation pages

Further Information and Comments

Reviewer Checklist

  • The PR title is descriptive enough for the changelog, and the PR is labeled correctly
  • If applicable: newly added non-private functions and classes have a docstring including a short summary and a PARAMETERS section
  • If applicable: newly added functions and classes are tested

@mforbes
Copy link
Contributor Author

mforbes commented Jan 8, 2022

I think the code is complete, but need to figure out how to write tests. Also, I have slightly abused config allowing users to set config.embed_video = True (or False to override CoLab). Should add an official config option or just leave this as a mildly documented feature?

@mforbes
Copy link
Contributor Author

mforbes commented Jan 8, 2022

Any suggestions on how to test this change would be appreciated. Only the _generate_file_name() function seems to be currently tested in tests/. Am I missing some sort of testing that spins up a notebook and executes the magic?

@mforbes
Copy link
Contributor Author

mforbes commented Jan 8, 2022

In principle Images can be embedded too, so I changed the config option to simply embed and apply it to images as well. The CoLab override only applies to videos, but the default for Image is generally True unless it is a URL.

@behackl behackl added this to the 0.15.0 milestone Feb 2, 2022
Copy link
Member

@behackl behackl left a comment

Choose a reason for hiding this comment

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

In general this looks good to me, thank you for your contribution!

I am somewhat on the fence regarding the Jupyter-only implementation of --embed, and I think that given the fact that stuff like media_width also is a proper configuration option it would be more consistent to do so here as well. What do you (or other devs) think about that?

manim/utils/ipython_magic.py Outdated Show resolved Hide resolved
Copy link
Member

@behackl behackl left a comment

Choose a reason for hiding this comment

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

I have thought about it some more, and I think introducing jupyter-only flags is a bad idea overall. This should be implemented as a proper config option, just like media_width. Perhaps also renamed to media_embed.

In case there is no reaction here, I'll look into it.

@mforbes
Copy link
Contributor Author

mforbes commented Feb 13, 2022

Okay, I took a stab at making media_embed follow the same pattern as media_width. I don't see any tests for media_width and am not familiar enough with the code to know how to add new tests for these. Can one do manim --media_width? It does not seem to be supported. (Or is it only a config-file configurable option?)

Copy link
Member

@behackl behackl 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 very much for your efforts! There are two problems that should be addressed:

  • In default.cfg, media_embed should not be assigned a value (otherwise it will be false by default); just put media_embed = .
  • The value from the default config currently get read and parsed as strings, you can check that python -c "from manim import config; config.media_embed" yields the string "False". The logic in utils.py needs to be adapted: after changing the value in default.cfg the default case will be that parser["jupyter"].get("media_embed") will yield the empty string "".

What do you think?

manim/utils/ipython_magic.py Show resolved Hide resolved
@behackl
Copy link
Member

behackl commented Feb 20, 2022

I went ahead and fixed the issues raised in my code review via 1ec2017 -- from my point of view, this is good to go now.

Thanks again for your efforts!

@behackl behackl changed the title feat: Added --embed option to %%manim ManimMagic. Added media_embed config option to control whether media in Jupyter notebooks is embedded Feb 21, 2022
@behackl behackl added the new feature Enhancement specifically adding a new feature (feature request should be used for issues instead) label Feb 21, 2022
Copy link
Member

@Darylgolden Darylgolden left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

@behackl behackl enabled auto-merge (squash) February 23, 2022 09:34
@behackl behackl merged commit 99b11da into ManimCommunity:main Feb 23, 2022
@ad-chaos
Copy link
Collaborator

ad-chaos commented Mar 5, 2022

This seems to have broken preview in jupyter notebooks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature Enhancement specifically adding a new feature (feature request should be used for issues instead)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add video_embed or --embed argument to ManimMagic
4 participants