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

Compiler @import don't work #112

Closed
airtonix opened this issue May 13, 2012 · 15 comments
Closed

Compiler @import don't work #112

airtonix opened this issue May 13, 2012 · 15 comments
Labels
bug Bug confirmed or can be reproduced

Comments

@airtonix
Copy link
Contributor

With the below situation, our 'base' bundle is still being compressed and written to a file called 'css/base.css' (where it should be 'css/thatguyismystyle.base.min.css' )

The template tag still writes out the desired filename (which is 'css/thatguyismystyle.base.min.css' )


Django==1.3
django-pipeline==1.2.5
django-staticfiles==1.2.1

    from os.path import join
    from settings import SERVER_ROOT
    from collections import OrderedDict as OD

    NODE_BIN = join(SERVER_ROOT, 'node_modules/.bin')

    #
    # Pipelined CSS Files
    #


    PIPELINE_CSS = OD((
        ('base', {
            'source_filenames': (
                'css/base.less',
            ),

            'output_filename':
                'css/thatguyismystyle.base.min.css',

            'extra_context': {
                'media': 'screen',
            },
        }),
        ('theme', {
            'source_filenames': (
                'css/theme/base.less',
            ),
            'output_filename':
                'css/theme/thatguyismystyle.theme.min.css',

            'extra_context': {
                'media': 'screen',
            },
        }),
        ('theme-light', {
            'source_filenames': (
                'themes/light/css/base.less'
            ),
            'output_filename':
                'themes/thatguyismystyle.colour.light.min.css',
            'extra_context': {
                "media": "screen",
            }
        }),
        ('theme-dark', {
            'source_filenames': (
                'themes/dark/css/base.less'
            ),
            'output_filename':
                'themes/thatguyismystyle.colour.dark.min.css',
            'extra_context': {
                "media": "screen",
            }
        }),
    ))

    #
    # Pipelined JS FILES
    #

    BASE_JS_FRAMEWORK = (
        "js/lib/modernizr.min.js",
        "js/lib/jquery.min.1.7.1.js",
        "js/lib/history.js/jquery.history.js",
        "js/lib/moment.min.pretty.js",
        "js/lib/moment.strftime.min.js",
    )
    BOOTSTRAP_JS = (
        'js/lib/bootstrap/bootstrap-alert.js',
        'js/lib/bootstrap/bootstrap-button.js',
        'js/lib/bootstrap/bootstrap-carousel.js',
        'js/lib/bootstrap/bootstrap-collapse.js',
        'js/lib/bootstrap/bootstrap-dropdown.js',
        'js/lib/bootstrap/bootstrap-modal.js',
        'js/lib/bootstrap/bootstrap-popover.js',
        'js/lib/bootstrap/bootstrap-scrollspy.js',
        'js/lib/bootstrap/bootstrap-tab.js',
        'js/lib/bootstrap/bootstrap-tooltip.js',
        'js/lib/bootstrap/bootstrap-transition.js',
        'js/lib/bootstrap-contrib/*.js',
    )
    CKEDITOR_JS = (
        'js/lib/ckeditor/*.js',
    )
    TINYMCS_JS = (
        'js/lib/tinymce/tiny_mce.js',
        'js/lib/tinymce/langs/*.js',
        'js/lib/tinymce/jquery.tinymce.js',
    )


    PIPELINE_JS = OD((
        ('backend', {
            'source_filenames': (
                'js/lib/jquery.js',
            ) + BOOTSTRAP_JS
              + CKEDITOR_JS + (
                'js/lib/jquery.*.js',
                'js/lib/thatguyismystyle.*.js',
                'js/application.js',
            ),
            'output_filename': 'js/.js',
        }),
        ('profile-pages', {
            'source_filenames': (
            ),
            'output_filename': 'js/profile.js'
        })
    ))
    PIPELINE_JS = dict()

    PIPELINE_DISABLE_WRAPPER = True

    #
    # Compilers
    #

    PIPELINE_STORAGE = 'staticfiles.storage.StaticFilesStorage'
    STATICFILES_STORAGE = 'staticfiles.storage.StaticFilesStorage'
    PIPELINE=True

    PIPELINE_COMPILERS = (
        'pipeline.compilers.less.LessCompiler',
        'pipeline.compilers.coffee.CoffeeScriptCompiler',
    )
    PIPELINE_LESS_BINARY = join( NODE_BIN, 'lessc' )

    #
    # Compressors
    #
    PIPELINE_JS_COMPRESSOR = 'pipeline.compressors.jsmin.JSMinCompressor'
    PIPELINE_CSS_COMPRESSOR = 'pipeline.compressors.cssmin.CssminCompressor'


    STATICFILES_FINDERS = (
     'staticfiles.finders.AppDirectoriesFinder',
    )

    STATICFILES_IGNORE_PATTERNS = (
        "*.txt",
        "tests",
        "css/*.old",
        "/opt/webfiles/common/*.txt",
        "/opt/webfiles/common/temp",
    )
@cyberdelia
Copy link
Member

Are you running in DEBUG mode ? If so, the templatetag should serve the compiled file (base.js in your case), otherwise it should serve css/thatguyismystyle.base.min.css, but the file will be generated by the collectstatic command.

@airtonix
Copy link
Contributor Author

Let's just focus on the CSS for now (I've commented out anything to do with JS on my project since I posted the original ticket)

I understand what is supposed to happen, however :

  1. a bit sad that versioning is gone, would have been a nice feature.
  2. my output files are only ever *.css versions of what my input file name is, as in the file name of my output is never created according to what is specified in my settings. (perhaps this is because I only have one file as the input?)

I think there is some inconsistent behaviour resulting from using django==1.3 and django-staticfiles.

I did a-lot of fiddling with the storage settings concerning pipeline.

@cyberdelia
Copy link
Member

  1. Versioning is not gone, we are just using the versioning provided by staticfiles, you just need to setup :
STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage'
  1. The final output file is only created when your run the collectstatic command.

@airtonix
Copy link
Contributor Author

I understand that the output file is supposed to be created when I use collectstatic and this is not the issue.

The issue is actually that the output filename is not conforming to the rules i dictate as master and lord of the reality that is my django project. As a meglo-manical fascist dictator this makes me very unhappy.

You see from my initial post, that I expect the collectstatic command to do several things :

  1. find all the files the various static folders in applications listed in INSTALLED_APPS
  2. run lessc ./static/css/base.less > ./static/css/thatguyismystyle.base.min.css

However the second step there actually happens like :

  1. run lessc ./static/css/base.less > ./static/css/base.css

@cyberdelia
Copy link
Member

It will happen as long as you don't have set STATICFILES_STORAGE= 'pipeline.storage.PipelineCachedStorage'.

@twoolie
Copy link

twoolie commented May 16, 2012

Can I add that pipeline also seems to try to build all the assets from within the app static directory instead of from the STATIC_ROOT directory where all the staticfiles have been collected

@cyberdelia
Copy link
Member

@airtonix Did STATICFILES_STORAGE= 'pipeline.storage.PipelineCachedStorage' worked for you ?
@twoolie See #80.

@airtonix
Copy link
Contributor Author

no because our less files span many app static directories, so they
only work under the assumption that they are processed in the collected
static root.

@cyberdelia
Copy link
Member

Let's proceed step by step, if you setup STATICFILES_STORAGE = "pipeline.storage.PipelineCachedStorage" and run manage.py collecstatic, do you obtain a file named css/thatguyismystyle.base.min.css in your STATIC_ROOT ?

@airtonix
Copy link
Contributor Author

@cyberdelia no. because there are less files in some apps that import less files from other apps... which fail because the less compiling occurs before they are moved to the settings.STATIC_ROOT.

For example :

# base/static/css/base_mixins.less

.handy_global_mixin_for_something(@a:#ccc){ color: @a; }

# blogs/static/css/comments.less

@import "base_mixins";

.blog{
 padding: 1em;

 .comments{
   .handy_global_mixin_for_something(#08f);
 }

}

This fails because the import expects the base_mixins.less to be in the same directory, but it is impractical to make a copy of this base_mixins inside every single django app where i want to make use of it.

all less files should be copied to the settings.STATIC_ROOT before lessc compiling occurs.

So I want to get this working so i can then get jsmin working on our javascript files... but i can't because it's impractical to edit the pipeline config to disable the less setup just to get the js working.

@cyberdelia
Copy link
Member

I acknowledge this issue. Thanks for taking time to debug it, it helps a lot.
I've started to build a fix (see the compiler-import branch), but it might have some drawbacks.

@cyberdelia
Copy link
Member

@twoolie Did you have the time to test the compiler-import branch ? Sorry again, It's been a busy month.

@twoolie
Copy link

twoolie commented Oct 3, 2012

@cyberdelia No sorry, I had to switch focus. I'll be testing it out around the end of this week/start of next though.

@cyberdelia
Copy link
Member

@twoolie It does work with collectstatic, but not in DEBUG/dev mode for now.

@cyberdelia
Copy link
Member

Closing in favor of #150.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug confirmed or can be reproduced
Projects
None yet
Development

No branches or pull requests

3 participants