==================================================
How to package a generateDS.py generated library
==================================================

:author: Dave Kuhlman
:address: dkuhlman (at) davekuhlman (dot) org
    http://www.davekuhlman.org

.. version

:revision: 2.28b

.. version

:date: |date|

.. |date| date:: %B %d, %Y


Introduction
============

This document explains how to use the generateDS.py library
template to create a package enabling you to distribute a module
generated with generateDS.py.  This package and the instructions
below will help you to create the following:

- A directory structure in which to hang things.

- A directory for sample scripts (sample_code/)

- A directory for sample XML instance documents

- A directory for schemas

- A (mostly empty file in which to place utility functions to help
  with the use of your generated module

- A script (quick_start.py) that does a bit of name replacement

- A directory for documentation containing some boiler plate
  material and also a set-up for generating document in various
  formats (for example HTML, LaTeX, PDF) with Sphinx

The latest copy of these instructions is here:

    http://www.davekuhlman.org/librarytemplate_howto.html

and the template package itself is here:

    http://www.davekuhlman.org/librarytemplate-1.0a.zip

These instructions assume the name "peach" as the name of the
schema.  You should replace "peach" in these instructions with the
name of your schema.

Find out more about generateDS.py here:
http://www.davekuhlman.org/generateDS.html

You will need to install Sphinx in order to build the documentation
in your package.  Learn about Sphinx here: http://sphinx.pocoo.org/.


Details
=======

In the instructions that follow, I'll assume that the name of your
XML schema is "peach" and that the name of the module that you
generate using ``generateDS.py`` will be "peachlib".

Follow these steps:

1. Unroll the library template (librarytemplate-x.y.zip), for
   example::

       $ unzip librarytemplate-1.0a.zip

2. Rename the top-level directory created by the previous step, for
   example:

       $ mv librarytemplate-x.y peachlib-1.0a

   Or, on MS Windows:

       $ rename librarytemplate-x.y peachlib-1.0a

3. Go to the new directory.  For example::

       $ cd peachlib-1.0a

4. Copy your generated modules into this directory.  Suggested name
   is ``{schema_name}lib.py``.  For example ``peachlib.py``.

5. Run ``quick_start.py`` (which is in the top level directory).
   ``quick_start.py`` makes changes in the boiler plate provided by
   librarytemplate; it changes occurrences of "{{schema_name}}" to
   the name of your schema, which is entered on the command line.
   For example::

       $ python quick_start.py --help
       $ python quick_start.py --schema-name=peach

6. Add some more content to the documentation.  It is likely that
   you will want to make additions and changes in the following
   files:

   - README.txt
   - docs/intro.txt
   - sample_code/README.txt

7. Generate the documentation.  This step requires Sphinx.

   First, add the top-level directory of your distribution to your
   PYTHONPATH environment variable.  Sphinx needs to be able to
   import your library module (peachlib.py).  Then, go to
   the ./docs/ directory and build the HTML documentation::

       $ cd docs
       $ make clean
       $ make html

   You also can build other forms of documentation, e.g. LaTeX and
   PDF.  See the Sphinx documentation, or type::

       $ make help

   By default, the generated documentation for the module includes
   lists of the member functions for each class.  You can change
   this by removing the ``:members:`` and ``:undoc-members:``
   options from the file ``docs/module_contents.txt``, and then
   run::

       $ make clean
       $ make html

   again.

8. Add some functionality and sample code.  In particular:

   - Add some helper functions in peachlibutils.py.

   - Add example applications in directory sample_code/. 
     Suggestions: (1) Rename and add code to
     sample_code/example01.txt.  (2) Generate a subclass module
     (using the "-s" command line option with ``generateDS.py``,
     then add a bit of code to a few of the subclasses.

   - List and describe any example applications that you add in the
     file sample_code/README.txt.

9. It might be a good idea to include the XML schema from which you
   generated your library module.  You can copy the schema(s) to
   the schemas/ directory, and/or add a link in file
   schemas/README.txt that points to a location where it can be
   found.

10. Create a distribution file.  For example, use either::

        $ tar czf peachlib-1.0a.tar.gz peachlib-1.0a

    or::

        $ zip -r peachlib-1.0a.zip peachlib-1.0a

    In order to avoid including backup files and compiled Python
    modules, you might want to use something like the following::

        $ zip -r peachlib-1.0a.zip peachlib-1.0a -x \*~ -x \*.pyc

    See the man page on zip for more on the -x command line option.
    The backslash avoids the shell filename substitution.  Adjust
    this command for your needs.  For example, you may need to use
    "\*.bak" instead of "\*~".

