1. fanstatic
  2. fanstatic
  3. fanstatic
Issue #84 new

Store compiled / versioned assets in different directory tree

Elmer de Looff
created an issue

My situations stems from the fact that my webserver (Apache using mod_wsgi) doesn't have permission to write in my project's source directories. I could alter this but that doesn't seem like the preferred solution. Also, I'm new to fanstatic, so it's quite possible I'm overlooking something fairly obvious.

My asset specification looks like this:

style_lib = fanstatic.Library(
    'style', 'styles', ignores=['*.sass', '*.scss'], minifiers={'.css': 'cssmin'})

app_css = fanstatic.Resource(
    style_lib, '_compiled/application.css', compiler='sass', source='application.sass')

The requirement for the app_css is placed in my base template as I always need it. This way however, the Apache user needs permission to write in the directory tree for my application. Ideally, I would like it to write somewhere else entirely (possibly /tmp or somewhere else on the filesystem).

Changing the _compiled path to an absolute path breaks retrieval and the docs don't seem to provide a solution here either.

For completeness, I'm using fanstatic 1.0a4 in combination with fanstatic_pyramid0.5.dev0.

Comments (4)

  1. Jan-Jaap Driessen

    We have built the fanstatic compiler feature around the best practice of not running compilers in production [1]. In such a scenario, you only ship python packages to the server, the compiling/minification of static assets can be part of the package build process.

    Another strategy that might work for you is to not use Apache+mod_wsgi, but run your pyramid app as a service user and set up an Apache reverse proxy.

    1) http://www.fanstatic.org/en/1.0a3/compilers.html

  2. Elmer de Looff reporter

    Thanks for your response, and yes, this is indeed the better solution.

    I find myself running into a slightly different problem now. I've changed my sass file to an scss file (the machinery seems to expect .scss extensions rather than sass, and this allows me to keep asset specifications a bit simpler).

    I now have the following code:

    import fanstatic
    
    style_lib = fanstatic.Library(
        'style',
        'styles',
        compilers={'.css': 'sass'},
        minifiers={'.css': 'cssmin'},
        )
    
    app_css = fanstatic.Resource(style_lib, 'application.css')
    

    The source file for this, appication.scss, is correctly picked up by fanstatic when I leave out the minifier, but when I add default minifiers on the library I get the following error:

    fanstatic.core.UnknownResourceError: Source file $project/frontend/ilost/frontend/assets/styles/application.min.scss for $project/frontend/ilost/frontend/assets/styles/application.min.css does not exist

    Am I wrong applying both a compiler and a minifier on a single library? This isn't in the examples but they don't state or imply this is impossible. Another thing that looks a bit iffy is the same .css extension for both compilation and minification, but this does follow from examples.

    Also, in addition to the above, after making an sdist and installing this, I still get errors stating that the source file for my (compiled and present) application.css is not present. My configuration for the test machine has compilation and hash computing disabled, so I'm not sure where this error comes from. It doesn't seem to follow that sources should be present.

    Apologies if the above comes across as negative, I really am enjoying the effect you and other put in, I've just not got my head wrapped around all of it.

  3. Jan-Jaap Driessen

    Sorry for the late response, I am on holidays. I'll look into the issues when I get back in a week. I see that you are in Groningen, will you attend the next PUN meeting in Amsterdam?

  4. Elmer de Looff reporter

    Not a problem, it's mostly small things that could be nicer, not a massive breaking problem. As for PUN, I may attend, depending on how and whether I can combine it with my already being in Amsterdam for work.

  5. Log in to comment