Skip to content

Commit 71564a4

Browse files
authored
fix(convert): use hash to restrict the length of new filenames (#124)
Closes #123
1 parent b062500 commit 71564a4

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

example.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,24 @@ def construct(self):
3232
self.pause() # Waits user to press continue to go to the next slide
3333

3434

35+
class TestFileTooLong(Slide):
36+
"""This is used to check against solution for issue #123."""
37+
38+
def construct(self):
39+
import random
40+
41+
circle = Circle(radius=3, color=BLUE)
42+
dot = Dot()
43+
self.play(GrowFromCenter(circle), run_time=0.1)
44+
45+
for _ in range(30):
46+
direction = (random.random() - 0.5) * LEFT + (random.random() - 0.5) * UP
47+
self.play(dot.animate.move_to(direction), run_time=0.1)
48+
self.play(dot.animate.move_to(ORIGIN), run_time=0.1)
49+
50+
self.pause()
51+
52+
3553
class ConvertExample(Slide):
3654
"""WARNING: this example does not seem to work with ManimGL."""
3755

manim_slides/config.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import hashlib
12
import os
23
import shutil
34
import subprocess
@@ -15,11 +16,18 @@ def merge_basenames(files: List[str]) -> str:
1516
"""
1617
Merge multiple filenames by concatenating basenames.
1718
"""
19+
logger.info(f"Generating a new filename for animations: {files}")
1820

1921
dirname = os.path.dirname(files[0])
2022
_, ext = os.path.splitext(files[0])
2123

22-
basename = "_".join(os.path.splitext(os.path.basename(file))[0] for file in files)
24+
basenames = (os.path.splitext(os.path.basename(file))[0] for file in files)
25+
26+
basenames_str = ",".join(f"{len(b)}:{b}" for b in basenames)
27+
28+
# We use hashes to prevent too-long filenames, see issue #123:
29+
# https://github.com/jeertmans/manim-slides/issues/123
30+
basename = hashlib.sha256(basenames_str.encode()).hexdigest()
2331

2432
return os.path.join(dirname, basename + ext)
2533

0 commit comments

Comments
 (0)