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
- absolute (bool) –
Returned paths will be absolute using
-
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
- filepath (str) – A file path. The path is allways relative to
sources directory. If not relative,
-
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 wherestart
is a list. The most relevant item frompaths
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 nofilepath
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 isTrue
(partial sources fail matchind condition). SeeFinder.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, elseFalse
.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)
. Wheretarget
is thesource
path but renamed with.css
extension. Relative directory from source dir is left unchanged but if given, returned paths will be absolute (usingsourcedir
for sources andtargetdir
for targets).Return type: list
- absolute (bool) –
Returned paths will be absolute using
-
-
boussole.finder.
path_parts_cmp
(x, y)[source]¶ Path comparison for
sorted()
.We just split paths on separator ‘/’ to have the biggest path parts length.
Note
TODO: Using hardcoded separator ‘/’ wont work on window FS, better should get the separator from os(.path?).
Parameters: - x (str) – First path to compare on.
- y (str) – Second path to compare to.
Returns: Negative, zero or positive number depending on whether the first argument is considered smaller than, equal to, or larger than the second argument.
Return type: int