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, logger, 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.
- logger (logging.Logger) – Logger object to write messages.
- inspector (boussole.inspector.ScssInspector) – Inspector instance.
-
settings
¶ boussole.conf.model.Settings
Filled from argument.
-
logger
¶ logging.Logger
Filled from argument.
-
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 toFalse
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.
- Todo:
- This should be also used (extended from another class?) to watch for some special name file (like ”.boussole-watcher-stop” create to raise a KeyboardInterrupt, so we may be able to unittest the watcher (click.CliRunner is not able to send signal like CTRL+C that is required to watchdog observer loop)
Parameters: event – Watchdog event, either watchdog.events.DirCreatedEvent
orwatchdog.events.FileCreatedEvent
.
-
on_deleted
(event)[source]¶ Called when a file or directory is deleted.
- Todo:
- Bugged with inspector and sass compiler since the does not exists anymore.
Parameters: event – Watchdog event, watchdog.events.DirDeletedEvent
orwatchdog.events.FileDeletedEvent
.
-
on_modified
(event)[source]¶ Called when a file or directory is modified.
Parameters: event – Watchdog event, watchdog.events.DirModifiedEvent
orwatchdog.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
orwatchdog.events.FileModifiedEvent
.
-
class
boussole.watcher.
SassProjectEventHandler
(settings, logger, inspector, *args, **kwargs)[source]¶ Bases:
boussole.watcher.SassLibraryEventHandler
Watch mixin handler for project sources.
Warning
DO NOT use project 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.
-
class
boussole.watcher.
WatchdogLibraryEventHandler
(settings, logger, inspector, *args, **kwargs)[source]¶ Bases:
boussole.watcher.SassLibraryEventHandler
,watchdog.events.PatternMatchingEventHandler
Watchdog event handler for library sources
-
class
boussole.watcher.
WatchdogProjectEventHandler
(settings, logger, inspector, *args, **kwargs)[source]¶ Bases:
boussole.watcher.SassProjectEventHandler
,watchdog.events.PatternMatchingEventHandler
Watchdog event handler for project sources.
Warning
DO NOT use project handler to watch libraries, there is a risk the compiler will try to compile their sources in a wrong directory.