/usr/share/doc/python-setuptools-doc/html/python3.html is in python-setuptools-doc 39.0.1-2.
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 | <!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>Supporting both Python 2 and Python 3 with Setuptools — Python documentation</title>
<link rel="stylesheet" href="_static/nature.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: '',
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" title="Search" href="search.html" />
<link rel="next" title="Development on Setuptools" href="development.html" />
<link rel="prev" title="Package Discovery and Resource Access using pkg_resources" href="pkg_resources.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="development.html" title="Development on Setuptools"
accesskey="N">next</a></li>
<li class="right" >
<a href="pkg_resources.html" title="Package Discovery and Resource Access using pkg_resources"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Python documentation</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="supporting-both-python-2-and-python-3-with-setuptools">
<h1>Supporting both Python 2 and Python 3 with Setuptools<a class="headerlink" href="#supporting-both-python-2-and-python-3-with-setuptools" title="Permalink to this headline">¶</a></h1>
<p>Starting with Distribute version 0.6.2 and Setuptools 0.7, the Setuptools
project supported Python 3. Installing and
using setuptools for Python 3 code works exactly the same as for Python 2
code.</p>
<p>Setuptools provides a facility to invoke 2to3 on the code as a part of the
build process, by setting the keyword parameter <code class="docutils literal"><span class="pre">use_2to3</span></code> to True, but
the Setuptools strongly recommends instead developing a unified codebase
using <a class="reference external" href="https://pypi.python.org/pypi/six">six</a>,
<a class="reference external" href="https://pypi.python.org/pypi/future">future</a>, or another compatibility
library.</p>
<div class="section" id="using-2to3">
<h2>Using 2to3<a class="headerlink" href="#using-2to3" title="Permalink to this headline">¶</a></h2>
<p>Setuptools attempts to make the porting process easier by automatically
running
2to3 as a part of running tests. To do so, you need to configure the
setup.py so that you can run the unit tests with <code class="docutils literal"><span class="pre">python</span> <span class="pre">setup.py</span> <span class="pre">test</span></code>.</p>
<p>See <a class="reference internal" href="setuptools.html#test"><span class="std std-ref">test - Build package and run a unittest suite</span></a> for more information on this.</p>
<p>Once you have the tests running under Python 2, you can add the use_2to3
keyword parameters to setup(), and start running the tests under Python 3.
The test command will now first run the build command during which the code
will be converted with 2to3, and the tests will then be run from the build
directory, as opposed from the source directory as is normally done.</p>
<p>Setuptools will convert all Python files, and also all doctests in Python
files. However, if you have doctests located in separate text files, these
will not automatically be converted. By adding them to the
<code class="docutils literal"><span class="pre">convert_2to3_doctests</span></code> keyword parameter Setuptools will convert them as
well.</p>
<p>By default, the conversion uses all fixers in the <code class="docutils literal"><span class="pre">lib2to3.fixers</span></code> package.
To use additional fixers, the parameter <code class="docutils literal"><span class="pre">use_2to3_fixers</span></code> can be set
to a list of names of packages containing fixers. To exclude fixers, the
parameter <code class="docutils literal"><span class="pre">use_2to3_exclude_fixers</span></code> can be set to fixer names to be
skipped.</p>
<p>An example setup.py might look something like this:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">setuptools</span> <span class="k">import</span> <span class="n">setup</span>
<span class="n">setup</span><span class="p">(</span>
<span class="n">name</span><span class="o">=</span><span class="s1">'your.module'</span><span class="p">,</span>
<span class="n">version</span><span class="o">=</span><span class="s1">'1.0'</span><span class="p">,</span>
<span class="n">description</span><span class="o">=</span><span class="s1">'This is your awesome module'</span><span class="p">,</span>
<span class="n">author</span><span class="o">=</span><span class="s1">'You'</span><span class="p">,</span>
<span class="n">author_email</span><span class="o">=</span><span class="s1">'your@email'</span><span class="p">,</span>
<span class="n">package_dir</span><span class="o">=</span><span class="p">{</span><span class="s1">''</span><span class="p">:</span> <span class="s1">'src'</span><span class="p">},</span>
<span class="n">packages</span><span class="o">=</span><span class="p">[</span><span class="s1">'your'</span><span class="p">,</span> <span class="s1">'you.module'</span><span class="p">],</span>
<span class="n">test_suite</span><span class="o">=</span><span class="s1">'your.module.tests'</span><span class="p">,</span>
<span class="n">use_2to3</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
<span class="n">convert_2to3_doctests</span><span class="o">=</span><span class="p">[</span><span class="s1">'src/your/module/README.txt'</span><span class="p">],</span>
<span class="n">use_2to3_fixers</span><span class="o">=</span><span class="p">[</span><span class="s1">'your.fixers'</span><span class="p">],</span>
<span class="n">use_2to3_exclude_fixers</span><span class="o">=</span><span class="p">[</span><span class="s1">'lib2to3.fixes.fix_import'</span><span class="p">],</span>
<span class="p">)</span>
</pre></div>
</div>
<div class="section" id="differential-conversion">
<h3>Differential conversion<a class="headerlink" href="#differential-conversion" title="Permalink to this headline">¶</a></h3>
<p>Note that a file will only be copied and converted during the build process
if the source file has been changed. If you add a file to the doctests
that should be converted, it will not be converted the next time you run
the tests, since it hasn’t been modified. You need to remove it from the
build directory. Also if you run the build, install or test commands before
adding the use_2to3 parameter, you will have to remove the build directory
before you run the test command, as the files otherwise will seem updated,
and no conversion will happen.</p>
<p>In general, if code doesn’t seem to be converted, deleting the build directory
and trying again is a good safeguard against the build directory getting
“out of sync” with the source directory.</p>
</div>
</div>
<div class="section" id="distributing-python-3-modules">
<h2>Distributing Python 3 modules<a class="headerlink" href="#distributing-python-3-modules" title="Permalink to this headline">¶</a></h2>
<p>You can distribute your modules with Python 3 support in different ways. A
normal source distribution will work, but can be slow in installing, as the
2to3 process will be run during the install. But you can also distribute
the module in binary format, such as a binary egg. That egg will contain the
already converted code, and hence no 2to3 conversion is needed during install.</p>
</div>
<div class="section" id="advanced-features">
<h2>Advanced features<a class="headerlink" href="#advanced-features" title="Permalink to this headline">¶</a></h2>
<p>If you don’t want to run the 2to3 conversion on the doctests in Python files,
you can turn that off by setting <code class="docutils literal"><span class="pre">setuptools.use_2to3_on_doctests</span> <span class="pre">=</span> <span class="pre">False</span></code>.</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="#">Supporting both Python 2 and Python 3 with Setuptools</a><ul>
<li><a class="reference internal" href="#using-2to3">Using 2to3</a><ul>
<li><a class="reference internal" href="#differential-conversion">Differential conversion</a></li>
</ul>
</li>
<li><a class="reference internal" href="#distributing-python-3-modules">Distributing Python 3 modules</a></li>
<li><a class="reference internal" href="#advanced-features">Advanced features</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="pkg_resources.html"
title="previous chapter">Package Discovery and Resource Access using <code class="docutils literal"><span class="pre">pkg_resources</span></code></a></p>
<h4>Next topic</h4>
<p class="topless"><a href="development.html"
title="next chapter">Development on Setuptools</a></p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/python3.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="development.html" title="Development on Setuptools"
>next</a></li>
<li class="right" >
<a href="pkg_resources.html" title="Package Discovery and Resource Access using pkg_resources"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Python documentation</a> »</li>
</ul>
</div>
<div class="footer" role="contentinfo">
© Copyright .
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.6.7.
</div>
</body>
</html>
|