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

Show the search paths in case of an import error #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions django_pyscss/extension/django.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,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 @@ -29,19 +29,21 @@ 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 = os.path.normpath(str(search_path / original_path.parent))
origin = os.path.normpath(str(origin / original_path.parent))
else:
search_path = original_path.parent
origin = original_path.parent

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