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: ImportPathsResolver, 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.

parsers

Dictionnary of available Sass format parsers, where key is the file extension related to the format and value is a parser instance.

get_parser(path)[source]

Returns parser depending of extension from given file path.

Parameters

path (str) – Path to split to find extension which will select the right parser. If file path does not have any extension or does not match any enabled extension, scss will be assumed on default.

Returns

Either ScssImportsParser or SassImportsParser instance depending of filepath.

Return type

parser

reset()[source]

Reset internal buffers _CHILDREN_MAP and _PARENTS_MAP.

look_source(sourcepath, library_paths=None)[source]

Open a SCSS file (sourcepath) and find all involved files from import rules.

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.

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.

_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

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