Coder Social home page Coder Social logo

django 1.3 compatibility about webassets HOT 14 CLOSED

miracle2k avatar miracle2k commented on August 19, 2024
django 1.3 compatibility

from webassets.

Comments (14)

kmike avatar kmike commented on August 19, 2024

If this approach is feasible I can work on patch.

from webassets.

miracle2k avatar miracle2k commented on August 19, 2024

I hadn't really looked at staticfiles before. I agree with your solution as described in 1. and 2., and I'd be happy to accept a patch.

(c) is an interesting problem though, and one that would need to be solved at some point. For example, I'm personally quite fond of CSS compilers like sass, and those always need processing, obviously.

Though I don't see a good solution forthcoming right now though. Something like 023c695 would probably be necessary to allow for flexible referencing of static files, and ASSETS_ROOT, which would still be used to determine the output filename, would simply need to be a directory that staticfiles includes. So either the user would need to conditionally append ASSETS_ROOT to STATICFILES_DIRS (in debug mode only), or django-assets could employ trickery to do it for him: either my modifying the setting, or monkeypatching staticfiles. Neither of those options sound particularly great though, so for the moment I'm inclined to go with requiring a manual setup.

from webassets.

miracle2k avatar miracle2k commented on August 19, 2024

Most of this has been dealt with in #22 . I'm leaving it open for the (c) part.

from webassets.

dchaplinsky avatar dchaplinsky commented on August 19, 2024

Hmm, I have some problems with this solutions.

I'm using django 1.2.5 with staticfiles installed. For production I collect staticfiles together with manage.py command but for development I use

    urlpatterns += patterns("",
        url(r"", include("staticfiles.urls")),
    )

The only problem is that not all my static files are laying in the same place. Some files served by staticfiles are from other installed apps, like uni_form and picked by staticfiles directly from the uni_form package.

But when I'm trying to create a bundle like this:

common_js = Bundle('media/js/jquery.js', 'media/js/jquery.cookie.js', 
                   'media/js/base.js', 'media/js/uni_form/uni-form.jquery.js',
                   output='gen/common.js')
register('common_js', common_js) 

it says:
IOError at /

[Errno 2] No such file or directory: '/Users/dchaplinsky/Projects/foobar/media/js/uni_form/uni-form.jquery.js'

Of course, it's absent there :)

from webassets.

dchaplinsky avatar dchaplinsky commented on August 19, 2024

Finally fixed it in such way in my assets.py:

from django_assets import Bundle, register
from staticfiles.resolvers import resolve

files = [resolve(fname) for fname in ('js/jquery.js', 'js/jquery.cookie.js', 
                                      'js/base.js', 'uni_form/uni-form.jquery.js')]
common_js = Bundle(*files, output='gen/common.js')
register('common_js', common_js)

But it will be great if it's possible to incorporate this changes directly into webassets. If you want, I can prepare pull request.

Answering potential question, I cannot put webassets into the debug mode, because I still need my sass files parsed and served.

from webassets.

miracle2k avatar miracle2k commented on August 19, 2024

Basically, your problem seems to be the missing (c) in the original report. Two problems not be to be solved here:

*) We want to be able to reference media files in Bundles that may actually be in any one of the static file directories. django_assets will need to overwrite how webassets finds/opens the files here, and invoke staticfiles.resolvers.resolve(). It will either have to do so when building, or at bundle creation time, like you are doing in your example. It could be helpful to look at how Flask-Assets deals with modules.

*) A decision needs to be taken as to where a compressed output file should be stored. As was mentioned, STATIC_ROOT is likely not served by the staticfiles app in development. It might be necessary to monkey patch Django here.

Let me note, for future personal reference, that I had a hard time to understand your first example, which is somewhat of confusing. I gather now that you have:

  • A /Users/dchaplinsky/Projects/foobar/media/js/ directory.
  • An installation of the django-uni-form app, which contains a media/uni_form directory.

It also looks like your ASSETS_ROOT base directory is "/Users/dchaplinsky/Projects/foobar/" for some reason, which seems strange. It might make more sense to have the base be "/Users/dchaplinsky/Projects/foobar/media/js", and specify your files in the bundle as "js/jquery.js".

from webassets.

miracle2k avatar miracle2k commented on August 19, 2024

Also, this has not been mentioned so far, and is unrelated to your issue, I wonder whether it makes sense to have the ./manage.py assets rebuild command invoke a staticfiles collection by default, make django-assets pick up the static files itself or otherwise ease the process. At the very least this is a documentation issue: When using staticfiles, the staticfiles collection needs to run before an asset build.

from webassets.

dchaplinsky avatar dchaplinsky commented on August 19, 2024
  • A /Users/dchaplinsky/Projects/foobar/media/js/ directory.
  • An installation of the django-uni-form app, which contains a media/uni_form directory.

That's correct

It also looks like your ASSETS_ROOT base directory is "/Users/dchaplinsky/Projects/foobar/" for some reason, which
seems strange. It might make more sense to have the base be "/Users/dchaplinsky/Projects/foobar/media/js", and specify your
files in the bundle as "js/jquery.js".

yes ASSETS_ROOT it just equals empty string. I'm still playing with webassets :) Your proposition makes more sense (assuming you accidentally wrote the /js at the end of the path ).

Better integration with staticfiles would be nice, because:

  • It's great lil' helper itself.
  • It's a part of the django from 1.3
  • I believe users of staticfiles is also interested in thing like webassets, because both projects aimed to solve basically the same task: efficient serving of static files.

I can build a small demo project which using both, webassets and staticfiles for you.

P.S. BTW, I spoke to dcramer yesterday and he said regarding issues with webassets in coffin and looks like due to some bugs of git he lost your changeset (or accidentally deleted those branch).

from webassets.

chrisdrackett avatar chrisdrackett commented on August 19, 2024

I've just run into this issue as well. I think I fall into the c) bucket. I have compass files in 2 apps that I'd like to be able to reference each other. I think this should work fine in production as collect static will move them into the same dir. But locally the files don't seem to see each other.

Just wanted to post here and make sure mine isn't a new issue. Some of this stuff is a bit over my head still :)

from webassets.

miracle2k avatar miracle2k commented on August 19, 2024

Chris, can you open a separate ticket for this? This opens up a whole bunch of new issues. The sass compiler supports multiple search paths, though the compass executable doesn't seem to; The compass filter may have to be rewritten to use the sass executable. There also needs to be a mechanism where those additional search paths can be made available to the filters by the django-assets addon.

from webassets.

chrisdrackett avatar chrisdrackett commented on August 19, 2024

@miracle2k added here: #55

from webassets.

miracle2k avatar miracle2k commented on August 19, 2024

For those interested in testing, I've implemented support for the staticfiles app in this branch:

https://github.com/miracle2k/webassets/tree/django-staticfiles

When DEBUG=True and 'django.contrib.staticfiles' in INSTALLED_APPS, then the staticfiles finders will be used to locate source files. The output file will always be written into STATIC_DIR, so in order to have these files served in debug mode,
you need to add "django_assets.finders.AssetsFinder" to the STATICFILES_FINDERS setting.

I still need to add a bunch of tests, then I'll merge it into master (pending no complaints).

from webassets.

AdrianRibao avatar AdrianRibao commented on August 19, 2024

I've been using this branch for a couple of weeks now, with compass files, and everything seems to work fine.

I hope this can be merged soon :)

Great job, thank you!

from webassets.

miracle2k avatar miracle2k commented on August 19, 2024

This is now in master.

from webassets.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.