Python command line program: generate man page from existing documentation and include in the distribution

不想你离开。 提交于 2019-12-03 05:47:21

To add static man pages in you distribution, you can add them in the MANIFEST file.

recursive-include docs *.txt
recursive-include po *.po
recursive-include sample_data *
recursive-include data *.desktop *.svg *.png
include COPYING.txt
include README.txt
recursive-include man_pages

Where man_pages is the directory containing the copies of generated man pages.

See also: http://linuxmanpages.com/man1/man.1.php

I would cause setup.py to generate the man pages probably before calling distutils.core.setup. Remember that setup.py at one level is python code. You want to test and make sure that it works even if sphinx is not installed (unless you require sphinx). So, if the man pages already exist and sphinx is not available do not fail. That way someone who unpacks your source distribution without sphinx can still run setup.py build and other targets.

The other option is to check in the man pages, but like you, I find that ugly.

The thing that I have seen done before is to provide a build target for your docs and make it clear in the README file that the documentation includes man pages and can be built by running that build target. Package maintainers then build your docs and package them during the package creation process.

The fedora 18 rpm for hawkey, for example, builds this way. I have also seen other rpms follow the model of building documentation at the same time as the source is built, then packaging it.

This question deserve a better answer, and not only because this issue has been bothering me for a while. So here is my implementation.

  • Download build_manpage.py from my github project (here is a link to build_manpage)
  • Save it somewhere you can import it to your setup.py

    # inside setup.py
    from setuptools import setup
    from build_manpage import BuildManPage
    
    ...
    ...
    
    setup(
    ...
    ...
    cmdclass={
    'build_manpage': BuildManPage,
    )
    

Now you can invoke setup.py like this:

$ python setup.py build_manpage --output=prog.1 --parser=yourmodule:argparser
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!