mirror of
https://github.com/3b1b/manim.git
synced 2025-04-13 09:47:07 +00:00
Get rid of the (hacky) solution to redefining Scene methods, since reload handles it better
This commit is contained in:
parent
cb3e115a6c
commit
5b315d5c70
1 changed files with 0 additions and 21 deletions
|
@ -123,29 +123,8 @@ class CheckpointManager:
|
||||||
|
|
||||||
checkpoint_key = self.get_leading_comment(code_string)
|
checkpoint_key = self.get_leading_comment(code_string)
|
||||||
self.handle_checkpoint_key(scene, checkpoint_key)
|
self.handle_checkpoint_key(scene, checkpoint_key)
|
||||||
code_string = self.handle_method_definitions(code_string)
|
|
||||||
|
|
||||||
shell.run_cell(code_string)
|
shell.run_cell(code_string)
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def handle_method_definitions(code_string: str):
|
|
||||||
# Copied methods of a scene are handled specially
|
|
||||||
# A bit hacky, yes, but convenient
|
|
||||||
lines = code_string.split("\n")
|
|
||||||
method_pattern = r"^def\s+([a-zA-Z_]\w*)\s*\(self.*\):"
|
|
||||||
method_names = re.findall(method_pattern, lines[0].strip())
|
|
||||||
if method_names:
|
|
||||||
method_name = method_names[0]
|
|
||||||
indent = " " * lines[0].index(lines[0].strip())
|
|
||||||
return "\n".join([
|
|
||||||
# Remove self from function signature
|
|
||||||
re.sub(r"self(,\s*)?", "", lines[0]),
|
|
||||||
*lines[1:],
|
|
||||||
# Attach to scene via self.func_name = func_name
|
|
||||||
f"{indent}self.{method_name} = {method_name}"
|
|
||||||
])
|
|
||||||
return code_string
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_leading_comment(code_string: str):
|
def get_leading_comment(code_string: str):
|
||||||
leading_line = code_string.partition("\n")[0].lstrip()
|
leading_line = code_string.partition("\n")[0].lstrip()
|
||||||
|
|
Loading…
Add table
Reference in a new issue