Search code examples
pythonsetup.pyepydoc

Distribute, epydoc, and setup.py


I would like to have a target (say docs) that runs epydoc for my package. I assume that I need to create a new command but I am not having much luck.

Has anyone done this before?


Solution

  • The Babel project provides several commands for use in setup.py files.

    You need to define a distutils.commands entry point with commands; example from the Babel setup.py file:

    entry_points = """
    [distutils.commands]
    compile_catalog = babel.messages.frontend:compile_catalog
    extract_messages = babel.messages.frontend:extract_messages
    init_catalog = babel.messages.frontend:init_catalog
    update_catalog = babel.messages.frontend:update_catalog
    """
    

    where the extra commands are then available as python setup.py commandname.

    The entry points point to subclasses of from distutils.cmd import Command. Example again from Babel, from the babel.messages.frontend module:

    from distutils.cmd import Command
    from distutils.errors import DistutilsOptionError
    
    
    class compile_catalog(Command):
        """Catalog compilation command for use in ``setup.py`` scripts."""
    
        # Description shown in setup.py --help-commands
        description = 'compile message catalogs to binary MO files'
        # Options available for this command, tuples of ('longoption', 'shortoption', 'help')
        # If the longoption name ends in a `=` it takes an argument
        user_options = [
            ('domain=', 'D',
             "domain of PO file (default 'messages')"),
            ('directory=', 'd',
             'path to base directory containing the catalogs'),
            # etc.
        ]
        # Options that don't take arguments, simple true or false options.
        # These *must* be included in user_options too, but without a = equals sign
        boolean_options = ['use-fuzzy', 'statistics']
    
        def initialize_options(self):
            # Set a default for each of your user_options (long option name)
    
        def finalize_options(self):
            # verify the arguments and raise DistutilOptionError if needed
    
        def run(self):
            # Do your thing here.