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

Automatically identifies the class name based on the specified line number. #2280

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Varniex
Copy link
Contributor

@Varniex Varniex commented Dec 16, 2024

Motivation

Whenever some user passes the command -e <line_number>, it feels redundant to specify the class name.

The closest class name (above the specified <line_number>) should automatically be identified by the program, and updates the value of scene_names key in the run_config dict.

Proposed Changes

I couldn't find a better position to insert the code than in the insert_embed_line_to_module function. As it ensures that the scene_names updates only when the e flag is passed, and also the module lines can be used to determine the class name.

Also, resolving minor bugs in text_mobject and string_mobject files.


# Add the relevant embed line to the code
indent = get_indent(lines, line_number)
lines.insert(line_number, indent + "self.embed()")
new_code = "\n".join(lines)

# When the user executes the `-e <line_number>` command,
# it should automatically identifies the nearest class
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# it should automatically identifies the nearest class
# it should automatically identify the nearest class

@@ -5,13 +5,13 @@
# you are running manim. For 3blue1brown, for instance, mind is
# here: https://github.com/3b1b/videos/blob/master/custom_config.yml

# Alternatively, you can create it whereever you like, and on running
# Alternatively, you can create it where ever you like, and on running
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# Alternatively, you can create it where ever you like, and on running
# Alternatively, you can create it wherever you like, and on running

See the Cambridge dictionary

# When the user executes the `-e <line_number>` command,
# it should automatically identifies the nearest class
# defined above `<line_number>` as 'scene_names'.
classes = list(filter(lambda line: line.startswith("class"), lines[:line_number]))
Copy link
Contributor

Choose a reason for hiding this comment

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

What about classes that are defined as nested class, i.e. inside some other classes? They would have an indentation so line.startswith("class") would return False.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess the Scene Class (like: class SomeName(Scene)) would not be the nested one. So, I think in that case as well, it works.

@@ -142,35 +143,48 @@ def get_indent(code_lines: list[str], line_number: int) -> str:
return n_spaces * " "


def insert_embed_line_to_module(module: Module, line_number: int):
def insert_embed_line_to_module(module: Module, run_config: Dict) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of passing run_config inside here, an alternative could be to return the scene names from this function and then update the scene_names of run_config from somewhere outside, e.g. in get_module that is calling insert_embed_line_to_module).

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.

2 participants