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

Conversation

thomasyip
Copy link
Contributor

This patch resolves the problem by copying the compiled file into the packager (s3) storage.

@peec
Copy link

peec commented Sep 28, 2015

+1 , very needed fix so S3 works.

@thomasyip
Copy link
Contributor Author

See also, issue: #473 and pr: #475

@peec
Copy link

peec commented Sep 29, 2015

If someone needs urgents fix like me:

monkey patch:

app/init.py:

# Fixes S3 for pipeline...
from pipeline.packager import Packager
from django.contrib.staticfiles.finders import get_finders, find


def __monkey_compile(self, paths, force=False):
        paths = self.compiler.compile(paths, 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 __monkey_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


Packager.compile = __monkey_compile
Packager.find_source_storage = __monkey_find_source_storage

@SverkerSbrg
Copy link

+1 Works well for me!

…tes output to the local one. This patch copies the generated file.

Conflicts:
	pipeline/packager.py
@coveralls
Copy link

Coverage Status

Coverage decreased (-1.1%) to 80.573% when pulling 0b4bf7b on beedesk:master into f004181 on jazzband:master.

@sowinski
Copy link

sowinski commented Aug 5, 2022

What need to be done to apply this fix to this branch? Is there a fork which is allready working?

@cyberdelia cyberdelia merged commit fafe97c into jazzband:master Aug 6, 2022
@sowinski
Copy link

sowinski commented Aug 6, 2022

@cyberdelia
Does it mean that it will work with the code from the master branch now?

EDIT:
With the current master branch it works perfectly:
pip3 install git+https://github.com/jazzband/django-pipeline.git@c85a2572e53218716359126d9465cc63447817e5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants