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
=== modified file 'debian/changelog'
--- debian/changelog 2012-07-08 06:59:21 +0000
+++ debian/changelog 2012-08-02 12:13:22 +0000
@@ -27,6 +27,9 @@
27 process). (LP: #996096)27 process). (LP: #996096)
28 * Refer to the backports process (LP: #1017984).28 * Refer to the backports process (LP: #1017984).
2929
30 [ Dmitry Shachnev ]
31 * Add python-packaging.rst (LP: #702008)
32
30 -- Daniel Holbach <daniel.holbach@ubuntu.com> Wed, 06 Jun 2012 09:28:00 +020033 -- Daniel Holbach <daniel.holbach@ubuntu.com> Wed, 06 Jun 2012 09:28:00 +0200
3134
32ubuntu-packaging-guide (0.1) quantal; urgency=low35ubuntu-packaging-guide (0.1) quantal; urgency=low
3336
=== modified file 'themes/ubuntu/layout.html'
--- themes/ubuntu/layout.html 2012-05-16 18:21:30 +0000
+++ themes/ubuntu/layout.html 2012-08-02 12:13:22 +0000
@@ -67,6 +67,7 @@
67 <link rel="stylesheet" href="{{ pathto('_static/960.css', 1) }}" type="text/css" />67 <link rel="stylesheet" href="{{ pathto('_static/960.css', 1) }}" type="text/css" />
68 <link rel="stylesheet" href="{{ pathto('_static/base.css', 1) }}" type="text/css" />68 <link rel="stylesheet" href="{{ pathto('_static/base.css', 1) }}" type="text/css" />
69 <link rel="stylesheet" href="{{ pathto('_static/home.css', 1) }}" type="text/css" />69 <link rel="stylesheet" href="{{ pathto('_static/home.css', 1) }}" type="text/css" />
70 <link rel="stylesheet" href="{{ pathto('_static/pygments.css', 1) }}" type="text/css" />
70 {%- for cssfile in css_files %}71 {%- for cssfile in css_files %}
71 <link rel="stylesheet" href="{{ pathto(cssfile, 1) }}" type="text/css" />72 <link rel="stylesheet" href="{{ pathto(cssfile, 1) }}" type="text/css" />
72 {%- endfor %}73 {%- endfor %}
7374
=== added file 'themes/ubuntu/static/pygments.css'
--- themes/ubuntu/static/pygments.css 1970-01-01 00:00:00 +0000
+++ themes/ubuntu/static/pygments.css 2012-08-02 12:13:22 +0000
@@ -0,0 +1,62 @@
1.highlight .hll { background-color: #ffffcc }
2.highlight { background: #f8f8f8; }
3.highlight .c { color: #408080; font-style: italic } /* Comment */
4.highlight .err { border: 1px solid #FF0000 } /* Error */
5.highlight .k { color: #008000; font-weight: bold } /* Keyword */
6.highlight .o { color: #666666 } /* Operator */
7.highlight .cm { color: #408080; font-style: italic } /* Comment.Multiline */
8.highlight .cp { color: #BC7A00 } /* Comment.Preproc */
9.highlight .c1 { color: #408080; font-style: italic } /* Comment.Single */
10.highlight .cs { color: #408080; font-style: italic } /* Comment.Special */
11.highlight .gd { color: #A00000 } /* Generic.Deleted */
12.highlight .ge { font-style: italic } /* Generic.Emph */
13.highlight .gr { color: #FF0000 } /* Generic.Error */
14.highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */
15.highlight .gi { color: #00A000 } /* Generic.Inserted */
16.highlight .go { color: #808080 } /* Generic.Output */
17.highlight .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
18.highlight .gs { font-weight: bold } /* Generic.Strong */
19.highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
20.highlight .gt { color: #0040D0 } /* Generic.Traceback */
21.highlight .kc { color: #008000; font-weight: bold } /* Keyword.Constant */
22.highlight .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */
23.highlight .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */
24.highlight .kp { color: #008000 } /* Keyword.Pseudo */
25.highlight .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */
26.highlight .kt { color: #B00040 } /* Keyword.Type */
27.highlight .m { color: #666666 } /* Literal.Number */
28.highlight .s { color: #BA2121 } /* Literal.String */
29.highlight .na { color: #7D9029 } /* Name.Attribute */
30.highlight .nb { color: #008000 } /* Name.Builtin */
31.highlight .nc { color: #0000FF; font-weight: bold } /* Name.Class */
32.highlight .no { color: #880000 } /* Name.Constant */
33.highlight .nd { color: #AA22FF } /* Name.Decorator */
34.highlight .ni { color: #999999; font-weight: bold } /* Name.Entity */
35.highlight .ne { color: #D2413A; font-weight: bold } /* Name.Exception */
36.highlight .nf { color: #0000FF } /* Name.Function */
37.highlight .nl { color: #A0A000 } /* Name.Label */
38.highlight .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
39.highlight .nt { color: #008000; font-weight: bold } /* Name.Tag */
40.highlight .nv { color: #19177C } /* Name.Variable */
41.highlight .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
42.highlight .w { color: #bbbbbb } /* Text.Whitespace */
43.highlight .mf { color: #666666 } /* Literal.Number.Float */
44.highlight .mh { color: #666666 } /* Literal.Number.Hex */
45.highlight .mi { color: #666666 } /* Literal.Number.Integer */
46.highlight .mo { color: #666666 } /* Literal.Number.Oct */
47.highlight .sb { color: #BA2121 } /* Literal.String.Backtick */
48.highlight .sc { color: #BA2121 } /* Literal.String.Char */
49.highlight .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */
50.highlight .s2 { color: #BA2121 } /* Literal.String.Double */
51.highlight .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */
52.highlight .sh { color: #BA2121 } /* Literal.String.Heredoc */
53.highlight .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
54.highlight .sx { color: #008000 } /* Literal.String.Other */
55.highlight .sr { color: #BB6688 } /* Literal.String.Regex */
56.highlight .s1 { color: #BA2121 } /* Literal.String.Single */
57.highlight .ss { color: #19177C } /* Literal.String.Symbol */
58.highlight .bp { color: #008000 } /* Name.Builtin.Pseudo */
59.highlight .vc { color: #19177C } /* Name.Variable.Class */
60.highlight .vg { color: #19177C } /* Name.Variable.Global */
61.highlight .vi { color: #19177C } /* Name.Variable.Instance */
62.highlight .il { color: #666666 } /* Literal.Number.Integer.Long */
063
=== modified file 'ubuntu-packaging-guide/index.rst'
--- ubuntu-packaging-guide/index.rst 2012-06-26 16:02:09 +0000
+++ ubuntu-packaging-guide/index.rst 2012-08-02 12:13:22 +0000
@@ -63,4 +63,5 @@
63 udd-newpackage63 udd-newpackage
64 chroots64 chroots
65 traditional-packaging65 traditional-packaging
66 python-packaging
66 kde67 kde
6768
=== added file 'ubuntu-packaging-guide/python-packaging.rst'
--- ubuntu-packaging-guide/python-packaging.rst 1970-01-01 00:00:00 +0000
+++ ubuntu-packaging-guide/python-packaging.rst 2012-08-02 12:13:22 +0000
@@ -0,0 +1,144 @@
1=========================================
2Packaging Python modules and applications
3=========================================
4
5Our 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`_.
6
7There are two types of Python packages — *modules* and *apps*.
8
9At 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.
10
11If you are going to package a new Python module, you can find ``py2dsc`` tool useful (available in `python-stdeb`_ package).
12
13debian/control
14--------------
15
16Python 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.
17
18Things in ``debian/control`` that are specific for a Python package:
19
20- Section of module packages should be ``python``, of the documentation package — ``doc``. For an application, a single binary package will be enough.
21- 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).
22- 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:
23 ::
24
25 X-Python-Version: >= 2.6
26 X-Python3-Version: >= 3.1
27
28 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.
29- Module packages should have ``{python:Depends}`` and ``{python3:Depends}`` substitution variables (respectively) in their dependency lists.
30
31debian/rules
32------------
33
34The 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).
35
36Here’s our ``debian/rules`` file (with annotations):
37
38.. code-block:: makefile
39
40 # This command builds the list of supported Python 3 versions
41 PYTHON3=$(shell py3versions -r)
42
43 %:
44 # Adding the required helpers
45 dh $@ --with python2,python3
46
47 override_dh_auto_clean:
48 dh_auto_clean
49 rm -rf build/
50
51 override_dh_auto_build:
52 # Build for each Python 3 version
53 set -ex; for python in $(PYTHON3); do \
54 $$python setup.py build; \
55 done
56 dh_auto_build
57
58 override_dh_auto_install:
59 # The same for install; note the --install-layout=deb option
60 set -ex; for python in $(PYTHON3); do \
61 $$python setup.py install --install-layout=deb --root=debian/tmp; \
62 done
63 dh_auto_install
64
65It 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``.
66
67debian/\*.install
68-----------------
69
70Python 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/``.
71
72If 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).
73
74So, our ``python-markdown.install`` file will look like this (we’ll also want to install a ``markdown_py`` executable):
75
76::
77
78 usr/lib/python2.*/
79 usr/bin/
80
81and ``python3-markdown.install`` will only have one line:
82
83::
84
85 usr/lib/python3/
86
87The ``-doc`` package
88--------------------
89
90Tool that is most commonly used for building Python docs is `Sphinx`_. To add Sphinx documentation to your package (using ``dh_sphinxdoc`` helper), you should:
91
92* Add build-dependency on ``python-sphinx`` or ``python3-sphinx`` package (depending on what Python version do you want to use);
93* Append ``sphinxdoc`` to ``dh --with`` line;
94* Run ``setup.py build_sphinx`` in ``override_dh_auto_build`` (sometimes not needed);
95* Add ``{sphinxdoc:Depends}`` to dependency list of your ``-doc`` package;
96* Add path to built docs directory (usually ``build/sphinx/html``) to your ``.docs`` file.
97
98In 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:
99
100::
101
102 build/docs/
103
104Because docs also contain source ``.txt`` files, we’ll also tell ``dh_compress`` to not compress them — and add this to ``debian/rules``:
105
106.. code-block:: makefile
107
108 override_dh_compress:
109 dh_compress -X.txt
110
111Checking for packaging mistakes
112-------------------------------
113
114Along 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:
115
116::
117
118 lintian{,4py} -EI --pedantic *.dsc *.deb
119
120Here, ``-EI`` option is used to enable experimental and informational tags.
121
122See also
123--------
124
125* The `Python policy`_;
126* `Python/Packaging`_ article on Debian wiki;
127* `Python/LibraryStyleGuide`_ and `Python/AppStyleGuide`_ articles on Debian wiki;
128* Debian `python-modules`_ and `python-apps`_ teams.
129
130.. _`Python policy`: http://www.debian.org/doc/packaging-manuals/python-policy/
131.. _`python-markdown`: http://packages.python.org/Markdown/
132.. _`PyPI`: http://pypi.python.org/pypi/Markdown/
133.. _`Subversion repository`: http://anonscm.debian.org/viewvc/python-modules/packages/python-markdown/trunk/debian/
134.. _`python-stdeb`: https://launchpad.net/ubuntu/+source/stdeb
135.. _`bug 597105`: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=597105
136.. _`Specifying Supported Versions`: http://www.debian.org/doc/packaging-manuals/python-policy/ch-module_packages.html#s-specifying_versions
137.. _`Programs Shipping Private Modules`: http://www.debian.org/doc/packaging-manuals/python-policy/ch-programs.html#s-current_version_progs
138.. _`Sphinx`: http://sphinx.pocoo.org/
139.. _`lintian4python`: https://launchpad.net/ubuntu/+source/lintian4python
140.. _`Python/Packaging`: http://wiki.debian.org/Python/Packaging
141.. _`Python/LibraryStyleGuide`: http://wiki.debian.org/Python/LibraryStyleGuide
142.. _`Python/AppStyleGuide`: http://wiki.debian.org/Python/AppStyleGuide
143.. _`python-modules`: http://wiki.debian.org/Teams/PythonModulesTeam/
144.. _`python-apps`: http://wiki.debian.org/Teams/PythonAppsPackagingTeam/

Subscribers

People subscribed via source and target branches