Source watcher

Watcher is almost isolated from command line code because it runs in an infinite loop, so note that handlers directly output some informations on a logging.logger.

class boussole.watcher.SassLibraryEventHandler(settings, inspector, *args, **kwargs)[source]

Bases: object

Watch mixin handler for library sources

Handler does not compile source which triggered an event, only its parent dependencies. Because libraries are not intended to be compiled.

Parameters:
settings

boussole.conf.model.Settings – Filled from argument.

logger

logging.Logger – Boussole logger.

inspector

boussole.inspector.ScssInspector – Filled from argument.

finder

boussole.finder.ScssFinder – Finder instance.

compiler

boussole.compiler.SassCompileHelper – Sass compile helper object.

compilable_files

dict – Pair of (source path, destination path) to compile. Automatically update from index() method.

source_files

list – List of source path to compile. Automatically update from index() method.

_event_error

bool – Internal flag setted to True if error has occured within an event. index() will reboot it to False each time a new event occurs.

compile_dependencies(sourcepath, include_self=False)[source]

Apply compile on all dependencies

Parameters:sourcepath (string) – Sass source path to compile to its destination using project settings.
Keyword Arguments:
 include_self (bool) – If True the given sourcepath is add to items to compile, else only its dependencies are compiled.
compile_source(sourcepath)[source]

Compile source to its destination

Check if the source is eligible to compile (not partial and allowed from exclude patterns)

Parameters:sourcepath (string) – Sass source path to compile to its destination using project settings.
Returns:
A pair of (sourcepath, destination), if source has
been compiled (or at least tried). If the source was not eligible to compile, return will be None.
Return type:tuple or None
index()[source]

Reset inspector buffers and index project sources dependencies.

This have to be executed each time an event occurs.

Note

If a Boussole exception occurs during operation, it will be catched and an error flag will be set to True so event operation will be blocked without blocking or breaking watchdog observer.

on_any_event(event)[source]

Catch-all event handler (moved, created, deleted, changed).

Before any event, index project to have the right and current dependencies map.

Parameters:event – Watchdog event watchdog.events.FileSystemEvent.
on_created(event)[source]

Called when a new file or directory is created.

Parameters:event – Watchdog event, either watchdog.events.DirCreatedEvent or watchdog.events.FileCreatedEvent.
on_deleted(event)[source]

Called when a file or directory is deleted.

Parameters:event – Watchdog event, watchdog.events.DirDeletedEvent or watchdog.events.FileDeletedEvent.
on_modified(event)[source]

Called when a file or directory is modified.

Parameters:event – Watchdog event, watchdog.events.DirModifiedEvent or watchdog.events.FileModifiedEvent.
on_moved(event)[source]

Called when a file or a directory is moved or renamed.

Many editors don’t directly change a file, instead they make a transitional file like *.part then move it to the final filename.

Parameters:event – Watchdog event, either watchdog.events.DirMovedEvent or watchdog.events.FileModifiedEvent.
class boussole.watcher.SassProjectEventHandler(settings, inspector, *args, **kwargs)[source]

Bases: boussole.watcher.SassLibraryEventHandler

Watch mixin handler for project sources.

Warning

DO NOT use this handler to watch libraries, there is a risk the compiler will try to compile their sources in a wrong directory.

Source that trigger event is compiled (if eligible) with its dependencies.

compile_dependencies(sourcepath, include_self=True)[source]

Same as inherit method but the default value for keyword argument ìnclude_self is True.

class boussole.watcher.WatchdogLibraryEventHandler(settings, inspector, *args, **kwargs)[source]

Bases: boussole.watcher.SassLibraryEventHandler, watchdog.events.PatternMatchingEventHandler

Watchdog event handler for library sources

class boussole.watcher.WatchdogProjectEventHandler(settings, inspector, *args, **kwargs)[source]

Bases: boussole.watcher.SassProjectEventHandler, watchdog.events.PatternMatchingEventHandler

Watchdog event handler for project sources.

Warning

DO NOT use this handler to watch libraries, there is a risk the compiler will try to compile their sources in a wrong directory.