@@ -195,9 +195,19 @@ def _to_bytes(obj):
195
195
196
196
197
197
def _importer_callback_wrapper (func ):
198
+ if PY2 :
199
+ argspec = inspect .getargspec (func )
200
+ else :
201
+ argspec = inspect .getfullargspec (func )
202
+
203
+ num_args = len (argspec .args )
204
+
198
205
@functools .wraps (func )
199
- def inner (path ):
200
- ret = func (path .decode ('UTF-8' ))
206
+ def inner (path , prev ):
207
+ if num_args == 2 :
208
+ ret = func (path .decode ('UTF-8' ), prev .decode ('UTF-8' ))
209
+ else :
210
+ ret = func (path .decode ('UTF-8' ))
201
211
return _normalize_importer_return_value (ret )
202
212
return inner
203
213
@@ -477,8 +487,10 @@ def func_name(a, b):
477
487
A priority of zero is acceptable; priority determines the order callbacks
478
488
are attempted.
479
489
480
- These callbacks must accept a single string argument representing the path
481
- passed to the ``@import`` directive, and either return ``None`` to
490
+ These callbacks can accept one or two string arguments. The first argument
491
+ is the path that was passed to the ``@import`` directive; the second
492
+ (optional) argument is the previous resolved path, where the ``@import``
493
+ directive was found. The callbacks must either return ``None`` to
482
494
indicate the path wasn't handled by that callback (to continue with others
483
495
or fall back on internal ``libsass`` filesystem behaviour) or a list of
484
496
one or more tuples, each in one of three forms:
@@ -494,7 +506,7 @@ def func_name(a, b):
494
506
495
507
.. code-block:: python
496
508
497
- def my_importer(path):
509
+ def my_importer(path, prev ):
498
510
return [(path, '#' + path + ' { color: red; }')]
499
511
500
512
sass.compile(
@@ -530,6 +542,10 @@ def my_importer(path):
530
542
Added ``source_map_contents``, ``source_map_embed``,
531
543
``omit_source_map_url``, and ``source_map_root`` parameters.
532
544
545
+ .. versionadded:: 0.18.0
546
+ The importer callbacks can now take a second argument, the previously-
547
+ resolved path, so that importers can do relative path resolution.
548
+
533
549
"""
534
550
modes = set ()
535
551
for mode_name in MODES :
0 commit comments