MCPcopy
hub / github.com/django/django / post_process

Method post_process

django/contrib/staticfiles/storage.py:316–378  ·  view source on GitHub ↗

Post process the given dictionary of files (called from collectstatic). Processing is actually two separate operations: 1. renaming files to include a hash of their content for cache-busting, and copying those files to the target storage. 2. adjusting fi

(self, paths, dry_run=False, **options)

Source from the content-addressed store, hash-verified

314 return converter
315
316 def post_process(self, paths, dry_run=False, **options):
317 """
318 Post process the given dictionary of files (called from collectstatic).
319
320 Processing is actually two separate operations:
321
322 1. renaming files to include a hash of their content for cache-busting,
323 and copying those files to the target storage.
324 2. adjusting files which contain references to other files so they
325 refer to the cache-busting filenames.
326
327 If either of these are performed on a file, then that file is
328 considered post-processed.
329 """
330 # don't even dare to process the files if we're in dry run mode
331 if dry_run:
332 return
333
334 # where to store the new paths
335 hashed_files = {}
336
337 # build a list of adjustable files
338 adjustable_paths = [
339 path for path in paths if matches_patterns(path, self._patterns)
340 ]
341
342 # Adjustable files to yield at end, keyed by the original path.
343 processed_adjustable_paths = {}
344
345 # Do a single pass first. Post-process all files once, yielding not
346 # adjustable files and exceptions, and collecting adjustable files.
347 for name, hashed_name, processed, _ in self._post_process(
348 paths, adjustable_paths, hashed_files
349 ):
350 if name not in adjustable_paths or isinstance(processed, Exception):
351 yield name, hashed_name, processed
352 else:
353 processed_adjustable_paths[name] = (name, hashed_name, processed)
354
355 paths = {path: paths[path] for path in adjustable_paths}
356 unresolved_paths = []
357 for i in range(self.max_post_process_passes):
358 unresolved_paths = []
359 for name, hashed_name, processed, subst in self._post_process(
360 paths, adjustable_paths, hashed_files
361 ):
362 # Overwrite since hashed_name may be newer.
363 processed_adjustable_paths[name] = (name, hashed_name, processed)
364 if subst:
365 unresolved_paths.append(name)
366
367 if not unresolved_paths:
368 break
369
370 if unresolved_paths:
371 problem_paths = ", ".join(sorted(unresolved_paths))
372 yield problem_paths, None, RuntimeError("Max post-process passes exceeded.")
373

Callers 2

post_processMethod · 0.45
collectMethod · 0.45

Calls 6

_post_processMethod · 0.95
matches_patternsFunction · 0.90
appendMethod · 0.45
joinMethod · 0.45
updateMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected