Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved packager.compile() to handle s3 storage when compiler generates output to the local one. #502

Merged
merged 1 commit into from
Aug 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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