18

I have a Python project which is basically a set of command line scripts and a helper package. As these scripts have a number of command line options I decided to create a manual page for each script and used ronn (http://rtomayko.github.com/ronn/) to write manuals in Markdown and generate mdoc from it.

The question is: how to generate and install man pages in distutils based project?

I came up with the following solution: create an simple install.sh script which generates and installs manual pages. I call this script from the overloaded 'install' command and pass specified prefix to it... you can check actual code here: http://github.com/novel/lc-tools.

I don't quite like this solution as for the simple task I have to add some hacks to setup.py and implement a shell script as well. Moreover, I use ${PREFIX}/share/man for man page path and it's not correct for all systems, e.g. FreeBSD seem to install 3rd party man pages to /usr/local/man (i.e. no share/).

Are there more elegant ways to do this?

bstpierre
  • 30,042
  • 15
  • 70
  • 103

2 Answers2

2

Your little hack in your setup.py does the trick.... In complement, you can add a special man_prefix options that can be passed at setup time to change the man path.

You can do this like this :

class lc_install(install):
    description = "Custom Install Process"

    user_options= install.user_options[:]
    user_options.extend([('manprefix=', None, 'MAN Prefix Path')])

def initialize_options(self):
    self.manprefix = None
    install.initialize_options(self)
def finalize_options(self):
    if self.manprefix is None :
        self.manprefix = "DEFAULT MAN PREFIX PATH IF THE OPTION IS NOT SET"
    install.finalize_options(self)

def run(self):
    .... # Your run method
ohe
  • 3,461
  • 3
  • 26
  • 50
  • Yeah, I guess it would be nice thing to add. – Roman Bogorodskiy Sep 19 '10 at 11:05
  • 1
    SO won’t let me fix one bug in your code: If you don’t make a copy of the install.user_options list, then when you call extend you end up editing the original list of install options. Remember that user_options = install.user_options binds a second name to the same object, you have to use e.g. user_options = install.user_options[:] to create a different object. – merwok Oct 09 '11 at 10:19
2

distutils does not support man pages. People have written extensions to support them, generally in the form of a custom distutils command. See for example python-distutils-extra from Ubuntu.

distutils2 will support installing man pages.

merwok
  • 6,779
  • 1
  • 28
  • 42
  • do you have references for the last claim? – Frederick Nord Oct 05 '17 at 21:01
  • I was the maintainer of distutils2, so it was in my plan. Now distutils2 is no more, replaced by various projects (packaging for base specs, setuptools+wheel or flit to build, twine to upload, pip to install). There is also an open ticket to add manpage generation to the argparse module in the stdlib. – merwok Oct 09 '17 at 23:26
  • @ÉricAraujo can you post a link to that ticket? We could find it useful. – sorin May 09 '18 at 16:39
  • @sorin https://github.com/python/cpython/issues/58310 – Yaroslav Nikitenko Jul 12 '22 at 13:16