Skip to content

Commit

Permalink
show the search paths in case of an import error
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipGarnero committed Jul 17, 2015
1 parent a48118f commit ee79823
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
16 changes: 9 additions & 7 deletions django_pyscss/extension/django.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from scss.extension.core import CoreExtension
from scss.source import SourceFile

from ..utils import get_file_and_storage
from ..utils import get_file_and_storage, get_searched_paths


class DjangoExtension(CoreExtension):
Expand All @@ -26,21 +26,23 @@ def handle_import(self, name, compilation, rule):

if original_path.is_absolute():
# Remove the beginning slash
search_path = original_path.relative_to('/').parent
origin = original_path.relative_to('/').parent
elif rule.source_file.origin:
search_path = rule.source_file.origin
origin = rule.source_file.origin
if original_path.parent:
search_path = search_path / original_path.parent
origin = origin / original_path.parent
else:
search_path = original_path.parent
origin = original_path.parent

basename = original_path.stem

for prefix, suffix in product(('_', ''), search_exts):
filename = PurePath(prefix + basename + suffix)

full_filename, storage = get_file_and_storage(str(search_path / filename))
full_filename, storage = get_file_and_storage(str(origin / filename))

if full_filename:
with storage.open(full_filename) as f:
return SourceFile.from_file(f, origin=search_path, relpath=filename)
return SourceFile.from_file(f, origin=origin, relpath=filename)

compilation.compiler.search_path = get_searched_paths(basename)
5 changes: 5 additions & 0 deletions django_pyscss/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,8 @@ def get_file_and_storage(filename):
if storage is None:
name, storage = get_file_from_storage(filename)
return name, storage


def get_searched_paths(filename):
finders.find(filename)
return finders.searched_locations

0 comments on commit ee79823

Please sign in to comment.