把所有的东西组合起来

最后整个Python包, 看起来像这样:

funniest/
    funniest/
        __init__.py
        command_line.py
        tests/
            __init__.py
            test_joke.py
            test_command_line.py
    MANIFEST.in
    README.rst
    setup.py
    .gitignore

每个文件如下:

funniest/__init__.py

from markdown import markdown

def joke():
    return markdown(u'How do you tell HTML from HTML5?'
                    u'Try it out in **Internet Explorer**.'
                    u'Does it work?'
                    u'No?'
                    u'It\'s HTML5.')

funniest/command_line.py

from . import joke


def main():
    print joke()

funniest/tests/__init__.py

(empty)

funniest/tests/test_joke.py

from unittest import TestCase

import funniest


class TestJoke(TestCase):
    def test_is_string(self):
        s = funniest.joke()
        self.assertTrue(isinstance(s, basestring))

funniest/tests/test_command_line.py

from unittest import TestCase

from funniest.cmd import main


class TestCmd(TestCase):
    def test_basic(self):
        main()

MANIFEST.in

include README.rst

README.rst

Funniest
--------

To use (with caution), simply do::

    >>> import funniest
    >>> print funniest.joke()

setup.py

from setuptools import setup

def readme():
    with open('README.rst.example') as f:
        return f.read()

setup(name='funniest',
      version='0.1',
      description='The funniest joke in the world',
      long_description=readme(),
      classifiers=[
        'Development Status :: 3 - Alpha',
        'License :: OSI Approved :: MIT License',
        'Programming Language :: Python :: 2.7',
        'Topic :: Text Processing :: Linguistic',
      ],
      keywords='funniest joke comedy flying circus',
      url='http://github.com/storborg/funniest',
      author='Flying Circus',
      author_email='flyingcircus@example.com',
      license='MIT',
      packages=['funniest'],
      install_requires=[
          'markdown',
      ],
      test_suite='nose.collector',
      tests_require=['nose', 'nose-cover3'],
      entry_points={
          'console_scripts': ['funniest-joke=funniest.command_line:main'],
      },
      include_package_data=True,
      zip_safe=False)

.gitignore

# Compiled python modules.
*.pyc

# Setuptools distribution folder.
/dist/

# Python egg metadata, regenerated from source files by setuptools.
/*.egg-info
/*.egg