Prev Up Next
Plugins Plugins Import Filters

Plugin Configuration

On startup, Sketch searches for plugins on the plugin path. Every Python source file found is scanned for configuration information. Later, when the the plugin is needed it is imported.

The plugin path is a list of directories stored in Sketch.config.plugin_path. The directory names should be absolute pathnames. Sketch uses a notation borrowed from the kpathsea library (which is used by many TeX programs to search files):

The configuration information is a series of Python statements (assignments), each on its own line, between the lines '###Sketch Config' and `###End'.

One of the assignments must be to a variable named `type'. This specifies the type of the plugin (import filter, plugin object, etc.).

Another variable that may be used in the future, is `version' which will be used to specify the version of the plugin-config conventions used (not the version of the plugin itself).

Other variable names are type dependent.

Each of the lines may be commented out.

###Sketch Config
#type = Import
#class_name = 'SKLoader'
#rx_magic = '^##Sketch 1 *(?P<minor>[0-9]+)'
#tk_file_type = ('Sketch Document', '.sk')
format_name = 'SK-1'

Sketch uses this method--instead of importing every plugin module and requiring that they register themselves with the plugin manager--to avoid loading unnecessary modules.

Implementation Note: currently Sketch reads the lines between `###Sketch Config' and `###End' into a single string (after removing the initial `#'s if present) and exec's it with a globals dictionary containing the predefined plugin types and an empty locals dictionary which receives all the variables. A consequence of this approach is that it is currently possible to use arbitrary Python statements and not just assignments. Don't rely on this, it could be changed in the future.

Plugins Plugins Import Filters
Prev Up Next