Finder

Finder is in charge to find main Sass stylesheets files to compile to CSS files, meaning it will ignore all partials Sass stylesheets (see Sass partials Reference).

class boussole.finder.ScssFinder[source]

Project finder for SCSS sources

FINDER_STYLESHEET_EXTS

List of file extensions regarded as compilable stylesheet sources.

change_extension(filepath, new_extension)[source]

Change final filename extension.

Parameters:
  • filepath (str) – A file path (relative or absolute).
  • new_extension (str) – New extension name (without leading dot) to apply.
Returns:

Filepath with new extension.

Return type:

str

compilable_sources(sourcedir, absolute=False, recursive=True, excludes=[])[source]

Find all scss sources that should be compiled, aka all sources that are not “partials” Sass sources.

Parameters:

sourcedir (str) – Directory path to scan.

Keyword Arguments:
 
  • absolute (bool) – Returned paths will be absolute using sourcedir argument (if True), else return relative paths.
  • recursive (bool) – Switch to enabled recursive finding (if True). Default to True.
  • excludes (list) – A list of excluding patterns (glob patterns). Patterns are matched against the relative filepath (from its sourcedir).
Returns:

List of source paths.

Return type:

list

get_destination(filepath, targetdir=None)[source]

Return destination path from given source file path.

Destination is allways a file with extension .css.

Parameters:
  • filepath (str) – A file path. The path is allways relative to sources directory. If not relative, targetdir won’t be joined.
  • absolute (bool) – If given will be added at beginning of file path.
Returns:

Destination filepath.

Return type:

str

get_relative_from_paths(filepath, paths)[source]

Find the relative filepath from the most relevant multiple paths.

This is somewhat like a os.path.relpath(path[, start]) but where start is a list. The most relevant item from paths will be used to apply the relative transform.

Parameters:
  • filepath (str) – Path to transform to relative.
  • paths (list) – List of absolute paths to use to find and remove the start path from filepath argument. If there is multiple path starting with the same directories, the biggest will match.
Raises:
  • boussole.exception.FinderException – If no filepath start could
  • be finded.
Returns:

Relative filepath where the start coming from paths is

removed.

Return type:

str

is_allowed(filepath, excludes=[])[source]

Check from exclude patterns if a relative filepath is allowed

Parameters:filepath (str) – A relative file path. (exclude patterns are allways based from the source directory).
Keyword Arguments:
 excludes (list) – A list of excluding (glob) patterns. If filepath matchs one of patterns, filepath is not allowed.
Raises:boussole.exception.FinderException – If given filepath is absolute.
Returns:Filepath with new extension.
Return type:str
is_partial(filepath)[source]

Check if file is a Sass partial source (see Sass partials Reference).

Parameters:
  • filepath (str) – A file path. Can be absolute, relative or just a
  • filename.
Returns:

True if file is a partial source, else False.

Return type:

bool

match_conditions(filepath, sourcedir=None, nopartial=True, exclude_patterns=[], excluded_libdirs=[])[source]

Find if a filepath match all required conditions.

Available conditions are (in order):

  • Is allowed file extension;
  • Is a partial source;
  • Is from an excluded directory;
  • Is matching an exclude pattern;
Parameters:

filepath (str) – Absolute filepath to match against conditions.

Keyword Arguments:
 
  • sourcedir (str or None) – Absolute sources directory path. Can be None but then the exclude_patterns won’t be matched against (because this method require to distinguish source dir from lib dirs).
  • nopartial (bool) – Accept partial sources if False. Default is True (partial sources fail matchind condition). See Finder.is_partial().
  • exclude_patterns (list) – List of glob patterns, if filepath match one these pattern, it wont match conditions. See Finder.is_allowed().
  • excluded_libdirs (list) – A list of directory to match against filepath, if filepath starts with one them, it won’t match condtions.
Returns:

True if match all conditions, else False.

Return type:

bool

mirror_sources(sourcedir, targetdir=None, recursive=True, excludes=[])[source]

Mirroring compilable sources filepaths to their targets.

Parameters:

sourcedir (str) – Directory path to scan.

Keyword Arguments:
 
  • absolute (bool) – Returned paths will be absolute using sourcedir argument (if True), else return relative paths.
  • recursive (bool) – Switch to enabled recursive finding (if True). Default to True.
  • excludes (list) – A list of excluding patterns (glob patterns). Patterns are matched against the relative filepath (from its sourcedir).
Returns:

A list of pairs (source, target). Where target is the

source path but renamed with .css extension. Relative directory from source dir is left unchanged but if given, returned paths will be absolute (using sourcedir for sources and targetdir for targets).

Return type:

list

boussole.finder.paths_by_depth(paths)[source]

Sort list of paths by number of directories in it

Parameters:paths (iterable) – iterable containing paths (str)
Return type:list