bhoov / manim-notebook

Simple commands to replicate the manim dev workflow in VSCode
MIT License
5 stars 2 forks source link

Only show ManimCells in actual Manim files #12

Open Splines opened 3 days ago

Splines commented 3 days ago

See my comment here:

Question: "Can we implement logic to only show this [Manim Cells with fold ranging] when we are in a manim file?"

Sure I could give this a try, maybe this is a better fit for a subsequent PR [...]. To detect if we're in a manim file, I'd try to find the class we're in right now and see if that one inherits from either Scene or InteractiveScene. Searching for a manim-related import string would be a poor choice in my opinion as even in 3b1b's video repo, he's using something like from manim_imports_ext import * where `manim_importsext is a custom file at the root of the repo. So imports don't even have to include "manim" as string and yet it could be a Manim-related file.

Splines commented 3 days ago

One easy solution (for us) would be to force users to name their files properly e.g. myScene.manim.py. But this might be too restrictive.

bhoov commented 2 days ago

Agree, a naming convention for manim scene files would be too restrictive, and indeed we should not do string matching in case users put their manim imports in a separate file.

Here's a proposed workflow, ignoring developer effort:

  1. For any given .py file, check if classes inherit from Scene or InteractiveScene. Next to each non-empty line in the .construct submethod of these classes, add a "Start Manim Notebook at this line" (making an assumption about the official name for this extension) button that will run the manimgl <fname.py> <SceneName> -se <currLineNum> command.
    • (Is only putting initialization buttons in the construct method too restricting? I can imagine some users will want to abstract functionality of the construct method to external functions)
  2. Before an interactive manim session is running, the "Run Active Cell button" starts the manimgl interactive session up to the lineNumber at the end of that cell
  3. If a file contains no Scene or InteractiveScene classes, manim code folding, active cell running, and buttons to initialize the interactive manim session are disabled
VladimirFokow commented 2 days ago

Another easy option:

require that each "manim file" contains a special line, e.g.:

# Manimfile

kind of like xml version="1.0" in xml (but in xml it's optional – here it would be mandatory)

(not necessarily the first line - to allow to have e.g. license headers)




About your proposed option: .manim.py -
I personally don't think it's restrictive at all - because you can have any file name; you're just adding .manim before the .py
However I slightly prefer my first option (above).

Splines commented 2 days ago

Next to each non-empty line in the .construct submethod of these classes, add a "Start Manim Notebook at this line"

If there was a button next to every single line of my Python method, I would definitely panic. This should rather be a command IMHO.

Before an interactive manim session is running, the "Run Active Cell button" starts the manimgl interactive session up to the lineNumber at the end of that cell

Love that behavior, which goes along with #2. But I'd rather want that manimgl gets passed the start of the cell, since I want to preview from the start point, right? I.e. the line where Preview Manim Cell is shown.

For any given .py file, check if classes inherit from Scene or InteractiveScene

This sounds reasonable. Maybe then just add appropriate Manim behavior to every function of such classes? I mean, if users don't want to use a Manim Cell in a custom function living inside a Scene class, they just don't use ## in their comments and that's it. I wouldn't restrict it to the construct() method since users can call any other method from within construct() or setup().

We should make sure that there's no other way than creating a class inheriting from Scene or Inheriting Scene to define Manim code.

Another easy option: require that each "manim file" contains a special line [...]

While a # Manimfile preamble or file name like .manim.py would work, even something simple like this can create friction for new users. It'd be neat to aim for a "works out of the box" solution. We already have to inform users that ## starts a Manim Cell, but maybe that's all they need to know to preview cells and interact with the extension?

bhoov commented 2 days ago

If there was a button next to every single line of my Python method, I would definitely panic. This should rather be a command IMHO.

😂😂 Fair. I was envisioning hijacking the "debug" button to launch manimgl interactive. the debug button only shows if it is cursed over, and maybe we can even hijack the tooltip and icon in manim files (aspirational), but this would be one way of doing this without introducing any visual chaos.

Export-1729612019907

I'd rather want that manimgl gets passed the start of the cell

Yes fair. I agree this is the better behavior

While a # Manimfile preamble or file name like .manim.py would work, even something simple like this can create friction for new users.

I agree with @Splines here. We should use these tricks only as a fallback if we can't come up with anything else. In general, I feel that the rule should be:

"Other people have already built awesome manim videos using their own naming conventions and scripts. How can we activate this manim extension seamlessly and automatically for those scripts, while minimizing the number of manim-unrelated scripts we activate on?"

I will continue to think on this. Maybe even having a vscode popup that says "Possible Manim file detected, vscode-manim automatically activated. Deactivate? [y/N]"

We should make sure that there's no other way than creating a class inheriting from Scene or Inheriting Scene to define Manim code.

I'm not familiar enough with how people use Manim to answer this question... Clearly it is easiest to make a Manim video from these classes 🤷