@@ -858,12 +858,27 @@ def prepare_collect_graphics(self, source_info, resolved_src_url, counter):
858858 )
859859 target_ext = converter_info ['target_ext' ]
860860
861- target_fname = self .collect_graphics_filename_template_obj .substitute ({
862- 'basename' : os .path .basename (resolved_src_url ),
863- 'basenoext' : basenoext ,
864- 'ext' : target_ext ,
865- 'counter' : counter ,
866- })
861+ input_hash = None
862+ if source_type == 'file' :
863+ with open (resolved_src_url , 'rb' ) as f :
864+ input_hash = hashlib .file_digest (f , 'sha256' ).hexdigest ()
865+
866+ try :
867+ target_fname = self .collect_graphics_filename_template_obj .substitute ({
868+ 'basename' : os .path .basename (resolved_src_url ),
869+ 'basenoext' : basenoext ,
870+ 'ext' : target_ext ,
871+ 'counter' : counter ,
872+ 'hash' : input_hash if input_hash is not None else 'NOHASH' ,
873+ 'hash6' : input_hash [:6 ] if input_hash is not None else 'NOHASH' ,
874+ })
875+ except KeyError as e :
876+ raise ValueError (
877+ f"Invalid file name template in feature_graphics_collection: ‘"
878+ + self .collect_graphics_filename_template
879+ + f"’ refers to invalid key ‘{ e .args [0 ]} ’"
880+ )
881+
867882 target_path = os .path .join (
868883 self .reference_output_dir ,
869884 self .collect_graphics_to_output_folder ,
@@ -880,6 +895,7 @@ def prepare_collect_graphics(self, source_info, resolved_src_url, counter):
880895 'source_url' : source_url ,
881896 'src_url_resolved' : resolved_src_url ,
882897 'converter_info' : converter_info ,
898+ 'input_hash' : input_hash ,
883899 'target_path' : target_path ,
884900 'target_relative_path' : target_relative_path ,
885901 'from_ext' : ext ,
@@ -902,10 +918,7 @@ def collect_graphics(self, source_key, collect_info, *, cache_info):
902918
903919 logger .debug ('converter_info = %r' , converter_info )
904920
905- input_hash = None
906- if source_type == 'file' :
907- with open (src_url , 'rb' ) as f :
908- input_hash = hashlib .file_digest (f , 'sha256' ).hexdigest ()
921+ input_hash = collect_info ['input_hash' ]
909922
910923 if os .path .exists (target_path ):
911924 # check if the input file was updated since last run
0 commit comments