Merge lp:~mitya57/ubuntu-packaging-guide/add-python into lp:ubuntu-packaging-guide

Proposed by Dmitry Shachnev
Status: Merged
Merged at revision: 122
Proposed branch: lp:~mitya57/ubuntu-packaging-guide/add-python
Merge into: lp:ubuntu-packaging-guide
Diff against target: 251 lines (+211/-0)
5 files modified
debian/changelog (+3/-0)
themes/ubuntu/layout.html (+1/-0)
themes/ubuntu/static/pygments.css (+62/-0)
ubuntu-packaging-guide/index.rst (+1/-0)
ubuntu-packaging-guide/python-packaging.rst (+144/-0)
To merge this branch: bzr merge lp:~mitya57/ubuntu-packaging-guide/add-python
Reviewer Review Type Date Requested Status
Ubuntu Packaging Guide Team Pending
Review via email: mp+117875@code.launchpad.net

Description of the change

Added article "Packaging Python modules and apps" (python-packaging.rst).

Initially it was based on http://wiki.ubuntu.com/PackagingGuide/Python, but that page was very outdated, so I've rewritten it almost from scratch.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2012-07-08 06:59:21 +0000
3+++ debian/changelog 2012-08-02 12:13:22 +0000
4@@ -27,6 +27,9 @@
5 process). (LP: #996096)
6 * Refer to the backports process (LP: #1017984).
7
8+ [ Dmitry Shachnev ]
9+ * Add python-packaging.rst (LP: #702008)
10+
11 -- Daniel Holbach <daniel.holbach@ubuntu.com> Wed, 06 Jun 2012 09:28:00 +0200
12
13 ubuntu-packaging-guide (0.1) quantal; urgency=low
14
15=== modified file 'themes/ubuntu/layout.html'
16--- themes/ubuntu/layout.html 2012-05-16 18:21:30 +0000
17+++ themes/ubuntu/layout.html 2012-08-02 12:13:22 +0000
18@@ -67,6 +67,7 @@
19 <link rel="stylesheet" href="{{ pathto('_static/960.css', 1) }}" type="text/css" />
20 <link rel="stylesheet" href="{{ pathto('_static/base.css', 1) }}" type="text/css" />
21 <link rel="stylesheet" href="{{ pathto('_static/home.css', 1) }}" type="text/css" />
22+ <link rel="stylesheet" href="{{ pathto('_static/pygments.css', 1) }}" type="text/css" />
23 {%- for cssfile in css_files %}
24 <link rel="stylesheet" href="{{ pathto(cssfile, 1) }}" type="text/css" />
25 {%- endfor %}
26
27=== added file 'themes/ubuntu/static/pygments.css'
28--- themes/ubuntu/static/pygments.css 1970-01-01 00:00:00 +0000
29+++ themes/ubuntu/static/pygments.css 2012-08-02 12:13:22 +0000
30@@ -0,0 +1,62 @@
31+.highlight .hll { background-color: #ffffcc }
32+.highlight { background: #f8f8f8; }
33+.highlight .c { color: #408080; font-style: italic } /* Comment */
34+.highlight .err { border: 1px solid #FF0000 } /* Error */
35+.highlight .k { color: #008000; font-weight: bold } /* Keyword */
36+.highlight .o { color: #666666 } /* Operator */
37+.highlight .cm { color: #408080; font-style: italic } /* Comment.Multiline */
38+.highlight .cp { color: #BC7A00 } /* Comment.Preproc */
39+.highlight .c1 { color: #408080; font-style: italic } /* Comment.Single */
40+.highlight .cs { color: #408080; font-style: italic } /* Comment.Special */
41+.highlight .gd { color: #A00000 } /* Generic.Deleted */
42+.highlight .ge { font-style: italic } /* Generic.Emph */
43+.highlight .gr { color: #FF0000 } /* Generic.Error */
44+.highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */
45+.highlight .gi { color: #00A000 } /* Generic.Inserted */
46+.highlight .go { color: #808080 } /* Generic.Output */
47+.highlight .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
48+.highlight .gs { font-weight: bold } /* Generic.Strong */
49+.highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
50+.highlight .gt { color: #0040D0 } /* Generic.Traceback */
51+.highlight .kc { color: #008000; font-weight: bold } /* Keyword.Constant */
52+.highlight .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */
53+.highlight .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */
54+.highlight .kp { color: #008000 } /* Keyword.Pseudo */
55+.highlight .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */
56+.highlight .kt { color: #B00040 } /* Keyword.Type */
57+.highlight .m { color: #666666 } /* Literal.Number */
58+.highlight .s { color: #BA2121 } /* Literal.String */
59+.highlight .na { color: #7D9029 } /* Name.Attribute */
60+.highlight .nb { color: #008000 } /* Name.Builtin */
61+.highlight .nc { color: #0000FF; font-weight: bold } /* Name.Class */
62+.highlight .no { color: #880000 } /* Name.Constant */
63+.highlight .nd { color: #AA22FF } /* Name.Decorator */
64+.highlight .ni { color: #999999; font-weight: bold } /* Name.Entity */
65+.highlight .ne { color: #D2413A; font-weight: bold } /* Name.Exception */
66+.highlight .nf { color: #0000FF } /* Name.Function */
67+.highlight .nl { color: #A0A000 } /* Name.Label */
68+.highlight .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
69+.highlight .nt { color: #008000; font-weight: bold } /* Name.Tag */
70+.highlight .nv { color: #19177C } /* Name.Variable */
71+.highlight .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
72+.highlight .w { color: #bbbbbb } /* Text.Whitespace */
73+.highlight .mf { color: #666666 } /* Literal.Number.Float */
74+.highlight .mh { color: #666666 } /* Literal.Number.Hex */
75+.highlight .mi { color: #666666 } /* Literal.Number.Integer */
76+.highlight .mo { color: #666666 } /* Literal.Number.Oct */
77+.highlight .sb { color: #BA2121 } /* Literal.String.Backtick */
78+.highlight .sc { color: #BA2121 } /* Literal.String.Char */
79+.highlight .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */
80+.highlight .s2 { color: #BA2121 } /* Literal.String.Double */
81+.highlight .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */
82+.highlight .sh { color: #BA2121 } /* Literal.String.Heredoc */
83+.highlight .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
84+.highlight .sx { color: #008000 } /* Literal.String.Other */
85+.highlight .sr { color: #BB6688 } /* Literal.String.Regex */
86+.highlight .s1 { color: #BA2121 } /* Literal.String.Single */
87+.highlight .ss { color: #19177C } /* Literal.String.Symbol */
88+.highlight .bp { color: #008000 } /* Name.Builtin.Pseudo */
89+.highlight .vc { color: #19177C } /* Name.Variable.Class */
90+.highlight .vg { color: #19177C } /* Name.Variable.Global */
91+.highlight .vi { color: #19177C } /* Name.Variable.Instance */
92+.highlight .il { color: #666666 } /* Literal.Number.Integer.Long */
93
94=== modified file 'ubuntu-packaging-guide/index.rst'
95--- ubuntu-packaging-guide/index.rst 2012-06-26 16:02:09 +0000
96+++ ubuntu-packaging-guide/index.rst 2012-08-02 12:13:22 +0000
97@@ -63,4 +63,5 @@
98 udd-newpackage
99 chroots
100 traditional-packaging
101+ python-packaging
102 kde
103
104=== added file 'ubuntu-packaging-guide/python-packaging.rst'
105--- ubuntu-packaging-guide/python-packaging.rst 1970-01-01 00:00:00 +0000
106+++ ubuntu-packaging-guide/python-packaging.rst 2012-08-02 12:13:22 +0000
107@@ -0,0 +1,144 @@
108+=========================================
109+Packaging Python modules and applications
110+=========================================
111+
112+Our packaging follows Debian’s `Python policy`_. We will use `python-markdown`_ package as an example, which can be downloaded from `PyPI`_. You can look at its packaging at its `Subversion repository`_.
113+
114+There are two types of Python packages — *modules* and *apps*.
115+
116+At the moment of writing this, Ubuntu has two incompatible versions of Python — *2.x* and *3.x*. ``/usr/bin/python`` is a symbolic link to a default Python 2.x version, and ``/usr/bin/python3`` — to a default Python 2.x version. Python modules should be built against all supported Python versions.
117+
118+If you are going to package a new Python module, you can find ``py2dsc`` tool useful (available in `python-stdeb`_ package).
119+
120+debian/control
121+--------------
122+
123+Python 2.x and 3.x versions of the package should be in separate binary packages. Names should have ``python{,3}-modulename`` format (like: ``python3-dbus.mainloop.qt``). Here, we will use ``python-markdown`` and ``python3-markdown`` for module packages and ``python-markdown-doc`` for the documentation package.
124+
125+Things in ``debian/control`` that are specific for a Python package:
126+
127+- Section of module packages should be ``python``, of the documentation package — ``doc``. For an application, a single binary package will be enough.
128+- We should add build dependencies on ``python-all (>= 2.6.6-3~)`` and ``python3-all (>= 3.1.2-7~)`` to make sure Python helpers are available (see the next section for details).
129+- It’s recommended to add ``X-Python-Version`` and ``X-Python3-Version`` fields — see “`Specifying Supported Versions`_” section of the Policy for details. For example:
130+ ::
131+
132+ X-Python-Version: >= 2.6
133+ X-Python3-Version: >= 3.1
134+
135+ If your package works only with Python 2.x or 3.x, build depend only on one ``-all`` package and use only one ``-Version`` field.
136+- Module packages should have ``{python:Depends}`` and ``{python3:Depends}`` substitution variables (respectively) in their dependency lists.
137+
138+debian/rules
139+------------
140+
141+The recommended helpers for python modules are ``dh_python2`` and ``dh_python3``. Unfortunately, ``debhelper`` doesn’t yet build Python 3.x packages automatically (see `bug 597105`_ in Debian BTS), so we’ll need to do that manually in override sections (skip this if your package doesn’t support Python 3.x).
142+
143+Here’s our ``debian/rules`` file (with annotations):
144+
145+.. code-block:: makefile
146+
147+ # This command builds the list of supported Python 3 versions
148+ PYTHON3=$(shell py3versions -r)
149+
150+ %:
151+ # Adding the required helpers
152+ dh $@ --with python2,python3
153+
154+ override_dh_auto_clean:
155+ dh_auto_clean
156+ rm -rf build/
157+
158+ override_dh_auto_build:
159+ # Build for each Python 3 version
160+ set -ex; for python in $(PYTHON3); do \
161+ $$python setup.py build; \
162+ done
163+ dh_auto_build
164+
165+ override_dh_auto_install:
166+ # The same for install; note the --install-layout=deb option
167+ set -ex; for python in $(PYTHON3); do \
168+ $$python setup.py install --install-layout=deb --root=debian/tmp; \
169+ done
170+ dh_auto_install
171+
172+It is also a good practice to run tests during the build, if they are shipped by upstream. Usually tests can be invoked using ``setup.py test`` or ``setup.py check``.
173+
174+debian/\*.install
175+-----------------
176+
177+Python 2.x modules are installed into ``/usr/share/pyshared/`` directory, and symbolic links are created ``/usr/lib/python2.x/dist-packages/`` for every interpreter version, while Python 3.x ones are all installed into ``/usr/lib/python3/dist-packages/``.
178+
179+If your package is an application and has private Python modules, they should be installed in ``/usr/share/module``, or ``/usr/lib/module`` if the modules are architecture-dependent (e.g. extensions) (see “`Programs Shipping Private Modules`_” section of the Policy).
180+
181+So, our ``python-markdown.install`` file will look like this (we’ll also want to install a ``markdown_py`` executable):
182+
183+::
184+
185+ usr/lib/python2.*/
186+ usr/bin/
187+
188+and ``python3-markdown.install`` will only have one line:
189+
190+::
191+
192+ usr/lib/python3/
193+
194+The ``-doc`` package
195+--------------------
196+
197+Tool that is most commonly used for building Python docs is `Sphinx`_. To add Sphinx documentation to your package (using ``dh_sphinxdoc`` helper), you should:
198+
199+* Add build-dependency on ``python-sphinx`` or ``python3-sphinx`` package (depending on what Python version do you want to use);
200+* Append ``sphinxdoc`` to ``dh --with`` line;
201+* Run ``setup.py build_sphinx`` in ``override_dh_auto_build`` (sometimes not needed);
202+* Add ``{sphinxdoc:Depends}`` to dependency list of your ``-doc`` package;
203+* Add path to built docs directory (usually ``build/sphinx/html``) to your ``.docs`` file.
204+
205+In our case, docs are automatically built in ``build/docs/`` directory (when we run ``setup.py build``), so we can simply put this in the ``python-markdown-doc.docs`` file:
206+
207+::
208+
209+ build/docs/
210+
211+Because docs also contain source ``.txt`` files, we’ll also tell ``dh_compress`` to not compress them — and add this to ``debian/rules``:
212+
213+.. code-block:: makefile
214+
215+ override_dh_compress:
216+ dh_compress -X.txt
217+
218+Checking for packaging mistakes
219+-------------------------------
220+
221+Along with ``lintian``, there is a special tool for checking Python packages — ``lintian4py``. It is available in `lintian4python`_ package. For example, this command invokes both ``lintian`` and ``lintian4py`` and checks source and binary packages:
222+
223+::
224+
225+ lintian{,4py} -EI --pedantic *.dsc *.deb
226+
227+Here, ``-EI`` option is used to enable experimental and informational tags.
228+
229+See also
230+--------
231+
232+* The `Python policy`_;
233+* `Python/Packaging`_ article on Debian wiki;
234+* `Python/LibraryStyleGuide`_ and `Python/AppStyleGuide`_ articles on Debian wiki;
235+* Debian `python-modules`_ and `python-apps`_ teams.
236+
237+.. _`Python policy`: http://www.debian.org/doc/packaging-manuals/python-policy/
238+.. _`python-markdown`: http://packages.python.org/Markdown/
239+.. _`PyPI`: http://pypi.python.org/pypi/Markdown/
240+.. _`Subversion repository`: http://anonscm.debian.org/viewvc/python-modules/packages/python-markdown/trunk/debian/
241+.. _`python-stdeb`: https://launchpad.net/ubuntu/+source/stdeb
242+.. _`bug 597105`: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=597105
243+.. _`Specifying Supported Versions`: http://www.debian.org/doc/packaging-manuals/python-policy/ch-module_packages.html#s-specifying_versions
244+.. _`Programs Shipping Private Modules`: http://www.debian.org/doc/packaging-manuals/python-policy/ch-programs.html#s-current_version_progs
245+.. _`Sphinx`: http://sphinx.pocoo.org/
246+.. _`lintian4python`: https://launchpad.net/ubuntu/+source/lintian4python
247+.. _`Python/Packaging`: http://wiki.debian.org/Python/Packaging
248+.. _`Python/LibraryStyleGuide`: http://wiki.debian.org/Python/LibraryStyleGuide
249+.. _`Python/AppStyleGuide`: http://wiki.debian.org/Python/AppStyleGuide
250+.. _`python-modules`: http://wiki.debian.org/Teams/PythonModulesTeam/
251+.. _`python-apps`: http://wiki.debian.org/Teams/PythonAppsPackagingTeam/

Subscribers

People subscribed via source and target branches