|
| 1 | +.. _packaging-your-code-ref: |
| 2 | + |
| 3 | +=================== |
1 | 4 | Packaging Your Code |
2 | 5 | =================== |
3 | 6 |
|
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. |
5 | 15 |
|
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. |
7 | 27 |
|
8 | 28 | The `Python Packaging Guide <https://python-packaging-user-guide.readthedocs.org/en/latest/>`_ |
9 | 29 | provides an extensive guide on creating and maintaining Python packages. |
10 | 30 |
|
| 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 | + |
11 | 41 | For Python Developers |
12 | 42 | ::::::::::::::::::::: |
13 | 43 |
|
@@ -106,9 +136,42 @@ prerequisite for this is that you have an Amazon AWS account with an S3 bucket. |
106 | 136 |
|
107 | 137 | * You can now install your package with :code:`pip install --index-url=http://your-s3-bucket/packages/simple/ YourPackage` |
108 | 138 |
|
| 139 | +.. _packaging-for-linux-distributions-ref: |
| 140 | + |
109 | 141 | For Linux Distributions |
110 | 142 | :::::::::::::::::::::::: |
111 | 143 |
|
| 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 | +However, creating and maintaining the different configurations required for |
| 155 | +each distribution's format (e.g. .deb for Debian/Ubuntu, .rpm for Red |
| 156 | +Hat/Fedora, etc) is a fair amount of work. If your code is an application that |
| 157 | +you plan to distribute on other platforms, then you'll also have to create and |
| 158 | +maintain the separate config required to freeze your application for Windows |
| 159 | +and OSX. It would be much less work to simply create and maintain a single |
| 160 | +config for one of the cross platform :ref:`freezing tools |
| 161 | +<freezing-your-code-ref>`, which will produce stand-alone executables for all |
| 162 | +distributions of Linux, as well as Windows and OSX. |
| 163 | + |
| 164 | +Creating a distribution package is also problematic if your code is for a |
| 165 | +version of Python that isn't currently supported by a distribution. |
| 166 | +Having to tell *some versions* of Ubuntu end-users that they need to add `the |
| 167 | +'dead-snakes' PPA <https://launchpad.net/~fkrull/+archive/ubuntu/deadsnakes>`_ |
| 168 | +using `sudo apt-repository` commands before they can install your .deb file |
| 169 | +makes for an extremely hostile user experience. Not only that, but you'd have |
| 170 | +to maintain a custom equivalent of these instructions for every distribution, |
| 171 | +and worse, have your users read, understand, and act on them. |
| 172 | + |
| 173 | +Having said all that, here's how to do it: |
| 174 | + |
112 | 175 | * `Fedora <https://fedoraproject.org/wiki/Packaging:Python>`_ |
113 | 176 | * `Debian and Ubuntu <http://www.debian.org/doc/packaging-manuals/python-policy/>`_ |
114 | 177 | * `Arch <https://wiki.archlinux.org/index.php/Python_Package_Guidelines>`_ |
|
0 commit comments