This page discusses a small project called ekrProject created so I can explore issues relating to python packages. This project has clarified many confusing issues for me.

The ekrProject has the following organization:

ekrProject/ # top-level folder.  not a package.
    ekrProject/ # The ekrProject package.
        core # The ekrProject/core package.
            __init__.py
            mod1.py # a module
            leo.py # a module
        plugins # The ekrProject/plugins package.
            __init__.py
        __init__.py
    dist/ # Created by setup.py sdist.
        ekrProj-0.0.1.zip
    setup.py

Here is the contents of ekrProject/setup.py:

from distutils.core import setup
long_description = '''Project to test distribution issues for Leo.'''
version='0.0.1' # No spaces and no trailing comma.
setup (
    name='ekrProj',
    version=version,
    author='Edward K. Ream',
    author_email='edreamleo@yahoo.com',
    url='http://webpages.charter.net/edreamleo/front.html',
    download_url='',
    # py_modules=['ekrProj','core','plugins'],
    packages = ['ekrProj','ekrProj.core','ekrProj.plugins'],
    description = 'ekrProj',
    license='Python',
    platforms=['all',],
    long_description = long_description,
)

With the above organization, I can create a distribution in a completely standard way, and users can also install the distributed file in a standard way. The result is a leo package in Python's site-packages folders.

In detail, the steps are as follows.

  1. The distributor (me) runs:

    python setup.py sdist
    

This creates ekrProj-0.0.1.zip in the ekrProject/dist folder.

  1. Typically the user will download and unpack ekrProj-0.0.1.zip to <some folder>.

  2. Now the user runs this script from <some folder>ekrProj-0.0.1:

    python setup.py install
    

The point of this page is that this will create a leo package in the python/Lib/site-packages folder as we want.

Yes, all this seems pretty simple, but getting to this point took me a lot of thought.

Important: setup.py presently specifies files simply by listing the packages to be included. This probably won't work for the real Leo distribution: a proper manifest.in file will probably have to be generated as is done at present.