Edgewall Software

Changes between Version 71 and Version 72 of TracDev/PluginDevelopment


Ignore:
Timestamp:
Jun 19, 2015, 2:25:11 PM (9 years ago)
Author:
figaro
Comment:

Cosmetic changes

Legend:

Unmodified
Added
Removed
Modified
  • TracDev/PluginDevelopment

    v71 v72  
     1[[PageOutline(2-5,Contents,pullout)]]
     2
    13= Writing Plugins for Trac
    2 
    3 [[PageOutline]]
    44
    55Starting 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.
     
    77== Writing the plugin code
    88
    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:
     9To 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:
    1010
    1111{{{#!python
     
    5151These variables can also be accessed from the initializer (`__init__`) of a component.
    5252
    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.
     53Storing 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.
    5454
    5555== Single file plugins
     
    5959== Packaging plugins
    6060
    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.
     61TracPlugins 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.
    6262
    6363The 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:
     
    7777}}}
    7878
    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.
     79This 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.
    8080
    8181== !Internationalization/Localization of plugins
    8282
    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.
     83If 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.
    8684
    8785== Plugin deployment
     
    113111You can omit the `--install-dir` and `--multi-version` arguments to make the development version of your plugin available globally.
    114112
    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.
     113This 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.
    116114
    117115A tutorial to build your own plugins is available [http://trac-hacks.org/wiki/EggCookingTutorial here].