Skip to content

Commit 56974e3

Browse files
committed
Merge pull request #548 from tartley/master
Intro paras for Freezing and Packaging your code
2 parents 3e8a4d1 + b4f393c commit 56974e3

File tree

2 files changed

+94
-9
lines changed

2 files changed

+94
-9
lines changed

docs/shipping/freezing.rst

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,36 @@
1+
.. _freezing-your-code-ref:
2+
3+
==================
14
Freezing Your Code
25
==================
36

4-
An alternative to shipping your code is freezing it — shipping it as an
5-
executable with a bundled Python interpreter.
7+
To 'Freeze' your code is to distribute to end-users as an executable which
8+
includes a bundled Python interpreter.
69

7-
Many applications you use every day do this:
10+
Applications such as 'Dropbox', BitTorrent clients, 'Eve Online' and
11+
'Civilisation IV' do this.
812

9-
- Dropbox
10-
- BitTorrent
11-
- ...
13+
The advantage of distributing this way is that your application will work even
14+
if the user doesn't already have the required version of Python installed. On
15+
Windows, and even on many Linux distributions and OSX versions, the right
16+
version of Python will not already be installed.
1217

13-
.. todo:: Fill in "Freezing Your Code" stub
18+
One disadvantage is that it will bloat your distribution by about 2MB.
19+
Another problem is that your application will not receive any security updates
20+
to the version of Python it uses unless you freeze a new version and get
21+
users to download it.
22+
23+
Alternatives to Freezing
24+
------------------------
1425

26+
:ref:`Packaging your code <packaging-your-code-ref>` is for distributing
27+
libraries or tools to other developers.
28+
29+
On Linux, an alternative to freezing is to
30+
:ref:`create a Linux distro package <packaging-for-linux-distributions-ref>`
31+
(e.g. .deb files for Debian or Ubuntu, or .rpm files for Red Hat and SuSE.)
32+
33+
.. todo:: Fill in "Freezing Your Code" stub
1534

1635

1736
Comparison

docs/shipping/packaging.rst

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,43 @@
1+
.. _packaging-your-code-ref:
2+
3+
===================
14
Packaging Your Code
25
===================
36

4-
Packaging your code is important.
7+
Package your code to share it with other developers. For example
8+
to share a library for other developers to use in their application,
9+
or for development tools like 'py.test'.
10+
11+
An advantage of this method of distribution is its well established ecosystem
12+
of tools such as PyPI and pip, which make it easy for other developers to
13+
download and install your package either for casual experiments, or as part of
14+
large, professional systems.
515

6-
You'll need to package your code first before sharing it with other developers.
16+
It is a well-established convention for Python code to be shared this way.
17+
If your code isn't packaged on PyPI, then it will be harder
18+
for other developers to find it, and to use it as part of their existing
19+
process. They will regard such projects with substantial suspicion of being
20+
either badly managed or abandoned.
21+
22+
The downside of distributing code like this is that it relies on the
23+
recipient understanding how to install the required version of Python,
24+
and being able and willing to use tools such as pip to install your code's
25+
other dependencies. This is fine when distributing to other developers, but
26+
makes this method unsuitable for distributing applications to end-uers.
727

828
The `Python Packaging Guide <https://python-packaging-user-guide.readthedocs.org/en/latest/>`_
929
provides an extensive guide on creating and maintaining Python packages.
1030

31+
Alternatives to Packaging
32+
:::::::::::::::::::::::::
33+
34+
To distribute applications to end-users, you should
35+
:ref:`freeze your application <freezing-your-code-ref>`.
36+
37+
On Linux, you may also want to consider
38+
:ref:`creating a Linux distro package <packaging-for-linux-distributions-ref>`
39+
(e.g. a .deb file for Debian or Ubuntu.)
40+
1141
For Python Developers
1242
:::::::::::::::::::::
1343

@@ -106,9 +136,45 @@ prerequisite for this is that you have an Amazon AWS account with an S3 bucket.
106136

107137
* You can now install your package with :code:`pip install --index-url=http://your-s3-bucket/packages/simple/ YourPackage`
108138

139+
.. _packaging-for-linux-distributions-ref:
140+
109141
For Linux Distributions
110142
::::::::::::::::::::::::
111143

144+
Creating a Linux distro package is arguably the "right way" to distribute code
145+
on Linux.
146+
147+
Because a distribution package doesn't include the Python interpreter, it
148+
makes the download and install about 2MB smaller than
149+
:ref:`freezing your application <freezing-your-code-ref>`.
150+
151+
Also, if a distribution releases a new security update for Python, then your
152+
application will automatically start using that new version of Python.
153+
154+
The bdist_rpm command makes `producing an RPM file <https://docs.python.org/3/distutils/builtdist.html#creating-rpm-packages>`_
155+
for use by distributions like Red Hat or SuSE is trivially easy.
156+
157+
However, creating and maintaining the different configurations required for
158+
each distribution's format (e.g. .deb for Debian/Ubuntu, .rpm for Red
159+
Hat/Fedora, etc) is a fair amount of work. If your code is an application that
160+
you plan to distribute on other platforms, then you'll also have to create and
161+
maintain the separate config required to freeze your application for Windows
162+
and OSX. It would be much less work to simply create and maintain a single
163+
config for one of the cross platform :ref:`freezing tools
164+
<freezing-your-code-ref>`, which will produce stand-alone executables for all
165+
distributions of Linux, as well as Windows and OSX.
166+
167+
Creating a distribution package is also problematic if your code is for a
168+
version of Python that isn't currently supported by a distribution.
169+
Having to tell *some versions* of Ubuntu end-users that they need to add `the
170+
'dead-snakes' PPA <https://launchpad.net/~fkrull/+archive/ubuntu/deadsnakes>`_
171+
using `sudo apt-repository` commands before they can install your .deb file
172+
makes for an extremely hostile user experience. Not only that, but you'd have
173+
to maintain a custom equivalent of these instructions for every distribution,
174+
and worse, have your users read, understand, and act on them.
175+
176+
Having said all that, here's how to do it:
177+
112178
* `Fedora <https://fedoraproject.org/wiki/Packaging:Python>`_
113179
* `Debian and Ubuntu <http://www.debian.org/doc/packaging-manuals/python-policy/>`_
114180
* `Arch <https://wiki.archlinux.org/index.php/Python_Package_Guidelines>`_

0 commit comments

Comments
 (0)