Skip to content

Commit

Permalink
Improved packager.compile() to handle s3 storage when compiler genera…
Browse files Browse the repository at this point in the history
…tes output to the local one. This patch copies the generated file. (#502)
  • Loading branch information
thomasyip authored Aug 6, 2022
1 parent f961008 commit fafe97c
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions pipeline/packager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.contrib.staticfiles.storage import staticfiles_storage
from django.contrib.staticfiles.finders import find
from django.contrib.staticfiles.finders import get_finders, find
from django.core.files.base import ContentFile
from django.utils.encoding import smart_bytes

Expand Down Expand Up @@ -98,11 +98,25 @@ def pack_stylesheets(self, package, **kwargs):
variant=package.variant, **kwargs)

def compile(self, paths, compiler_options={}, force=False):
return self.compiler.compile(
paths = self.compiler.compile(
paths,
compiler_options=compiler_options,
force=force,
)
for path in paths:
if not self.storage.exists(path):
if self.verbose:
print("Compiled file '%s' cannot be found with packager's storage. Locating it." % path)

source_storage = self.find_source_storage(path)
if source_storage is not None:
with source_storage.open(path) as source_file:
if self.verbose:
print("Saving: %s" % path)
self.storage.save(path, source_file)
else:
raise IOError("File does not exist: %s" % path)
return paths

def pack(self, package, compress, signal, **kwargs):
output_filename = package.output_filename
Expand All @@ -127,6 +141,15 @@ def pack_templates(self, package):
def save_file(self, path, content):
return self.storage.save(path, ContentFile(smart_bytes(content)))

def find_source_storage(self, path):
for finder in get_finders():
for short_path, storage in finder.list(''):
if short_path == path:
if self.verbose:
print("Found storage: %s" % str(self.storage))
return storage
return None

def create_packages(self, config):
packages = {}
if not config:
Expand Down

0 comments on commit fafe97c

Please sign in to comment.