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

Filled from argument.

Type

boussole.conf.model.Settings

logger

Boussole logger.

Type

logging.Logger

inspector

Filled from argument.

Type

boussole.inspector.ScssInspector

finder

Finder instance.

Type

boussole.finder.ScssFinder

compiler

Sass compile helper object.

Type

boussole.compiler.SassCompileHelper

compilable_files

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

Type

dict

source_files

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

Type

list

_event_error

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

Type

bool

is_valid_event(event)[source]

Check if given event is valid event for index method.

An event is considered valid if event type is supported (from SassLibraryEventHandler.SUPPORTED_EVENTS) and file is allowed (from method ImportPathsResolver.is_allowed_source).

Parameters

event (watchdog.events.FileSystemEvent) – Watchdog file system event.

Returns

True if valid, else False.

Return type

bool

index(event)[source]

Reset inspector buffers and index project sources dependencies.

This have to be executed each time an event occurs.

Parameters

event (watchdog.events.FileSystemEvent) – Watchdog file system event.

Returns

True if allowed, else False.

Return type

bool

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 stopped without blocking or breaking watchdog observer.

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

compile_dependencies(sourcepath, include_self=False)[source]

Register source(s) for compile and possibly its 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 added to items to compile, else only its dependencies are compiled.

on_any_event(event)[source]

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

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

Parameters

event – Watchdog event watchdog.events.FileSystemEvent.

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.

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_modified(event)[source]

Called when a file or directory is modified.

Parameters

event – Watchdog event, watchdog.events.DirModifiedEvent or watchdog.events.FileModifiedEvent.

on_deleted(event)[source]

Called when a file or directory is deleted.

Parameters

event – Watchdog event, watchdog.events.DirDeletedEvent or watchdog.events.FileDeletedEvent.

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

Bases: SassLibraryEventHandler

Watch mixin handler for project sources.

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

Warning

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

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: SassLibraryEventHandler, PatternMatchingEventHandler

Watchdog event handler for library sources

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

Bases: SassProjectEventHandler, PatternMatchingEventHandler

Watchdog event handler for project sources.

Warning

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