Changes between Version 71 and Version 72 of TracDev/PluginDevelopment
- Timestamp:
- Jun 19, 2015, 2:25:11 PM (9 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
TracDev/PluginDevelopment
v71 v72 1 [[PageOutline(2-5,Contents,pullout)]] 2 1 3 = Writing Plugins for Trac 2 3 [[PageOutline]]4 4 5 5 Starting with version [milestone:0.9 0.9], you can develop plugins for Trac that extend the builtin functionality. The plugin functionality is based on the [wiki:TracDev/ComponentArchitecture component architecture], so please read that document before continuing here. For more information, not covered here, see TracDev. … … 7 7 == Writing the plugin code 8 8 9 To extend Trac with a custom plugin, you need to implement a ''component''. For example, to add a new web module to Trac (i.e. a component that handles HTTP requests and extends the navigation bar), you'd start with something like the following code:9 To extend Trac with custom functionality, you need to implement a '''component'''. For example, to add a new web module to Trac (i.e. a component that handles HTTP requests and extends the navigation bar), you would start with something like the following: 10 10 11 11 {{{#!python … … 51 51 These variables can also be accessed from the initializer (`__init__`) of a component. 52 52 53 Storing any other objects as instance variables of your component is probably a bad idea: remember that a component is only instantiated once for a given environment ; unless your plugin is used in a CGI deployment of Trac, that means that the same component instance will get invoked for multiple HTTP requests; if the server is multi-threaded, this will even happen concurrently.53 Storing any other objects as instance variables of your component is probably a bad idea: remember that a component is only instantiated once for a given environment. Unless your plugin is used in a CGI deployment of Trac, that means that the same component instance will get invoked for multiple HTTP requests; if the server is multi-threaded, this will even happen concurrently. 54 54 55 55 == Single file plugins … … 59 59 == Packaging plugins 60 60 61 TracPlugins are packaged as [http://peak.telecommunity.com/DevCenter/PythonEggs Python Eggs]. You can use [https://pythonhosted.org/setuptools/setuptools.html setuptools] to make a `setup.py` script that will produce a Python egg for your plugin.61 TracPlugins are packaged as [http://peak.telecommunity.com/DevCenter/PythonEggs Python eggs]. You can use [https://pythonhosted.org/setuptools/setuptools.html setuptools] to make a `setup.py` script that will produce a Python egg for your plugin. 62 62 63 63 The egg needs to export an [https://pythonhosted.org/setuptools/setuptools.html#dynamic-discovery-of-services-and-plugins entry points] group named `trac.plugins`, listing the names of the modules that Trac should import for the plugin-provided components to get registered. For example: … … 77 77 }}} 78 78 79 This assumes that the `HelloWorldPlugin` example above is defined in the module `helloworld.py` in the `myplugs` package. The entry point ''name'' (in this example “helloworld”) is required by the Python egg runtime, but not currently used by Trac. In most cases, you can simply use the qualified module name there.79 This assumes that the `HelloWorldPlugin` example above is defined in the module `helloworld.py` in the `myplugs` package. The entry point ''name'' (in this example "helloworld") is required by the Python egg runtime, but not currently used by Trac. In most cases, you can simply use the qualified module name there. 80 80 81 81 == !Internationalization/Localization of plugins 82 82 83 '' relevant since trac-0.12 introduced i18n/l10n support for Trac utilizing Babel'' 84 85 See the [wiki:CookBook/PluginL10N plugin i18n/l10n cookbook page] for details. 83 If you plan on supporting your plugin for i18n/l10n, see the [wiki:CookBook/PluginL10N plugin i18n/l10n cookbook page] for details. Support for i18n/l10n has been introduced since Trac 0.12 and uses Babel. 86 84 87 85 == Plugin deployment … … 113 111 You can omit the `--install-dir` and `--multi-version` arguments to make the development version of your plugin available globally. 114 112 115 This will install an `.egg-link` file instead of the actual egg. That file is basically a link to the source directory of your plugin, so that Trac will always see the latest version of your code. In this case you will have to explicitly enable your plugin in the trac configuration as explained on TracPlugins.113 This will install an `.egg-link` file instead of the actual egg. That file is basically a link to the source directory of your plugin, so that Trac will always see the latest version of your code. In this case you will have to explicitly enable your plugin in the Trac configuration as explained on TracPlugins. 116 114 117 115 A tutorial to build your own plugins is available [http://trac-hacks.org/wiki/EggCookingTutorial here].