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) – Project settings.
inspector (boussole.inspector.ScssInspector) – Inspector instance.
- settings¶
Filled from argument.
- logger¶
Boussole logger.
- Type
logging.Logger
- inspector¶
Filled from argument.
- finder¶
Finder instance.
- compiler¶
Sass compile helper object.
- 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 toFalse
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 methodImportPathsResolver.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
orwatchdog.events.FileModifiedEvent
.
- on_created(event)[source]¶
Called when a new file or directory is created.
- Parameters
event – Watchdog event, either
watchdog.events.DirCreatedEvent
orwatchdog.events.FileCreatedEvent
.
- 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.
- 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.