Page 76 -
P. 76

distribution plan


           Prepare your distribution


           In order to share your newly created module, you need to prepare a
           distribution. This is the Python name given to the collection of files that
           together allow you to build, package, and distribute your module.
           Once a distribution exists, you can install your module into your local copy         Do this!
           of Python, as well as upload your module to PyPI to share with the world.
           Follow along with the process described on these two pages to create a
           distribution for your module.

             1     Begin by creating a folder for your module.                   Follow along with each of
                   With the folder created, copy your nester.py module file into the   the steps described on these
                   folder. To keep things simple, let’s call the folder nester:  pages. By the time you reach
                                                                                 the end, your module will
                                                                                 have transformed into a
            The “nester.py”                                                      Python distribution.
             module file.



                                                                                        The newly created
                                                                                       “nester” folder (or
                                                                    nester              directory).




             2     Create a file called “setup.py” in your new folder.
                   This file contains metadata about your distribution. Edit this file by adding the following code:
         Import the
        “setup” function
         from Python’s     from distutils.core import setup
         distribution utilities.
                                                                    Associate your module’s
                           setup(                                   metadata with the setup
                                   name         = 'nester',         function’s arguments.
            These are the           version      = '1.0.0',
            setup function’s           py_modules   = ['nester'],
            argument names.          author       = 'hfpython',                                 These are the
                                                                                                values Head First
                                   author_email = 'hfpython@headfirstlabs.com',
                                                                                                Labs use with
                                   url          = 'http://www.headfirstlabs.com',               their modules;
                                   description  = 'A simple printer of nested lists',          your metadata
                                )                                                              will be different.




           40    Chapter 2
   71   72   73   74   75   76   77   78   79   80   81