-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
base: master
Are you sure you want to change the base?
Conversation
|
||
# 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Alternatively, you can create it where ever you like, and on running | |
# Alternatively, you can create it wherever you like, and on running |
# 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])) |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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)
.
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 ofscene_names
key in therun_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 thescene_names
updates only when thee
flag is passed, and also the module lines can be used to determine the class name.Also, resolving minor bugs in
text_mobject
andstring_mobject
files.