django_libsass

Circular Dependency

So is the cause of my

AttributeError at /admin/login/

'module' object has no attribute 'compile'

a circular dependency within the modules?

Thie StackOverflow question shows an example of what you’d do to get :

AttributeError: 'module' object has no attribute 'blahblah'

In this case it was cause by circular dependency or mutual top-level imports. I suppose that’s a bit like causing this to happen within your files, where a calls b which calls a ….:

infinity

Let me try and see if this is what’s happening with my SassCompiler?

import sass
from compressor.filters.base import FilterBase

Sass is on my Path and Python Path (I checked by importing it in Python and then checking my sys.path).

FilterBase can be found in compressor filter’s base.py

class FilterBase(object):

def __init__(self, content, filter_type=None, filename=None, verbose=0):
 self.type = filter_type
 self.content = content
 self.verbose = verbose or settings.COMPRESS_VERBOSE
 self.logger = logger
 self.filename = filename
def input(self, **kwargs):
 raise NotImplementedError
def output(self, **kwargs):
 raise NotImplementedError

from this we see a class field FilterBase and subclass Object.

Q: What are Field Classes?

  • The first class is the Python object that your users will manipulate. They will assign it to the model attribute, they will read from it for displaying purposes, things like that.
  • The second class is the Field subclass. This is the class that knows how to convert your first class back and forth between its permanent storage form and the Python form.
Advertisements

from django_libsass import SassCompiler

Following on from the Error during Template Rendering, I still have not solved why I get a

Exception Value:
'module' object has no attribute 'compile'

as previous analyzed, I suspect it means sass is not recognized as a module. But having posted the question on StackOverflow, one of the Wagtail guys have replied :

“…Indicates that Django Compressor is trying to run django_libsass.SassCompiler as a shell command, and the script is failing to run.” – This is a red herring. Django-compressor first tries to interpret the string as a python module, and if that fails (as apparently it is doing here), it falls back on treating it as a shell command. It shouldn’t be necessary to install a command-line Sass tool to use Wagtail – the django-libsass library should be handling it entirely on the Python side.” – gasman

Looks like I’m looking at the wrong stuff then!

 

He also commented:

What error message (if any) do you get if you run from django_libsass import SassCompiler within manage.py shell? –  gasman

I went back into shell, ran

python manage.py shell

Python 2.7.6 (default, Nov 11 2013, 18:34:29)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.
(InteractiveConsole)
>>> from django_libsass import SassCompiler

Did not get any errors there, which means django_libsass and SassCompiler are both working and the errors lies elsewhere. Will have to go strain my eyes and poke at that riddle.

Error during template rendering

Picture 18

 

Error during template rendering

In template /home/username/env/lib/python2.7/site-packages/wagtail/wagtailadmin/templates/wagtailadmin/skeleton.html, error at line 20

‘module’ object has no attribute ‘compile’

 

This is what I’m stuck at now.

line 20 = {% compress css %}

in my admin skeleton.html

Which means the error links back to the Compressor.

Digging through the traceback logs reveal:

51. return compile(filename=self.filename)
File “/home/username/env/lib/python2.7/site-packages/django_libsass.py” in compile
41. return sass.compile(**kwargs)

Exception Type: AttributeError at /admin/login/
Exception Value: ‘module’ object has no attribute ‘compile’

Django_libsass is a django-compressor filter to compile SASS files using libsass, written by torchbox, the same guys who wrote Wagtail.

‘module’ object refers to sass in line 41.

either it does not recognize sass, or there is no compile class within sass for django_libsass to call and hence this error.

Possible Actions:

  1. Check dependencies and requirements are properly installed
  2. Check that django_libsass is on path and python path
  3. Find out where is sass.
  4. Do I have to pip install sass or is it within django_libsass?
  5. Find if compile is defined in sass, wherever that is
  6. See if I can run sass and compile in command line
  7. List django_libsass in settings.py as a ‘module’