/usr/share/doc/python-kitchen-doc/html/hacking.html is in python-kitchen-doc 1.2.5-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 | <!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" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Conventions for contributing to kitchen — kitchen 1.2.5 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">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: '1.2.5',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: '.txt'
};
</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="search" type="application/opensearchdescription+xml"
title="Search within kitchen 1.2.5 documentation"
href="_static/opensearch.xml"/>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Glossary" href="glossary.html" />
<link rel="prev" title="1.0.0 Porting Guide" href="porting-guide-0.3.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="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="glossary.html" title="Glossary"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="porting-guide-0.3.html" title="1.0.0 Porting Guide"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">kitchen 1.2.5 documentation</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="conventions-for-contributing-to-kitchen">
<h1>Conventions for contributing to kitchen<a class="headerlink" href="#conventions-for-contributing-to-kitchen" title="Permalink to this headline">¶</a></h1>
<div class="section" id="style">
<h2>Style<a class="headerlink" href="#style" title="Permalink to this headline">¶</a></h2>
<ul class="simple">
<li>Strive to be <span class="target" id="index-0"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0008"><strong>PEP 8</strong></a> compliant</li>
<li>Run <cite>:command:`pylint</cite> ` over the code and try to resolve most of its nitpicking</li>
</ul>
</div>
<div class="section" id="python-2-4-compatibility">
<h2>Python 2.4 compatibility<a class="headerlink" href="#python-2-4-compatibility" title="Permalink to this headline">¶</a></h2>
<p>At the moment, we’re supporting python-2.4 and above. Understand that there’s
a lot of python features that we cannot use because of this.</p>
<p>Sometimes modules in the <a class="reference external" href="http://docs.python.org/library">python standard library</a> can be added to kitchen so that they’re
available. When we do that we need to be careful of several things:</p>
<ol class="arabic simple">
<li>Keep the module in sync with the version in the python-2.x trunk. Use
<code class="file docutils literal"><span class="pre">maintainers/sync-copied-files.py</span></code> for this.</li>
<li>Sync the unittests as well as the module.</li>
<li>Be aware that not all modules are written to remain compatible with
Python-2.4 and might use python language features that were not present
then (generator expressions, relative imports, decorators, with, try: with
both except: and finally:, etc) These are not good candidates for
importing into kitchen as they require more work to keep synced.</li>
</ol>
</div>
<div class="section" id="unittests">
<h2>Unittests<a class="headerlink" href="#unittests" title="Permalink to this headline">¶</a></h2>
<ul>
<li><p class="first">At least smoketest your code (make sure a function will return expected
values for one set of inputs).</p>
</li>
<li><p class="first">Note that even 100% coverage is not a guarantee of working code! Good tests
will realize that you need to also give multiple inputs that test the code
paths of called functions that are outside of your code. Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">to_unicode</span><span class="p">(</span><span class="n">msg</span><span class="p">,</span> <span class="n">encoding</span><span class="o">=</span><span class="s1">'utf8'</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="s1">'replace'</span><span class="p">):</span>
<span class="k">return</span> <span class="nb">unicode</span><span class="p">(</span><span class="n">msg</span><span class="p">,</span> <span class="n">encoding</span><span class="p">,</span> <span class="n">errors</span><span class="p">)</span>
<span class="c1"># Smoketest only. This will give 100% coverage for your code (it</span>
<span class="c1"># tests all of the code inside of to_unicode) but it leaves a lot of</span>
<span class="c1"># room for errors as it doesn't test all combinations of arguments</span>
<span class="c1"># that are then passed to the unicode() function.</span>
<span class="n">tools</span><span class="o">.</span><span class="n">ok_</span><span class="p">(</span><span class="n">to_unicode</span><span class="p">(</span><span class="s1">'abc'</span><span class="p">)</span> <span class="o">==</span> <span class="sa">u</span><span class="s1">'abc'</span><span class="p">)</span>
<span class="c1"># Better -- tests now cover non-ascii characters and that error conditions</span>
<span class="c1"># occur properly. There's a lot of other permutations that can be</span>
<span class="c1"># added along these same lines.</span>
<span class="n">tools</span><span class="o">.</span><span class="n">ok_</span><span class="p">(</span><span class="n">to_unicode</span><span class="p">(</span><span class="sa">u</span><span class="s1">'café'</span><span class="p">,</span> <span class="s1">'utf8'</span><span class="p">,</span> <span class="s1">'replace'</span><span class="p">))</span>
<span class="n">tools</span><span class="o">.</span><span class="n">assert_raises</span><span class="p">(</span><span class="ne">UnicodeError</span><span class="p">,</span> <span class="n">to_unicode</span><span class="p">,</span> <span class="p">[</span><span class="sa">u</span><span class="s1">'cafè ñunru'</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s1">'latin1'</span><span class="p">)])</span>
</pre></div>
</div>
</li>
<li><p class="first">We’re using nose for unittesting. Rather than depend on unittest2
functionality, use the functions that nose provides.</p>
</li>
<li><p class="first">Remember to maintain python-2.4 compatibility even in unittests.</p>
</li>
</ul>
</div>
<div class="section" id="docstrings-and-documentation">
<h2>Docstrings and documentation<a class="headerlink" href="#docstrings-and-documentation" title="Permalink to this headline">¶</a></h2>
<p>We use sphinx to build our documentation. We use the sphinx autodoc extension
to pull docstrings out of the modules for API documentation. This means that
docstrings for subpackages and modules should follow a certain pattern. The
general structure is:</p>
<ul class="simple">
<li>Introductory material about a module in the module’s top level docstring.<ul>
<li>Introductory material should begin with a level two title: an overbar and
underbar of ‘-‘.</li>
</ul>
</li>
<li>docstrings for every function.<ul>
<li>The first line is a short summary of what the function does</li>
<li>This is followed by a blank line</li>
<li>The next lines are a <cite>field list
<http://sphinx.pocoo.org/markup/desc.html#info-field-lists>_</cite> giving
information about the function’s signature. We use the keywords:
<code class="docutils literal"><span class="pre">arg</span></code>, <code class="docutils literal"><span class="pre">kwarg</span></code>, <code class="docutils literal"><span class="pre">raises</span></code>, <code class="docutils literal"><span class="pre">returns</span></code>, and sometimes <code class="docutils literal"><span class="pre">rtype</span></code>. Use
these to describe all arguments, key word arguments, exceptions raised,
and return values using these.<ul>
<li>Parameters that are <code class="docutils literal"><span class="pre">kwarg</span></code> should specify what their default
behaviour is.</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="kitchen-versioning">
<span id="id1"></span><h2>Kitchen versioning<a class="headerlink" href="#kitchen-versioning" title="Permalink to this headline">¶</a></h2>
<p>Currently the kitchen library is in early stages of development. While we’re
in this state, the main kitchen library uses the following pattern for version
information:</p>
<ul class="simple">
<li><dl class="first docutils">
<dt>Versions look like this::</dt>
<dd>__version_info__ = ((0, 1, 2),)
__version__ = ‘0.1.2’</dd>
</dl>
</li>
<li>The Major version number remains at 0 until we decide to make the first 1.0
release of kitchen. At that point, we’re declaring that we have some
confidence that we won’t need to break backwards compatibility for a while.</li>
<li>The Minor version increments for any backwards incompatible API changes.
When this is updated, we reset micro to zero.</li>
<li>The Micro version increments for any other changes (backwards compatible API
changes, pure bugfixes, etc).</li>
</ul>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Versioning is only updated for releases that generate sdists and new
uploads to the download directory. Usually we update the version
information for the library just before release. By contrast, we update
kitchen <a class="reference internal" href="#subpackage-versioning"><span class="std std-ref">Versioning</span></a> when an API change is made. When in
doubt, look at the version information in the last release.</p>
</div>
</div>
<div class="section" id="i18n">
<h2>I18N<a class="headerlink" href="#i18n" title="Permalink to this headline">¶</a></h2>
<p>All strings that are used as feedback for users need to be translated.
<code class="xref py py-mod docutils literal"><span class="pre">kitchen</span></code> sets up several functions for this. <code class="xref py py-func docutils literal"><span class="pre">_()</span></code> is used for
marking things that are shown to users via print, GUIs, or other “standard”
methods. Strings for exceptions are marked with <code class="xref py py-func docutils literal"><span class="pre">b_()</span></code>. This function
returns a byte <code class="xref py py-class docutils literal"><span class="pre">str</span></code> which is needed for use with exceptions:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">kitchen</span> <span class="kn">import</span> <span class="n">_</span><span class="p">,</span> <span class="n">b_</span>
<span class="k">def</span> <span class="nf">print_message</span><span class="p">(</span><span class="n">msg</span><span class="p">,</span> <span class="n">username</span><span class="p">):</span>
<span class="k">print</span> <span class="n">_</span><span class="p">(</span><span class="s1">'</span><span class="si">%(user)s</span><span class="s1">, your message of the day is: </span><span class="si">%(message)s</span><span class="s1">'</span><span class="p">)</span> <span class="o">%</span> <span class="p">{</span>
<span class="s1">'message'</span><span class="p">:</span> <span class="n">msg</span><span class="p">,</span> <span class="s1">'user'</span><span class="p">:</span> <span class="n">username</span><span class="p">}</span>
<span class="k">raise</span> <span class="ne">Exception</span> <span class="n">b_</span><span class="p">(</span><span class="s1">'Test message'</span><span class="p">)</span>
</pre></div>
</div>
<p>This serves several purposes:</p>
<ul class="simple">
<li>It marks the strings to be extracted by an xgettext-like program.</li>
<li><code class="xref py py-func docutils literal"><span class="pre">_()</span></code> is a function that will substitute available translations at
runtime.</li>
</ul>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">By using the <code class="docutils literal"><span class="pre">%()s</span> <span class="pre">with</span> <span class="pre">dict</span></code> style of string formatting, we make this
string friendly to translators that may need to reorder the variables when
they’re translating the string.</p>
</div>
<p><cite>paver <http://www.blueskyonmars.com/projects/paver/>_</cite> and <cite>babel
<http://babel.edgewall.org/>_</cite> are used to extract the strings.</p>
</div>
<div class="section" id="api-updates">
<h2>API updates<a class="headerlink" href="#api-updates" title="Permalink to this headline">¶</a></h2>
<p>Kitchen strives to have a long deprecation cycle so that people have time to
switch away from any APIs that we decide to discard. Discarded APIs should
raise a <code class="xref py py-exc docutils literal"><span class="pre">DeprecationWarning</span></code> and clearly state in the warning message and
the docstring how to convert old code to use the new interface. An example of
deprecating a function:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">warnings</span>
<span class="kn">from</span> <span class="nn">kitchen</span> <span class="kn">import</span> <span class="n">_</span>
<span class="kn">from</span> <span class="nn">kitchen.text.converters</span> <span class="kn">import</span> <span class="n">to_bytes</span><span class="p">,</span> <span class="n">to_unicode</span>
<span class="kn">from</span> <span class="nn">kitchen.text.new_module</span> <span class="kn">import</span> <span class="n">new_function</span>
<span class="k">def</span> <span class="nf">old_function</span><span class="p">(</span><span class="n">param</span><span class="p">):</span>
<span class="sd">'''**Deprecated**</span>
<span class="sd"> This function is deprecated. Use</span>
<span class="sd"> :func:`kitchen.text.new_module.new_function` instead. If you want</span>
<span class="sd"> unicode strngs as output, switch to::</span>
<span class="sd"> >>> from kitchen.text.new_module import new_function</span>
<span class="sd"> >>> output = new_function(param)</span>
<span class="sd"> If you want byte strings, use::</span>
<span class="sd"> >>> from kitchen.text.new_module import new_function</span>
<span class="sd"> >>> from kitchen.text.converters import to_bytes</span>
<span class="sd"> >>> output = to_bytes(new_function(param))</span>
<span class="sd"> '''</span>
<span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="n">_</span><span class="p">(</span><span class="s1">'kitchen.text.old_function is deprecated. Use'</span>
<span class="s1">' kitchen.text.new_module.new_function instead'</span><span class="p">),</span>
<span class="ne">DeprecationWarning</span><span class="p">,</span> <span class="n">stacklevel</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
<span class="n">as_unicode</span> <span class="o">=</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">param</span><span class="p">,</span> <span class="nb">unicode</span><span class="p">)</span>
<span class="n">message</span> <span class="o">=</span> <span class="n">new_function</span><span class="p">(</span><span class="n">to_unicode</span><span class="p">(</span><span class="n">param</span><span class="p">))</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">as_unicode</span><span class="p">:</span>
<span class="n">message</span> <span class="o">=</span> <span class="n">to_bytes</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>
<span class="k">return</span> <span class="n">message</span>
</pre></div>
</div>
<p>If a particular API change is very intrusive, it may be better to create a new
version of the subpackage and ship both the old version and the new version.</p>
</div>
<div class="section" id="news-file">
<h2>NEWS file<a class="headerlink" href="#news-file" title="Permalink to this headline">¶</a></h2>
<p>Update the <code class="file docutils literal"><span class="pre">NEWS</span></code> file when you make a change that will be visible to
the users. This is not a ChangeLog file so we don’t need to list absolutely
everything but it should give the user an idea of how this version differs
from prior versions. API changes should be listed here explicitly. bugfixes
can be more general:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="o">-----</span>
<span class="mf">0.2</span><span class="o">.</span><span class="mi">0</span>
<span class="o">-----</span>
<span class="o">*</span> <span class="n">Relicense</span> <span class="n">to</span> <span class="n">LGPLv2</span><span class="o">+</span>
<span class="o">*</span> <span class="n">Add</span> <span class="n">kitchen</span><span class="o">.</span><span class="n">text</span><span class="o">.</span><span class="n">format</span> <span class="n">module</span> <span class="k">with</span> <span class="n">the</span> <span class="n">following</span> <span class="n">functions</span><span class="p">:</span>
<span class="n">textual_width</span><span class="p">,</span> <span class="n">textual_width_chop</span><span class="o">.</span>
<span class="o">*</span> <span class="n">Rename</span> <span class="n">the</span> <span class="n">kitchen</span><span class="o">.</span><span class="n">text</span><span class="o">.</span><span class="n">utils</span> <span class="n">module</span> <span class="n">to</span> <span class="n">kitchen</span><span class="o">.</span><span class="n">text</span><span class="o">.</span><span class="n">misc</span><span class="o">.</span> <span class="n">use</span> <span class="n">of</span> <span class="n">the</span>
<span class="n">old</span> <span class="n">names</span> <span class="ow">is</span> <span class="n">deprecated</span> <span class="n">but</span> <span class="n">still</span> <span class="n">available</span><span class="o">.</span>
<span class="o">*</span> <span class="n">bugfixes</span> <span class="n">applied</span> <span class="n">to</span> <span class="n">kitchen</span><span class="o">.</span><span class="n">pycompat24</span><span class="o">.</span><span class="n">defaultdict</span> <span class="n">that</span> <span class="n">fixes</span> <span class="n">some</span>
<span class="n">tracebacks</span>
</pre></div>
</div>
</div>
<div class="section" id="kitchen-subpackages">
<h2>Kitchen subpackages<a class="headerlink" href="#kitchen-subpackages" title="Permalink to this headline">¶</a></h2>
<p>Kitchen itself is a namespace. The kitchen sdist (tarball) provides certain
useful subpackages.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<dl class="last docutils">
<dt><a class="reference internal" href="#kitchen-addon-packages">Kitchen addon packages</a></dt>
<dd>For information about subpackages not distributed in the kitchen sdist
that install into the kitchen namespace.</dd>
</dl>
</div>
<div class="section" id="versioning">
<span id="subpackage-versioning"></span><h3>Versioning<a class="headerlink" href="#versioning" title="Permalink to this headline">¶</a></h3>
<p>Each subpackage should have its own version information which is independent
of the other kitchen subpackages and the main kitchen library version. This is
used so that code that depends on kitchen APIs can check the version
information. The standard way to do this is to put something like this in the
subpackage’s <code class="file docutils literal"><span class="pre">__init__.py</span></code>:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">kitchen.versioning</span> <span class="kn">import</span> <span class="n">version_tuple_to_string</span>
<span class="n">__version_info__</span> <span class="o">=</span> <span class="p">((</span><span class="mi">1</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="n">__version__</span> <span class="o">=</span> <span class="n">version_tuple_to_string</span><span class="p">(</span><span class="n">__version_info__</span><span class="p">)</span>
</pre></div>
</div>
<p><code class="xref py py-attr docutils literal"><span class="pre">__version_info__</span></code> is documented in <a class="reference internal" href="api-versioning.html#module-kitchen.versioning" title="kitchen.versioning"><code class="xref py py-mod docutils literal"><span class="pre">kitchen.versioning</span></code></a>. The
values of the first tuple should describe API changes to the module. There
are at least three numbers present in the tuple: (Major, minor, micro). The
major version number is for backwards incompatible changes (For
instance, removing a function, or adding a new mandatory argument to
a function). Whenever one of these occurs, you should increment the major
number and reset minor and micro to zero. The second number is the minor
version. Anytime new but backwards compatible changes are introduced this
number should be incremented and the micro version number reset to zero. The
micro version should be incremented when a change is made that does not change
the API at all. This is a common case for bugfixes, for instance.</p>
<p>Version information beyond the first three parts of the first tuple may be
useful for versioning but semantically have similar meaning to the micro
version.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">We update the <code class="xref py py-attr docutils literal"><span class="pre">__version_info__</span></code> tuple when the API is updated.
This way there’s less chance of forgetting to update the API version when
a new release is made. However, we try to only increment the version
numbers a single step for any release. So if kitchen-0.1.0 has
kitchen.text.__version__ == ‘1.0.1’, kitchen-0.1.1 should have
kitchen.text.__version__ == ‘1.0.2’ or ‘1.1.0’ or ‘2.0.0’.</p>
</div>
</div>
<div class="section" id="criteria-for-subpackages-in-kitchen">
<h3>Criteria for subpackages in kitchen<a class="headerlink" href="#criteria-for-subpackages-in-kitchen" title="Permalink to this headline">¶</a></h3>
<p>Subpackages within kitchen should meet these criteria:</p>
<ul>
<li><p class="first">Generally useful or needed for other pieces of kitchen.</p>
</li>
<li><p class="first">No mandatory requirements outside of the <a class="reference external" href="http://docs.python.org/library">python standard library</a>.</p>
<ul class="simple">
<li>Optional requirements from outside the <a class="reference external" href="http://docs.python.org/library">python standard library</a> are allowed. Things with
mandatory requirements are better placed in <a class="reference internal" href="#kitchen-addon-packages">kitchen addon packages</a></li>
</ul>
</li>
<li><p class="first">Somewhat API stable – this is not a hard requirement. We can change the
kitchen api. However, it is better not to as people may come to depend on
it.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#api-updates">API Updates</a></p>
</div>
</li>
</ul>
</div>
</div>
<div class="section" id="kitchen-addon-packages">
<h2>Kitchen addon packages<a class="headerlink" href="#kitchen-addon-packages" title="Permalink to this headline">¶</a></h2>
<p>Addon packages are very similar to subpackages integrated into the kitchen
sdist. This section just lists some of the differences to watch out for.</p>
<div class="section" id="setup-py">
<h3>setup.py<a class="headerlink" href="#setup-py" title="Permalink to this headline">¶</a></h3>
<p>Your <code class="file docutils literal"><span class="pre">setup.py</span></code> should contain entries like this:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="c1"># It's suggested to use a dotted name like this so the package is easily</span>
<span class="c1"># findable on pypi:</span>
<span class="n">setup</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">'kitchen.config'</span><span class="p">,</span>
<span class="c1"># Include kitchen in the keywords, again, for searching on pypi</span>
<span class="n">keywords</span><span class="o">=</span><span class="p">[</span><span class="s1">'kitchen'</span><span class="p">,</span> <span class="s1">'configuration'</span><span class="p">],</span>
<span class="c1"># This package lives in the directory kitchen/config</span>
<span class="n">packages</span><span class="o">=</span><span class="p">[</span><span class="s1">'kitchen.config'</span><span class="p">],</span>
<span class="c1"># [...]</span>
<span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="package-directory-layout">
<h3>Package directory layout<a class="headerlink" href="#package-directory-layout" title="Permalink to this headline">¶</a></h3>
<p>Create a <code class="file docutils literal"><span class="pre">kitchen</span></code> directory in the toplevel. Place the addon
subpackage in there. For example:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="o">./</span> <span class="o"><==</span> <span class="n">toplevel</span> <span class="k">with</span> <span class="n">README</span><span class="p">,</span> <span class="n">setup</span><span class="o">.</span><span class="n">py</span><span class="p">,</span> <span class="n">NEWS</span><span class="p">,</span> <span class="n">etc</span>
<span class="n">kitchen</span><span class="o">/</span>
<span class="n">kitchen</span><span class="o">/</span><span class="fm">__init__</span><span class="o">.</span><span class="n">py</span>
<span class="n">kitchen</span><span class="o">/</span><span class="n">config</span><span class="o">/</span> <span class="o"><==</span> <span class="n">subpackage</span> <span class="n">directory</span>
<span class="n">kitchen</span><span class="o">/</span><span class="n">config</span><span class="o">/</span><span class="fm">__init__</span><span class="o">.</span><span class="n">py</span>
</pre></div>
</div>
</div>
<div class="section" id="fake-kitchen-module">
<h3>Fake kitchen module<a class="headerlink" href="#fake-kitchen-module" title="Permalink to this headline">¶</a></h3>
<p>The :file::<cite>__init__.py</cite> in the <code class="file docutils literal"><span class="pre">kitchen</span></code> directory is special. It
won’t be installed. It just needs to pull in the kitchen from the system so
that you are able to test your module. You should be able to use this
boilerplate:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="c1"># Fake module. This is not installed, It's just made to import the real</span>
<span class="c1"># kitchen modules for testing this module</span>
<span class="kn">import</span> <span class="nn">pkgutil</span>
<span class="c1"># Extend the __path__ with everything in the real kitchen module</span>
<span class="n">__path__</span> <span class="o">=</span> <span class="n">pkgutil</span><span class="o">.</span><span class="n">extend_path</span><span class="p">(</span><span class="n">__path__</span><span class="p">,</span> <span class="vm">__name__</span><span class="p">)</span>
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last"><code class="xref py py-mod docutils literal"><span class="pre">kitchen</span></code> needs to be findable by python for this to work. Installed
in the <code class="file docutils literal"><span class="pre">site-packages</span></code> directory or adding it to the
<span class="target" id="index-1"></span><code class="xref std std-envvar docutils literal"><span class="pre">PYTHONPATH</span></code> will work.</p>
</div>
<p>Your unittests should now be able to find both your submodule and the main
kitchen module.</p>
</div>
<div class="section" id="id2">
<h3>Versioning<a class="headerlink" href="#id2" title="Permalink to this headline">¶</a></h3>
<p>It is recommended that addon packages version similarly to
<a class="reference internal" href="#subpackage-versioning"><span class="std std-ref">Versioning</span></a>. The <code class="xref py py-data docutils literal"><span class="pre">__version_info__</span></code> and
<code class="xref py py-data docutils literal"><span class="pre">__version__</span></code> strings can be changed independently of the version
exposed by setup.py so that you have both an API version
(<code class="xref py py-data docutils literal"><span class="pre">__version_info__</span></code>) and release version that’s easier for people to
parse. However, you aren’t required to do this and you could follow
a different methodology if you want (for instance, <a class="reference internal" href="#kitchen-versioning"><span class="std std-ref">Kitchen versioning</span></a>)</p>
</div>
</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="#">Conventions for contributing to kitchen</a><ul>
<li><a class="reference internal" href="#style">Style</a></li>
<li><a class="reference internal" href="#python-2-4-compatibility">Python 2.4 compatibility</a></li>
<li><a class="reference internal" href="#unittests">Unittests</a></li>
<li><a class="reference internal" href="#docstrings-and-documentation">Docstrings and documentation</a></li>
<li><a class="reference internal" href="#kitchen-versioning">Kitchen versioning</a></li>
<li><a class="reference internal" href="#i18n">I18N</a></li>
<li><a class="reference internal" href="#api-updates">API updates</a></li>
<li><a class="reference internal" href="#news-file">NEWS file</a></li>
<li><a class="reference internal" href="#kitchen-subpackages">Kitchen subpackages</a><ul>
<li><a class="reference internal" href="#versioning">Versioning</a></li>
<li><a class="reference internal" href="#criteria-for-subpackages-in-kitchen">Criteria for subpackages in kitchen</a></li>
</ul>
</li>
<li><a class="reference internal" href="#kitchen-addon-packages">Kitchen addon packages</a><ul>
<li><a class="reference internal" href="#setup-py">setup.py</a></li>
<li><a class="reference internal" href="#package-directory-layout">Package directory layout</a></li>
<li><a class="reference internal" href="#fake-kitchen-module">Fake kitchen module</a></li>
<li><a class="reference internal" href="#id2">Versioning</a></li>
</ul>
</li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="porting-guide-0.3.html"
title="previous chapter">1.0.0 Porting Guide</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="glossary.html"
title="next chapter">Glossary</a></p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/hacking.rst.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<div><input type="text" name="q" /></div>
<div><input type="submit" value="Go" /></div>
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</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="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="glossary.html" title="Glossary"
>next</a> |</li>
<li class="right" >
<a href="porting-guide-0.3.html" title="1.0.0 Porting Guide"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">kitchen 1.2.5 documentation</a> »</li>
</ul>
</div>
<div class="footer" role="contentinfo">
© Copyright 2017 Red Hat, Inc. and others.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.6.5.
</div>
</body>
</html>
|