Sophie

Sophie

distrib > Mageia > 5 > i586 > by-pkgid > 27647990744ebd9cfe32398f37f67e20 > files > 2597

bzr-2.6.0-11.1.mga5.i586.rpm

<!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="Content-Type" content="text/html; charset=utf-8" />
    
    <title>API Versioning &mdash; Bazaar 2.6.0 documentation</title>
    
    <link rel="stylesheet" href="_static/default.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    './',
        VERSION:     '2.6.0',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </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>
    <link rel="shortcut icon" href="_static/bzr.ico"/>

    <link rel="top" title="Bazaar 2.6.0 documentation" href="index.html" />
    <link rel="up" title="Specifications" href="specifications.html" />
    <link rel="next" title="Bazaar Apport Integration" href="apport.html" />
    <link rel="prev" title="Revision Properties" href="revision-properties.html" />
<link rel="stylesheet" href="_static/bzr-doc.css" type="text/css" />
 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="apport.html" title="Bazaar Apport Integration"
             accesskey="N">next</a></li>
        <li class="right" >
          <a href="revision-properties.html" title="Revision Properties"
             accesskey="P">previous</a> |</li>
<li><a href="http://bazaar.canonical.com/">
    <img src="_static/bzr icon 16.png" /> Home</a>&nbsp;|&nbsp;</li>
<a href="http://doc.bazaar.canonical.com/en/">Documentation</a>&nbsp;|&nbsp;</li>

        <li><a href="index.html">Developer Document Catalog (2.6.0)</a> &raquo;</li>

          <li><a href="specifications.html" accesskey="U">Specifications</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="api-versioning">
<h1><a class="toc-backref" href="#id1">API Versioning</a><a class="headerlink" href="#api-versioning" title="Permalink to this headline">¶</a></h1>
<div class="section" id="status">
<h2><a class="toc-backref" href="#id2">Status</a><a class="headerlink" href="#status" title="Permalink to this headline">¶</a></h2>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Date:</th><td class="field-body">2007-06-26</td>
</tr>
</tbody>
</table>
<p>bzrlib has a rich API which is used both internally, and externally by
<a class="reference external" href="plugin-api.html">plugins</a> and scripts. To allow the API to change, specifically to allow
support for features and methods to be removed, without causing hard to
diagnose bugs in the clients of the API, bzrlib provides explicit API
compatibility data, and a compact API to allow scripts and plugins to
ascertain if the bzrlib they are using is compatible to the API they were
written against.</p>
<div class="contents topic" id="contents">
<p class="topic-title first">Contents</p>
<ul class="simple">
<li><a class="reference internal" href="#api-versioning" id="id1">API Versioning</a><ul>
<li><a class="reference internal" href="#status" id="id2">Status</a></li>
<li><a class="reference internal" href="#motivation" id="id3">Motivation</a></li>
<li><a class="reference internal" href="#terminology" id="id4">Terminology</a></li>
<li><a class="reference internal" href="#api-versions" id="id5">API versions</a></li>
<li><a class="reference internal" href="#managing-api-versions" id="id6">Managing API versions</a></li>
<li><a class="reference internal" href="#exported-api-s" id="id7">Exported API&#8217;s</a></li>
<li><a class="reference internal" href="#use-cases" id="id8">Use Cases</a><ul>
<li><a class="reference internal" href="#requiring-bzrlib-0-18-in-a-plugin" id="id9">Requiring bzrlib 0.18 in a plugin</a></li>
<li><a class="reference internal" href="#exporting-an-api-from-a-plugin" id="id10">Exporting an API from a plugin</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
<div class="section" id="motivation">
<h2><a class="toc-backref" href="#id3">Motivation</a><a class="headerlink" href="#motivation" title="Permalink to this headline">¶</a></h2>
<p>To allow plugins to apply their own policy for compatibility with bzrlib,
without requiring a new release on every library release. Plugins should
also be able to use the API to export their own compatibility information
for code reuse between plugins.</p>
</div>
<div class="section" id="terminology">
<h2><a class="toc-backref" href="#id4">Terminology</a><a class="headerlink" href="#terminology" title="Permalink to this headline">¶</a></h2>
<p>An <strong>API</strong> is a collection of python objects/modules/packages which can be
used by plugins and scripts. The <tt class="docutils literal"><span class="pre">bzrlib</span></tt> <strong>API</strong> covers all of bzrlib,
but we can be more precise - e.g. the <tt class="docutils literal"><span class="pre">WorkingTree</span> <span class="pre">API</span></tt>.
An <strong>API version</strong> is a tuple <tt class="docutils literal"><span class="pre">(major,</span> <span class="pre">minor,</span> <span class="pre">point)</span></tt>.</p>
</div>
<div class="section" id="api-versions">
<h2><a class="toc-backref" href="#id5">API versions</a><a class="headerlink" href="#api-versions" title="Permalink to this headline">¶</a></h2>
<p>For simplicity we treat API&#8217;s as being compatible with a range of
versions: the current release of the API, and some oldest version which is
also compatible. While we could say that there is a set of older versions
with which the current version is compatible, a range is easier to
express, and easier for a human to look at and understand, and finally
easier to manage. The oldest version with which the API for a python
object is compatible is obtained by looking up the <tt class="docutils literal"><span class="pre">api_minimum_version</span></tt>
attribute on the python object handed to <tt class="docutils literal"><span class="pre">require_api</span></tt>, and failing that
the bzrlib <tt class="docutils literal"><span class="pre">api_minimum_version</span></tt> is returned. The current version of the
API is obtained by looking for an <tt class="docutils literal"><span class="pre">api_current_version</span></tt> attribute, and
if that is not found, an <tt class="docutils literal"><span class="pre">version_info</span></tt> attribute (of which the first 3
elements are used). If no current version can be found, the bzrlib
<tt class="docutils literal"><span class="pre">version_info</span></tt> attribute is used to generate a current API version.
This lookup sequence allows users with simple setups (and no python style
<tt class="docutils literal"><span class="pre">version_info</span></tt> tuple) to still export an API version, and for new API&#8217;s
to be managed more granularly later on with a smooth transition -
everything starts off in lockstep with bzrlib&#8217;s master version.</p>
<p>API versions are compared lexically to answer the question &#8216;is
the requested version X &lt;= the current version, and &gt;= the minimum
version&#8217;.</p>
</div>
<div class="section" id="managing-api-versions">
<h2><a class="toc-backref" href="#id6">Managing API versions</a><a class="headerlink" href="#managing-api-versions" title="Permalink to this headline">¶</a></h2>
<p>The minimum API versions should be adjusted to the <strong>oldest</strong> API version
with which client code of the API will successfully run. It should not be
changed simply because of adding things in a compatible manner, or
deprecating features, but rather when errors will occur if client code is
not updated.  Versions for API&#8217;s from <tt class="docutils literal"><span class="pre">bzrlib</span></tt> are given the version
numbers that <tt class="docutils literal"><span class="pre">bzrlib</span></tt> has had for consistency. Plugins should also take
this approach and use the version numbering scheme the plugin used.</p>
</div>
<div class="section" id="exported-api-s">
<h2><a class="toc-backref" href="#id7">Exported API&#8217;s</a><a class="headerlink" href="#exported-api-s" title="Permalink to this headline">¶</a></h2>
<p>Currently we export a single API - the <tt class="docutils literal"><span class="pre">bzrlib</span> <span class="pre">API</span></tt> - and no finer
grained APIs. The API versioning support was introduced in bzrlib 0.18.
For plugins or tools that want to dynamically check for the presence of
the API versioning API, you should compare <tt class="docutils literal"><span class="pre">bzrlib.version_info[0:3]</span></tt>
with <tt class="docutils literal"><span class="pre">(0,</span> <span class="pre">18,</span> <span class="pre">0)</span></tt>.</p>
<table border="1" class="docutils">
<colgroup>
<col width="44%" />
<col width="56%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">API</th>
<th class="head">Covers</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>bzrlib</td>
<td>All of bzrlib</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="use-cases">
<h2><a class="toc-backref" href="#id8">Use Cases</a><a class="headerlink" href="#use-cases" title="Permalink to this headline">¶</a></h2>
<p>Some examples of using the API.</p>
<div class="section" id="requiring-bzrlib-0-18-in-a-plugin">
<h3><a class="toc-backref" href="#id9">Requiring bzrlib 0.18 in a plugin</a><a class="headerlink" href="#requiring-bzrlib-0-18-in-a-plugin" title="Permalink to this headline">¶</a></h3>
<p>In the plugins __init__.py:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">bzrlib</span>
<span class="kn">from</span> <span class="nn">bzrlib.api</span> <span class="kn">import</span> <span class="n">require_api</span>
<span class="kn">from</span> <span class="nn">bzrlib.errors</span> <span class="kn">import</span> <span class="n">IncompatibleAPI</span>
<span class="k">try</span><span class="p">:</span>
  <span class="n">require_api</span><span class="p">(</span><span class="n">bzrlib</span><span class="p">,</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">18</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span>
<span class="k">except</span> <span class="n">IncompatibleAPI</span><span class="p">:</span>
  <span class="k">raise</span> <span class="ne">ImportError</span><span class="p">(</span><span class="s">&quot;A bzrlib compatible with 0.18 is required.&quot;</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="exporting-an-api-from-a-plugin">
<h3><a class="toc-backref" href="#id10">Exporting an API from a plugin</a><a class="headerlink" href="#exporting-an-api-from-a-plugin" title="Permalink to this headline">¶</a></h3>
<p>In the plugin <tt class="docutils literal"><span class="pre">foo</span></tt> exporting the API (in __init__.py):</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">version_info</span> <span class="o">=</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="s">&#39;beta&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="n">api_version</span> <span class="o">=</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
</pre></div>
</div>
<p>In a plugin depending on that plugin (in __init__.py):</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">bzrlib.plugins.foo</span>
<span class="kn">from</span> <span class="nn">bzrlib.api</span> <span class="kn">import</span> <span class="n">require_api</span>
<span class="kn">from</span> <span class="nn">bzrlib.errors</span> <span class="kn">import</span> <span class="n">IncompatibleAPI</span>
<span class="k">try</span><span class="p">:</span>
  <span class="n">require_api</span><span class="p">(</span><span class="n">bzrlib</span><span class="o">.</span><span class="n">plugins</span><span class="o">.</span><span class="n">foo</span><span class="p">,</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
<span class="k">except</span> <span class="n">IncompatibleAPI</span><span class="p">:</span>
  <span class="k">raise</span> <span class="ne">ImportError</span><span class="p">(</span><span class="s">&quot;A bzrlib compatible with 0.0.1 is required.&quot;</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="index.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">API Versioning</a><ul>
<li><a class="reference internal" href="#status">Status</a></li>
<li><a class="reference internal" href="#motivation">Motivation</a></li>
<li><a class="reference internal" href="#terminology">Terminology</a></li>
<li><a class="reference internal" href="#api-versions">API versions</a></li>
<li><a class="reference internal" href="#managing-api-versions">Managing API versions</a></li>
<li><a class="reference internal" href="#exported-api-s">Exported API&#8217;s</a></li>
<li><a class="reference internal" href="#use-cases">Use Cases</a><ul>
<li><a class="reference internal" href="#requiring-bzrlib-0-18-in-a-plugin">Requiring bzrlib 0.18 in a plugin</a></li>
<li><a class="reference internal" href="#exporting-an-api-from-a-plugin">Exporting an API from a plugin</a></li>
</ul>
</li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="revision-properties.html"
                        title="previous chapter">Revision Properties</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="apport.html"
                        title="next chapter">Bazaar Apport Integration</a></p>
  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="_sources/api-versioning.txt"
           rel="nofollow">Show Source</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <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>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="apport.html" title="Bazaar Apport Integration"
             >next</a></li>
        <li class="right" >
          <a href="revision-properties.html" title="Revision Properties"
             >previous</a> |</li>
<li><a href="http://bazaar.canonical.com/">
    <img src="_static/bzr icon 16.png" /> Home</a>&nbsp;|&nbsp;</li>
<a href="http://doc.bazaar.canonical.com/en/">Documentation</a>&nbsp;|&nbsp;</li>

        <li><a href="index.html">Developer Document Catalog (2.6.0)</a> &raquo;</li>

          <li><a href="specifications.html" >Specifications</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2009-2011 Canonical Ltd.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.3.
    </div>
  </body>
</html>