<!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>General advices and troubleshooting — Yapsy 1.10.2 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: '1.10.2', 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/yapsy-favicon.ico"/> <link rel="top" title="Yapsy 1.10.2 documentation" href="index.html" /> <link rel="prev" title="PluginManagerDecorator" href="PluginManagerDecorator.html" /> </head> <body> <div class="related"> <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="PluginManagerDecorator.html" title="PluginManagerDecorator" accesskey="P">previous</a> |</li> <li><a href="index.html">Yapsy 1.10.2 documentation</a> »</li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body"> <div class="section" id="general-advices-and-troubleshooting"> <h1>General advices and troubleshooting<a class="headerlink" href="#general-advices-and-troubleshooting" title="Permalink to this headline">¶</a></h1> <div class="contents local topic" id="contents"> <ul class="simple"> <li><a class="reference internal" href="#getting-code-samples" id="id1">Getting code samples</a></li> <li><a class="reference internal" href="#use-the-logging-system" id="id2">Use the logging system</a></li> <li><a class="reference internal" href="#categorization-by-inheritance-caveat" id="id3">Categorization by inheritance caveat</a></li> <li><a class="reference internal" href="#plugin-class-detection-caveat" id="id4">Plugin class detection caveat</a></li> <li><a class="reference internal" href="#plugin-packaging" id="id5">Plugin packaging</a></li> <li><a class="reference internal" href="#code-conventions" id="id6">Code conventions</a></li> </ul> </div> <div class="section" id="getting-code-samples"> <h2><a class="toc-backref" href="#id1">Getting code samples</a><a class="headerlink" href="#getting-code-samples" title="Permalink to this headline">¶</a></h2> <p>Yapsy is used enough for your favorite search provider to have good chances of finding some examples of yapsy being used in the wild.</p> <p>However if you wonder how a specific functionality can be used, you can also look at the corresponding unit test (in the test folder packaged with yapsy’s sources).</p> </div> <div class="section" id="use-the-logging-system"> <h2><a class="toc-backref" href="#id2">Use the logging system</a><a class="headerlink" href="#use-the-logging-system" title="Permalink to this headline">¶</a></h2> <p>Yapsy uses Python’s standard <tt class="docutils literal"><span class="pre">logging</span></tt> module to record most important events and especially plugin loading failures.</p> <p>When developping an application based on yapsy, you’ll benefit from looking at the ‘debug’ level logs, which can easily be done from your application code with the following snippet:</p> <div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">logging</span> <span class="n">logging</span><span class="o">.</span><span class="n">basicConfig</span><span class="p">(</span><span class="n">level</span><span class="o">=</span><span class="n">logging</span><span class="o">.</span><span class="n">DEBUG</span><span class="p">)</span> </pre></div> </div> <p>Also, please note that yapsy uses a named logger for all its logs, so that you can selectively activage debug logs for yapsy with the following snippet:</p> <div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">logging</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="s">'yapsy'</span><span class="p">)</span><span class="o">.</span><span class="n">setLevel</span><span class="p">(</span><span class="n">logging</span><span class="o">.</span><span class="n">DEBUG</span><span class="p">)</span> </pre></div> </div> </div> <div class="section" id="categorization-by-inheritance-caveat"> <h2><a class="toc-backref" href="#id3">Categorization by inheritance caveat</a><a class="headerlink" href="#categorization-by-inheritance-caveat" title="Permalink to this headline">¶</a></h2> <p>If your application defines various categories of plugins with the yapsy’s built-in mechanism for that, please keep in mind the following facts:</p> <blockquote> <div><ul class="simple"> <li>a plugin instance is attributed to a given category by looking if it is an instance, <em>even via a subclass</em>, of the class associated to this category;</li> <li>a plugin may be attributed to several categories.</li> </ul> </div></blockquote> <p>Considering this, and if you consider using several categories, you should consider the following tips:</p> <blockquote> <div><ul class="simple"> <li><strong>don’t associate any category to ``IPlugin``</strong> (unless you want all plugins to be attributed to the corresponding category)</li> <li><strong>design a specific subclass</strong> of <tt class="docutils literal"><span class="pre">IPlugin</span></tt> for each category</li> <li>if you want to regroup plugins of some categories into a common category: do this by attributing a subclass of <tt class="docutils literal"><span class="pre">IPlugin</span></tt> to the common category and attribute to the other categories specific subclasses to this intermediate mother class so that <strong>the plugin class inheritance hierarchy reflects the hierarchy between categories</strong> (and if you want something more complex that a hierarchy, you can consider using mixins).</li> </ul> </div></blockquote> </div> <div class="section" id="plugin-class-detection-caveat"> <h2><a class="toc-backref" href="#id4">Plugin class detection caveat</a><a class="headerlink" href="#plugin-class-detection-caveat" title="Permalink to this headline">¶</a></h2> <p>Because of the “categorization by inheritance” system, you <strong>musn’t directly import the subclass</strong> of <tt class="docutils literal"><span class="pre">IPlugin</span></tt> in the main plugin file, instead import its containing module and make your plugin class inherit from <tt class="docutils literal"><span class="pre">ContainingModule.SpecificPluginClass</span></tt> as in the following example.</p> <p>The following code won’t work (the class <tt class="docutils literal"><span class="pre">MyBasePluginClass</span></tt> will be detected as the plugin’s implementation instead of <tt class="docutils literal"><span class="pre">MyPlugin</span></tt>):</p> <div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">myapp.plugintypes</span> <span class="kn">import</span> <span class="n">MyBasePluginClass</span> <span class="k">class</span> <span class="nc">MyPlugin</span><span class="p">(</span><span class="n">MyBasePluginClass</span><span class="p">):</span> <span class="k">pass</span> </pre></div> </div> <p>Instead you should do the following:</p> <div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">myapp.plugintypes</span> <span class="kn">as</span> <span class="nn">plugintypes</span> <span class="k">class</span> <span class="nc">MyPlugin</span><span class="p">(</span><span class="n">plugintypes</span><span class="o">.</span><span class="n">MyBasePluginClass</span><span class="p">):</span> <span class="k">pass</span> </pre></div> </div> </div> <div class="section" id="plugin-packaging"> <h2><a class="toc-backref" href="#id5">Plugin packaging</a><a class="headerlink" href="#plugin-packaging" title="Permalink to this headline">¶</a></h2> <p>When packaging plugins in a distutils installer or as parts of an application (like for instance with <cite>py2exe</cite>), you may want to take care about the following points:</p> <ul class="simple"> <li>when you set specific directories where to look for plugins with a hardcoded path, be very carefully about the way you write these paths because depending on the cases <strong>using ``__file__`` or relative paths may be unreliable</strong>. For instance with py2exe, you may want to follow the tips from the <a class="reference external" href="http://www.py2exe.org/index.cgi/WhereAmI">Where Am I FAQ</a>.</li> <li>you’d should either <strong>package the plugins as plain Python modules or data files</strong> (if you want to consider you application as the only module), either using the dedicated <cite>setup</cite> argument for <cite>py2exe</cite> or using distutils’ <cite>MANIFEST.in</cite></li> <li>if you do package the plugins as data files, <strong>make sure that their dependencies are correctly indicated as dependencies of your package</strong> (or packaged with you application if you use <cite>py2exe</cite>).</li> </ul> <p>See also a more detailed example for py2exe on <a class="reference external" href="http://notinthestars.blogspot.com.es/2011/04/using-python-plugin-scripts-with-py2exe.html">Simon on Tech’s Using python plugin scripts with py2exe</a>.</p> </div> <div class="section" id="code-conventions"> <h2><a class="toc-backref" href="#id6">Code conventions</a><a class="headerlink" href="#code-conventions" title="Permalink to this headline">¶</a></h2> <p>If you intend to modify yapsy’s sources and to contribute patches back, please respect the following conventions:</p> <ul class="simple"> <li>CamelCase (upper camel case) for class names and functions</li> <li>camelCase (lower camel case) for methods</li> <li>UPPERCASE for global variables (with a few exceptions)</li> <li>tabulations are used for indentation (and not spaces !)</li> <li>unit-test each new functionality</li> </ul> </div> </div> </div> </div> </div> <div class="sphinxsidebar"> <div class="sphinxsidebarwrapper"> <p class="logo"><a href="index.html"> <img class="logo" src="_static/yapsy-big.png" alt="Logo"/> </a></p> <h3><a href="index.html">Table Of Contents</a></h3> <ul> <li><a class="reference internal" href="#">General advices and troubleshooting</a><ul> <li><a class="reference internal" href="#getting-code-samples">Getting code samples</a></li> <li><a class="reference internal" href="#use-the-logging-system">Use the logging system</a></li> <li><a class="reference internal" href="#categorization-by-inheritance-caveat">Categorization by inheritance caveat</a></li> <li><a class="reference internal" href="#plugin-class-detection-caveat">Plugin class detection caveat</a></li> <li><a class="reference internal" href="#plugin-packaging">Plugin packaging</a></li> <li><a class="reference internal" href="#code-conventions">Code conventions</a></li> </ul> </li> </ul> <h4>Previous topic</h4> <p class="topless"><a href="PluginManagerDecorator.html" title="previous chapter">PluginManagerDecorator</a></p> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="_sources/Advices.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="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="PluginManagerDecorator.html" title="PluginManagerDecorator" >previous</a> |</li> <li><a href="index.html">Yapsy 1.10.2 documentation</a> »</li> </ul> </div> <div class="footer"> © Copyright 2010-2013, Thibauld Nion. Last updated on Oct 05, 2013. Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3. </div> </body> </html>