分发,epydoc和setup.py

时间:2012-11-23 13:02:12

标签: python setup.py epydoc

我想有一个目标(比如docs)为我的包运行epydoc。我假设我需要创建一个新命令,但我没有太多运气。

以前有人这样做过吗?

1 个答案:

答案 0 :(得分:2)

Babel project提供了几个可在setup.py文件中使用的命令。

您需要使用命令定义distutils.commands入口点;来自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
"""

其他命令随后可用python setup.py commandname

入口点指向from distutils.cmd import Command的子类。再次来自Babel,来自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.