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:

python3 setup.py --command-packages=click_man.commands man_pages

→ 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.

Installation

pip3 install click-man

click-man is also available for Python 2:

pip install click-man

Usage Recipes

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

Use with a previously installed package

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

Use with setuptools

click-man provides a sane setuptools command extension which can be used like the following:

python3 setup.py --command-packages=click_man.commands man_pages

or specify the man pages target directory:

python3 setup.py --command-packages=click_man.commands man_pages --target path/to/man/pages

Automatic man page installation with setuptools and pip

This approach of installing man pages is problematic for various reasons:

(1) 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.

(2) Man pages are not compatable 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.

(3) 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.

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:
	python3 setup.py --command-packages=click_man.commands man_pages --target debian/tmp/manpages
	dh_installman -O--buildsystem=pybuild

Now we are able to build are debian package with the tool of your choice, e.g.:

debuild -us -uc

Checkout a working example here: repo debian package

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.4.0.linux-x86_64.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

click_man-0.4.0-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file click-man-0.4.0.linux-x86_64.tar.gz.

File metadata

  • Download URL: click-man-0.4.0.linux-x86_64.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.5

File hashes

Hashes for click-man-0.4.0.linux-x86_64.tar.gz
Algorithm Hash digest
SHA256 7c594dbfa20a3f1382619e38076f30e41dc539fd67a9f261a160e8f80c6572cd
MD5 987adc2ade00000c7fb0ff926875bbf2
BLAKE2b-256 78bf72a69b18811db0d4df13f750c91e5b62c94c5ef4abeb948953f35762663a

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: click_man-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.5

File hashes

Hashes for click_man-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a8190655f8fd14de3247026675363a27d2d34ae4c454c7182270c49290b9f878
MD5 e094f9776b45589103dd0d08ea391371
BLAKE2b-256 103b932b51e73bb124c6ab97137a64c4a3af4693fd8a291a931478ae36f37b1f

See more details on using hashes here.

Provenance

Supported by

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