diff --git a/django_pyscss/extension/django.py b/django_pyscss/extension/django.py index c388940..ed1ea72 100644 --- a/django_pyscss/extension/django.py +++ b/django_pyscss/extension/django.py @@ -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): @@ -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) diff --git a/django_pyscss/utils.py b/django_pyscss/utils.py index e4222c0..fd16922 100644 --- a/django_pyscss/utils.py +++ b/django_pyscss/utils.py @@ -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