Inspector

Inspector is in charge to inspect a project about SASS stylesheets to search for their dependencies.

class boussole.inspector.ScssInspector(*args, **kwargs)[source]

Bases: boussole.resolver.ImportPathsResolver, boussole.parser.ScssImportsParser

Project inspector for SCSS sources

Inspector is stateful, meaning you will need to invoke reset() then inspect() each time a project change, else the parents and children maps will be eventually incorrects.

__init__ method use reset method to initialize some internal buffers.

_CHILDREN_MAP

Dictionnary of finded direct children for each inspected sources.

_PARENTS_MAP

Dictionnary of finded direct parents for each inspected sources.

_get_recursive_dependancies(dependencies_map, sourcepath, recursive=True)[source]

Return all dependencies of a source, recursively searching through its dependencies.

This is a common method used by children and parents methods.

Parameters:
  • dependencies_map (dict) – Internal buffer (internal buffers _CHILDREN_MAP or _PARENTS_MAP) to use for searching.
  • sourcepath (str) – Source file path to start searching for dependencies.
Keyword Arguments:
 

recursive (bool) – Switch to enable recursive finding (if True). Default to True.

Raises:

CircularImport – If circular error is detected from a source.

Returns:

List of dependencies paths.

Return type:

set

children(sourcepath, recursive=True)[source]

Recursively find all children that are imported from the given source path.

Parameters:sourcepath (str) – Source file path to search for.
Keyword Arguments:
 recursive (bool) – Switch to enabled recursive finding (if True). Default to True.
Returns:List of finded parents path.
Return type:set
inspect(*args, **kwargs)[source]

Recursively inspect all given SCSS files to find imported dependencies.

This does not return anything. Just fill internal buffers about inspected files.

Note

This will ignore orphan files (files that are not imported from any of given SCSS files).

Parameters:*args – One or multiple arguments, each one for a source file path to inspect.
Keyword Arguments:
 library_paths (list) – List of directory paths for libraries to resolve paths if resolving fails on the base source path. Default to None.
look_source(sourcepath, library_paths=None)[source]

Open a SCSS file (sourcepath) and find all involved file through imports.

This will fill internal buffers _CHILDREN_MAP and _PARENTS_MAP.

Parameters:sourcepath (str) – Source file path to start searching for imports.
Keyword Arguments:
 library_paths (list) – List of directory paths for libraries to resolve paths if resolving fails on the base source path. Default to None.
parents(sourcepath, recursive=True)[source]

Recursively find all parents that import the given source path.

Parameters:sourcepath (str) – Source file path to search for.
Keyword Arguments:
 recursive (bool) – Switch to enabled recursive finding (if True). Default to True.
Returns:List of finded parents path.
Return type:set
reset()[source]

Reset internal buffers _CHILDREN_MAP and _PARENTS_MAP.