Éric Araujo | 3a9f58f | 2011-06-01 20:42:49 +0200 | [diff] [blame] | 1 | ================== |
| 2 | Packaging tutorial |
| 3 | ================== |
| 4 | |
| 5 | Welcome to the Packaging tutorial! We will learn how to use Packaging |
| 6 | to package your project. |
| 7 | |
| 8 | .. TODO merge with introduction.rst |
| 9 | |
| 10 | |
| 11 | Getting started |
| 12 | --------------- |
| 13 | |
| 14 | Packaging works with the *setup.cfg* file. It contains all the metadata for |
| 15 | your project, as defined in PEP 345, but also declare what your project |
| 16 | contains. |
| 17 | |
| 18 | Let's say you have a project called *CLVault* containing one package called |
| 19 | *clvault*, and a few scripts inside. You can use the *pysetup* script to create |
| 20 | a *setup.cfg* file for the project. The script will ask you a few questions:: |
| 21 | |
| 22 | $ mkdir CLVault |
| 23 | $ cd CLVault |
| 24 | $ pysetup create |
| 25 | Project name [CLVault]: |
| 26 | Current version number: 0.1 |
| 27 | Package description: |
| 28 | >Command-line utility to store and retrieve passwords |
| 29 | Author name: Tarek Ziade |
| 30 | Author e-mail address: tarek@ziade.org |
| 31 | Project Home Page: http://bitbucket.org/tarek/clvault |
| 32 | Do you want to add a package ? (y/n): y |
| 33 | Package name: clvault |
| 34 | Do you want to add a package ? (y/n): n |
| 35 | Do you want to set Trove classifiers? (y/n): y |
| 36 | Please select the project status: |
| 37 | |
| 38 | 1 - Planning |
| 39 | 2 - Pre-Alpha |
| 40 | 3 - Alpha |
| 41 | 4 - Beta |
| 42 | 5 - Production/Stable |
| 43 | 6 - Mature |
| 44 | 7 - Inactive |
| 45 | |
| 46 | Status: 3 |
| 47 | What license do you use: GPL |
| 48 | Matching licenses: |
| 49 | |
| 50 | 1) License :: OSI Approved :: GNU General Public License (GPL) |
| 51 | 2) License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL) |
| 52 | |
| 53 | Type the number of the license you wish to use or ? to try again:: 1 |
| 54 | Do you want to set other trove identifiers (y/n) [n]: n |
| 55 | Wrote "setup.cfg". |
| 56 | |
| 57 | |
| 58 | A setup.cfg file is created, containing the metadata of your project and the |
| 59 | list of the packages it contains:: |
| 60 | |
| 61 | $ cat setup.cfg |
| 62 | [metadata] |
| 63 | name = CLVault |
| 64 | version = 0.1 |
| 65 | author = Tarek Ziade |
| 66 | author_email = tarek@ziade.org |
| 67 | description = Command-line utility to store and retrieve passwords |
| 68 | home_page = http://bitbucket.org/tarek/clvault |
| 69 | |
| 70 | classifier = Development Status :: 3 - Alpha |
| 71 | License :: OSI Approved :: GNU General Public License (GPL) |
| 72 | |
| 73 | [files] |
| 74 | packages = clvault |
| 75 | |
| 76 | |
| 77 | Our project will depend on the *keyring* project. Let's add it in the |
| 78 | [metadata] section:: |
| 79 | |
| 80 | [metadata] |
| 81 | ... |
| 82 | requires_dist = |
| 83 | keyring |
| 84 | |
| 85 | |
| 86 | Running commands |
| 87 | ---------------- |
| 88 | |
| 89 | You can run useful commands on your project once the setup.cfg file is ready: |
| 90 | |
| 91 | - sdist: creates a source distribution |
| 92 | - register: register your project to PyPI |
| 93 | - upload: upload the distribution to PyPI |
| 94 | - install_dist: install it |
| 95 | |
| 96 | All commands are run using the run script:: |
| 97 | |
| 98 | $ pysetup run install_dist |
| 99 | $ pysetup run sdist |
| 100 | $ pysetup run upload |
| 101 | |
| 102 | If you want to push a source distribution of your project to PyPI, do:: |
| 103 | |
| 104 | $ pysetup run sdist register upload |
| 105 | |
| 106 | |
| 107 | Installing the project |
| 108 | ---------------------- |
| 109 | |
| 110 | The project can be installed by manually running the packaging install command:: |
| 111 | |
| 112 | $ pysetup run install_dist |