mirror of
https://github.com/jeertmans/manim-slides.git
synced 2025-09-22 18:49:52 +08:00
feat(cli): using cached files when possible (#142)
* feat(cli): using cached files when possible This should improve a bit the overall performances * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
@ -169,7 +169,7 @@ class PresentationConfig(BaseModel): # type: ignore
|
|||||||
|
|
||||||
return values
|
return values
|
||||||
|
|
||||||
def copy_to(self, dest: Path) -> "PresentationConfig":
|
def copy_to(self, dest: Path, use_cached: bool = True) -> "PresentationConfig":
|
||||||
"""
|
"""
|
||||||
Copy the files to a given directory.
|
Copy the files to a given directory.
|
||||||
"""
|
"""
|
||||||
@ -177,13 +177,18 @@ class PresentationConfig(BaseModel): # type: ignore
|
|||||||
for i in range(n):
|
for i in range(n):
|
||||||
file = self.files[i]
|
file = self.files[i]
|
||||||
dest_path = dest / self.files[i].name
|
dest_path = dest / self.files[i].name
|
||||||
logger.debug(f"Moving / copying {file} to {dest_path}")
|
|
||||||
shutil.copy(file, dest_path)
|
|
||||||
self.files[i] = dest_path
|
self.files[i] = dest_path
|
||||||
|
if use_cached and dest_path.exists():
|
||||||
|
logger.debug(f"Skipping copy of {file}, using cached copy")
|
||||||
|
continue
|
||||||
|
logger.debug(f"Copying {file} to {dest_path}")
|
||||||
|
shutil.copy(file, dest_path)
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def concat_animations(self, dest: Optional[Path] = None) -> "PresentationConfig":
|
def concat_animations(
|
||||||
|
self, dest: Optional[Path] = None, use_cached: bool = True
|
||||||
|
) -> "PresentationConfig":
|
||||||
"""
|
"""
|
||||||
Concatenate animations such that each slide contains one animation.
|
Concatenate animations such that each slide contains one animation.
|
||||||
"""
|
"""
|
||||||
@ -193,8 +198,16 @@ class PresentationConfig(BaseModel): # type: ignore
|
|||||||
for i, slide_config in enumerate(self.slides):
|
for i, slide_config in enumerate(self.slides):
|
||||||
files = self.files[slide_config.slides_slice]
|
files = self.files[slide_config.slides_slice]
|
||||||
|
|
||||||
|
slide_config.start_animation = i
|
||||||
|
slide_config.end_animation = i + 1
|
||||||
|
|
||||||
if len(files) > 1:
|
if len(files) > 1:
|
||||||
dest_path = merge_basenames(files)
|
dest_path = merge_basenames(files)
|
||||||
|
dest_paths.append(dest_path)
|
||||||
|
|
||||||
|
if use_cached and dest_path.exists():
|
||||||
|
logger.debug(f"Concatenated animations already exist for slide {i}")
|
||||||
|
continue
|
||||||
|
|
||||||
f = tempfile.NamedTemporaryFile(mode="w", delete=False)
|
f = tempfile.NamedTemporaryFile(mode="w", delete=False)
|
||||||
f.writelines(f"file '{os.path.abspath(path)}'\n" for path in files)
|
f.writelines(f"file '{os.path.abspath(path)}'\n" for path in files)
|
||||||
@ -225,14 +238,14 @@ class PresentationConfig(BaseModel): # type: ignore
|
|||||||
if error:
|
if error:
|
||||||
logger.debug(error.decode())
|
logger.debug(error.decode())
|
||||||
|
|
||||||
dest_paths.append(dest_path)
|
if not dest_path.exists():
|
||||||
|
raise ValueError(
|
||||||
|
"could not properly concatenate animations, use `-v INFO` for more details"
|
||||||
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
dest_paths.append(files[0])
|
dest_paths.append(files[0])
|
||||||
|
|
||||||
slide_config.start_animation = i
|
|
||||||
slide_config.end_animation = i + 1
|
|
||||||
|
|
||||||
self.files = dest_paths
|
self.files = dest_paths
|
||||||
|
|
||||||
if dest:
|
if dest:
|
||||||
|
Reference in New Issue
Block a user