@@ -111,9 +111,8 @@ def init_output_directories(self, scene_name):
111
111
"images_dir" , module_name = module_name , scene_name = scene_name
112
112
),
113
113
)
114
- self .image_file_path = os .path .join (
115
- image_dir ,
116
- add_extension_if_not_present (self .output_name , ".png" ),
114
+ self .image_file_path = image_dir / add_extension_if_not_present (
115
+ self .output_name , ".png"
117
116
)
118
117
119
118
if write_to_movie ():
@@ -122,14 +121,10 @@ def init_output_directories(self, scene_name):
122
121
"video_dir" , module_name = module_name , scene_name = scene_name
123
122
),
124
123
)
125
-
126
- self .movie_file_path = os .path .join (
127
- movie_dir ,
128
- add_extension_if_not_present (
129
- self .output_name ,
130
- config ["movie_file_extension" ],
131
- ),
124
+ self .movie_file_path = movie_dir / add_extension_if_not_present (
125
+ self .output_name , config ["movie_file_extension" ]
132
126
)
127
+
133
128
# TODO: /dev/null would be good in case sections_output_dir is used without bein set (doesn't work on Windows), everyone likes defensive programming, right?
134
129
self .sections_output_dir = ""
135
130
if config .save_sections :
@@ -149,7 +144,7 @@ def init_output_directories(self, scene_name):
149
144
self .gif_file_path
150
145
)
151
146
152
- self .gif_file_path = os . path . join ( movie_dir , self .gif_file_path )
147
+ self .gif_file_path = movie_dir / self .gif_file_path
153
148
154
149
self .partial_movie_directory = guarantee_existence (
155
150
config .get_dir (
@@ -213,9 +208,9 @@ def add_partial_movie_file(self, hash_animation):
213
208
self .partial_movie_files .append (None )
214
209
self .sections [- 1 ].partial_movie_files .append (None )
215
210
else :
216
- new_partial_movie_file = os . path . join (
217
- self .partial_movie_directory ,
218
- f"{ hash_animation } { config ['movie_file_extension' ]} " ,
211
+ new_partial_movie_file = str (
212
+ self .partial_movie_directory
213
+ / f"{ hash_animation } { config ['movie_file_extension' ]} "
219
214
)
220
215
self .partial_movie_files .append (new_partial_movie_file )
221
216
self .sections [- 1 ].partial_movie_files .append (new_partial_movie_file )
@@ -380,7 +375,8 @@ def write_opengl_frame(self, renderer):
380
375
renderer .get_raw_frame_buffer_object_data (),
381
376
)
382
377
elif is_png_format () and not config ["dry_run" ]:
383
- target_dir , extension = os .path .splitext (self .image_file_path )
378
+ target_dir = self .image_file_path .parent / self .image_file_path .stem
379
+ extension = self .image_file_path .suffix
384
380
self .output_image (
385
381
renderer .get_image (),
386
382
target_dir ,
@@ -389,7 +385,8 @@ def write_opengl_frame(self, renderer):
389
385
)
390
386
391
387
def output_image_from_array (self , frame_data ):
392
- target_dir , extension = os .path .splitext (self .image_file_path )
388
+ target_dir = self .image_file_path .parent / self .image_file_path .stem
389
+ extension = self .image_file_path .suffix
393
390
self .output_image (
394
391
Image .fromarray (frame_data ),
395
392
target_dir ,
@@ -442,8 +439,8 @@ def finish(self):
442
439
else :
443
440
self .clean_cache ()
444
441
elif is_png_format () and not config ["dry_run" ]:
445
- target_dir , _ = os . path . splitext ( self .image_file_path )
446
- logger .info ("\n %i images ready at %s\n " , self .frame_count , target_dir )
442
+ target_dir = self . image_file_path . parent / self .image_file_path . stem
443
+ logger .info ("\n %i images ready at %s\n " , self .frame_count , str ( target_dir ) )
447
444
if self .subcaptions :
448
445
self .write_subcaption_file ()
449
446
@@ -524,11 +521,11 @@ def is_already_cached(self, hash_invocation):
524
521
"""
525
522
if not hasattr (self , "partial_movie_directory" ) or not write_to_movie ():
526
523
return False
527
- path = os . path . join (
528
- self .partial_movie_directory ,
529
- f"{ hash_invocation } { config ['movie_file_extension' ]} " ,
524
+ path = (
525
+ self .partial_movie_directory
526
+ / f"{ hash_invocation } { config ['movie_file_extension' ]} "
530
527
)
531
- return os . path .exists (path )
528
+ return path .exists ()
532
529
533
530
def combine_files (
534
531
self ,
@@ -537,17 +534,15 @@ def combine_files(
537
534
create_gif = False ,
538
535
includes_sound = False ,
539
536
):
540
- file_list = os .path .join (
541
- self .partial_movie_directory ,
542
- "partial_movie_file_list.txt" ,
543
- )
537
+ file_list = str (self .partial_movie_directory / "partial_movie_file_list.txt" )
544
538
logger .debug (
545
539
f"Partial movie files to combine ({ len (input_files )} files): %(p)s" ,
546
540
{"p" : input_files [:5 ]},
547
541
)
548
542
with open (file_list , "w" , encoding = "utf-8" ) as fp :
549
543
fp .write ("# This file is used internally by FFMPEG.\n " )
550
544
for pf_path in input_files :
545
+ pf_path = str (pf_path )
551
546
if os .name == "nt" :
552
547
pf_path = pf_path .replace ("\\ " , "/" )
553
548
fp .write (f"file 'file:{ pf_path } '\n " )
@@ -578,7 +573,7 @@ def combine_files(
578
573
if not includes_sound :
579
574
commands += ["-an" ]
580
575
581
- commands += [output_file ]
576
+ commands += [str ( output_file ) ]
582
577
583
578
combine_process = subprocess .Popen (commands )
584
579
combine_process .wait ()
@@ -598,6 +593,7 @@ def combine_to_movie(self):
598
593
movie_file_path = self .movie_file_path
599
594
if is_gif_format ():
600
595
movie_file_path = self .gif_file_path
596
+ movie_file_path = str (movie_file_path )
601
597
logger .info ("Combining to Movie file." )
602
598
self .combine_files (
603
599
partial_movie_files ,
@@ -675,8 +671,8 @@ def combine_to_section_videos(self) -> None:
675
671
def clean_cache (self ):
676
672
"""Will clean the cache by removing the oldest partial_movie_files."""
677
673
cached_partial_movies = [
678
- os . path . join (self .partial_movie_directory , file_name )
679
- for file_name in os . listdir ( self .partial_movie_directory )
674
+ (self .partial_movie_directory / file_name )
675
+ for file_name in self .partial_movie_directory . iterdir ( )
680
676
if file_name != "partial_movie_file_list.txt"
681
677
]
682
678
if len (cached_partial_movies ) > config ["max_files_cached" ]:
@@ -689,7 +685,7 @@ def clean_cache(self):
689
685
)[:number_files_to_delete ]
690
686
# oldest_file_path = min(cached_partial_movies, key=os.path.getatime)
691
687
for file_to_delete in oldest_files_to_delete :
692
- os . remove ( file_to_delete )
688
+ file_to_delete . unlink ( )
693
689
logger .info (
694
690
f"The partial movie directory is full (> { config ['max_files_cached' ]} files). Therefore, manim has removed the { number_files_to_delete } oldest file(s)."
695
691
" You can change this behaviour by changing max_files_cached in config." ,
@@ -698,12 +694,12 @@ def clean_cache(self):
698
694
def flush_cache_directory (self ):
699
695
"""Delete all the cached partial movie files"""
700
696
cached_partial_movies = [
701
- os . path . join ( self .partial_movie_directory , file_name )
702
- for file_name in os . listdir ( self .partial_movie_directory )
697
+ self .partial_movie_directory / file_name
698
+ for file_name in self .partial_movie_directory . iterdir ( )
703
699
if file_name != "partial_movie_file_list.txt"
704
700
]
705
701
for f in cached_partial_movies :
706
- os . remove ( f )
702
+ f . unlink ( )
707
703
logger .info (
708
704
f"Cache flushed. { len (cached_partial_movies )} file(s) deleted in %(par_dir)s." ,
709
705
{"par_dir" : self .partial_movie_directory },
0 commit comments