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).

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

class boussole.finder.ScssFinder[source]

Project finder for SCSS sources

FINDER_STYLESHEET_EXTS

List of file extensions regarded as compilable stylesheet sources.

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_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

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

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

append_suffix(filepath, suffix)[source]

Change final filename by appending a suffix.

Parameters
  • filepath (str) – A file path (relative or absolute).

  • suffix (str) – Suffix to append

Returns

Filepath with the new filename.

Return type

str

change_extension(filepath, new_extension, hashid=None)[source]

Alter filename to change its file extensions and possibly a hash ID between them.

Parameters
  • filepath (str) – A file path (relative or absolute).

  • new_extension (str) – New extension name (without leading dot) to apply.

Keyword Arguments

hashid (str) – Hash ID to add between file name and extension if given.

Returns

Filepath with new extension.

Return type

str

get_destination(filepath, targetdir=None, hashid=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.

Keyword Arguments
  • targetdir (str) – If given will be added at beginning of file path.

  • hashid (str) – Hash ID to add between file name and extension if given.

Returns

Destination filepath.

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

mirror_sources(sourcedir, targetdir=None, recursive=True, excludes=[], hashid=None)[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).

  • hashid (str) – Hash ID to include into destination filenames.

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