Skip to main content

Generate man pages for click based CLI applications

Project description

click-man

Build Status PyPI Package version

Create man pages for click application as easy as this:

click-man foo

where foo is the name of your script, as defined in console_scripts.

→ Checkout the debian packaging example

What it does

click-man will generate one man page per command of your click CLI application specified in console_scripts in your setup.py / setup.cfg / pyproject.toml.

Installation

pip install click-man

Usage

The following sections describe different usage example for click-man.

CLI

click-man provides its own command line tool which can be passed the name of an installed script:

click-man commandname

where commandname is the name of an installed console_script entry point.

To specify a target directory for the man pages, use the --target option:

click-man --target path/to/man/pages commandname

You can use the manpath command or MANPATH environment variable to identify where man pages can be placed.

Automatic man page installation with setuptools and pip

While earlier version of click-man provided a distutils hook that could be used to automatically install man pages, this approach had a number of caveats as outlined [below][issues-with-automatic-man-page-installation]. distutils was removed from Python stdlib in Python 3.12 and the distutils hook was removed from click-man in v0.5.0.

Debian packages

The debhelper packages provides a very convenient script called dh_installman. It checks for the debian/(pkg_name.)manpages file and it's content which is basically a line by line list of man pages or globs:

debian/tmp/manpages/*

We override the rule provided by dh_installman to generate our man pages in advance, like this:

override_dh_installman:
	click-man <executable> --target debian/tmp/manpages
	dh_installman -O--buildsystem=pybuild

Now we are able to build a Debian package with the tool of our choice, e.g.:

debuild -us -uc

Checkout a working example here: repo debian package

Other distro packages

To include man pages in packages for other package managers like dnf, zypper, or pacman, you will likely need to do one of the following:

  • For upstream maintainers: generate man pages as part of a build release process and include them in version control or your generated sdists
  • For packagers: generate man pages as part of the package build process and include these in the RPMs or tarballs, along with the relevant stanzas in the package definition

If you are packaging utilities, we would welcome PRs documenting best practices for those using click-man to document their utilities.

Issues with automatic man page installation

Man pages are a UNIX thing

Python in general and with that pip and setuptools are aimed to be platform independent. Man pages are not: they are a UNIX thing which means setuptools does not provide a sane solution to generate and install man pages. We should consider using automatic man page installation only with vendor specific packaging, e.g. for *.deb or *.rpm packages.

Man pages are not compatible with Python virtualenvs

Even on systems that support man pages, Python packages can be installed in virtualenvs via pip and setuptools, which do not make commands available globally. In fact, one of the "features" of a virtualenv is the ability to install a package without affecting the main system. As it is imposable to ensure a man page is only generated when not installing into a virtualenv, auto-generated man pages would pollute the main system and not stay contained in the virtualenv. Additionally, as a user could install multiple different versions of the same package into multiple different virtualenvs on the same system, there is no guarantee that a globally installed man page will document the version and behavior available in any given virtualenv.

We want to generate man pages on the fly

First, we do not want to commit man pages to our source control. We want to generate them on the fly, either during build or installation time.

With setuptools and pip we face two problems:

  1. If we generate and install them during installation of the package pip does not know about the man pages and thus cannot uninstall it.
  2. If we generate them in our build process and add them to your distribution we do not have a way to prevent installation to /usr/share/man for non-UNIX-like Operating Systems or from within virtualenvs.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

click_man-0.5.1.tar.gz (21.3 kB view details)

Uploaded Source

Built Distribution

click_man-0.5.1-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file click_man-0.5.1.tar.gz.

File metadata

  • Download URL: click_man-0.5.1.tar.gz
  • Upload date:
  • Size: 21.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for click_man-0.5.1.tar.gz
Algorithm Hash digest
SHA256 2db2163ef51a1b746d6d7781f78856430a2bcf0f10df428fe5986ecc0ef9809c
MD5 27a8082053aebb24d3af41b96355f0a9
BLAKE2b-256 8b1c686c42d3a07d25d1cde107d0b92a2cf6234b92e569e61f8a294ffe6c9357

See more details on using hashes here.

File details

Details for the file click_man-0.5.1-py3-none-any.whl.

File metadata

  • Download URL: click_man-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for click_man-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ed63caf6d6bf04f2b1fb198a1a764daea9785ad29f303b2962418a417541a6ce
MD5 506522daa275084d802da090b987bec5
BLAKE2b-256 e13734e03579eb583a587edba458599af6d82715a617e685dbe2ff30e4238930

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page