<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="X-UA-Compatible" content="IE=Edge" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Writing a plugin — Bazaar 2.7.0 documentation</title> <link rel="stylesheet" href="../_static/classic.css" type="text/css" /> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script> <script type="text/javascript" src="../_static/jquery.js"></script> <script type="text/javascript" src="../_static/underscore.js"></script> <script type="text/javascript" src="../_static/doctools.js"></script> <script type="text/javascript" src="../_static/language_data.js"></script> <link rel="shortcut icon" href="../_static/bzr.ico"/> <link rel="search" title="Search" href="../search.html" /> <link rel="next" title="Licence" href="licence.html" /> <link rel="prev" title="Serving Bazaar with Apache" href="http_smart_server.html" /> </head><body> <div class="related" role="navigation" aria-label="related navigation"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="licence.html" title="Licence" accesskey="N">next</a></li> <li class="right" > <a href="http_smart_server.html" title="Serving Bazaar with Apache" accesskey="P">previous</a> |</li> <li><a href="http://bazaar.canonical.com/"> <img src="../_static/bzr icon 16.png" /> Home</a> | </li> <a href="http://doc.bazaar.canonical.com/en/">Documentation</a> | </li> <li class="nav-item nav-item-0"><a href="../index.html">Table of Contents (2.7.0)</a> »</li> <li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Bazaar User Guide</a> »</li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body" role="main"> <div class="section" id="writing-a-plugin"> <h1>Writing a plugin<a class="headerlink" href="#writing-a-plugin" title="Permalink to this headline">¶</a></h1> <div class="section" id="introduction"> <h2>Introduction<a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h2> <p>Plugins are very similar to bzr core functionality. They can import anything in bzrlib. A plugin may simply override standard functionality, but most plugins supply new commands.</p> </div> <div class="section" id="creating-a-new-command"> <h2>Creating a new command<a class="headerlink" href="#creating-a-new-command" title="Permalink to this headline">¶</a></h2> <p>To create a command, make a new object that derives from <code class="docutils literal notranslate"><span class="pre">bzrlib.commands.Command</span></code>, and name it <code class="docutils literal notranslate"><span class="pre">cmd_foo</span></code>, where foo is the name of your command. If you create a command whose name contains an underscore, it will appear in the UI with the underscore turned into a hyphen. For example, <cite>cmd_baz_import</cite> will appear as <cite>baz-import</cite>. For examples of how to write commands, please see <code class="docutils literal notranslate"><span class="pre">builtins.py</span></code>.</p> <p>Once you’ve created a command you must register the command with <code class="docutils literal notranslate"><span class="pre">bzrlib.commands.register_command(cmd_foo)</span></code>. You must register the command when your file is imported, otherwise bzr will not see it.</p> </div> <div class="section" id="installing-a-hook"> <h2>Installing a hook<a class="headerlink" href="#installing-a-hook" title="Permalink to this headline">¶</a></h2> <p>See <a class="reference external" href="hooks.txt">Using hooks</a>.</p> <blockquote> <div></div></blockquote> </div> <div class="section" id="specifying-a-plugin-version-number"> <h2>Specifying a plugin version number<a class="headerlink" href="#specifying-a-plugin-version-number" title="Permalink to this headline">¶</a></h2> <p>Simply define <code class="docutils literal notranslate"><span class="pre">version_info</span></code> to be a tuple defining the current version number of your plugin. eg. <code class="docutils literal notranslate"><span class="pre">version_info</span> <span class="pre">=</span> <span class="pre">(0,</span> <span class="pre">9,</span> <span class="pre">0)</span></code> <code class="docutils literal notranslate"><span class="pre">version_info</span> <span class="pre">=</span> <span class="pre">(0,</span> <span class="pre">9,</span> <span class="pre">0,</span> <span class="pre">'dev',</span> <span class="pre">0)</span></code></p> </div> <div class="section" id="plugin-searching-rules"> <h2>Plugin searching rules<a class="headerlink" href="#plugin-searching-rules" title="Permalink to this headline">¶</a></h2> <p>Bzr will scan <code class="docutils literal notranslate"><span class="pre">~/.bazaar/plugins</span></code> and <code class="docutils literal notranslate"><span class="pre">bzrlib/plugins</span></code> for plugins by default. You can override this with <code class="docutils literal notranslate"><span class="pre">BZR_PLUGIN_PATH</span></code> (see <a class="reference external" href="../user-reference/configuration-help.html#bzr-plugin-path">User Reference</a> for details).</p> <p>Plugins may be either modules or packages. If your plugin is a single file, you can structure it as a module. If it has multiple files, or if you want to distribute it as a bzr branch, you should structure it as a package, i.e. a directory with an <code class="docutils literal notranslate"><span class="pre">__init__.py</span></code> file.</p> </div> <div class="section" id="more-information"> <h2>More information<a class="headerlink" href="#more-information" title="Permalink to this headline">¶</a></h2> <p>Please feel free to contribute your plugin to BzrTools, if you think it would be useful to other people.</p> <p>See the <a class="reference external" href="../developer-guide/HACKING.html">Bazaar Developer Guide</a> for details on Bazaar’s development guidelines and policies.</p> </div> </div> </div> </div> </div> <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> <div class="sphinxsidebarwrapper"> <h3><a href="../index.html">Table of Contents</a></h3> <ul> <li><a class="reference internal" href="#">Writing a plugin</a><ul> <li><a class="reference internal" href="#introduction">Introduction</a></li> <li><a class="reference internal" href="#creating-a-new-command">Creating a new command</a></li> <li><a class="reference internal" href="#installing-a-hook">Installing a hook</a></li> <li><a class="reference internal" href="#specifying-a-plugin-version-number">Specifying a plugin version number</a></li> <li><a class="reference internal" href="#plugin-searching-rules">Plugin searching rules</a></li> <li><a class="reference internal" href="#more-information">More information</a></li> </ul> </li> </ul> <h4>Previous topic</h4> <p class="topless"><a href="http_smart_server.html" title="previous chapter">Serving Bazaar with Apache</a></p> <h4>Next topic</h4> <p class="topless"><a href="licence.html" title="next chapter">Licence</a></p> <div role="note" aria-label="source link"> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="../_sources/user-guide/writing_a_plugin.txt" rel="nofollow">Show Source</a></li> </ul> </div> <div id="searchbox" style="display: none" role="search"> <h3>Quick search</h3> <div class="searchformwrapper"> <form class="search" action="../search.html" method="get"> <input type="text" name="q" /> <input type="submit" value="Go" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> </div> </div> <script type="text/javascript">$('#searchbox').show(0);</script> </div> </div> <div class="clearer"></div> </div> <div class="related" role="navigation" aria-label="related navigation"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="licence.html" title="Licence" >next</a></li> <li class="right" > <a href="http_smart_server.html" title="Serving Bazaar with Apache" >previous</a> |</li> <li><a href="http://bazaar.canonical.com/"> <img src="../_static/bzr icon 16.png" /> Home</a> | </li> <a href="http://doc.bazaar.canonical.com/en/">Documentation</a> | </li> <li class="nav-item nav-item-0"><a href="../index.html">Table of Contents (2.7.0)</a> »</li> <li class="nav-item nav-item-1"><a href="index.html" >Bazaar User Guide</a> »</li> </ul> </div> <div class="footer" role="contentinfo"> © Copyright 2009-2011 Canonical Ltd. Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.8.4. </div> </body> </html>