Debian Codegraph @

README.md

raw
1 # click-man
2
3 [![Build Status](https://github.com/click-contrib/click-man/actions/workflows/ci.yaml/badge.svg)](https://github.com/click-contrib/click-man/actions/workflows/ci.yaml) [![PyPI Package version](https://badge.fury.io/py/click-man.svg)](https://pypi.python.org/pypi/click-man)
4
5 Create **man pages** for [click](https://github.com/pallets/click) application as easy as this:
6
7 ```bash
8 click-man foo
9 ```
10
11 where `foo` is the name of your script, as defined in [`console_scripts`](https://python-packaging.readthedocs.io/en/latest/command-line-scripts.html#the-console-scripts-entry-point).
12
13 → Checkout the [debian packaging example](#debian-packages)
14
15 ## What it does
16
17 *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`.
18
19 ## Installation
20
21 ```bash
22 pip install click-man
23 ```
24
25 ## Usage
26
27 The following sections describe different usage example for *click-man*.
28
29 ### CLI
30
31 **click-man** provides its own command line tool which can be passed the name of an installed script:
32
33 ```bash
34 click-man commandname
35 ```
36
37 where `commandname` is the name of an installed `console_script` entry point.
38
39 To specify a target directory for the man pages, use the `--target` option:
40
41 ```bash
42 click-man --target path/to/man/pages commandname
43 ```
44
45 You can use the `manpath` command or `MANPATH` environment variable to identify where man pages can be placed.
46
47 ### Automatic man page installation with setuptools and pip
48
49 While earlier version of click-man provided a distutils hook that could be used to automatically install man pages,
50 this approach had a number of caveats as outlined [below][issues-with-automatic-man-page-installation].
51 distutils was removed from Python stdlib in Python 3.12 and the distutils hook was removed from **click-man** in v0.5.0.
52
53 ### Debian packages
54
55 The `debhelper` packages provides a very convenient script called `dh_installman`.
56 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:
57
58 ```
59 debian/tmp/manpages/*
60 ```
61
62 We override the rule provided by `dh_installman` to generate our man pages in advance, like this:
63
64 ```Makefile
65 override_dh_installman:
66 click-man <executable> --target debian/tmp/manpages
67 dh_installman -O--buildsystem=pybuild
68 ```
69
70 Now we are able to build a Debian package with the tool of our choice, e.g.:
71
72 ```bash
73 debuild -us -uc
74 ```
75
76 Checkout a working example here: [repo debian package](https://github.com/click-contrib/click-man/tree/master/examples/debian_pkg)
77
78 ### Other distro packages
79
80 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:
81
82 * For upstream maintainers: generate man pages as part of a build release process and include them in version control or your generated sdists
83 * 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
84
85 If you are packaging utilities, we would welcome PRs documenting best practices for those using **click-man** to document their utilities.
86
87 ## Issues with automatic man page installation
88
89 ### Man pages are a UNIX thing
90
91 Python in general and with that pip and setuptools are aimed to be platform independent.
92 Man pages are **not**: they are a UNIX thing which means setuptools does not provide a sane solution to generate and install man pages.
93 We should consider using automatic man page installation only with vendor specific packaging, e.g. for `*.deb` or `*.rpm` packages.
94
95 ### Man pages are not compatible with Python virtualenvs
96
97 Even on systems that support man pages, Python packages can be installed in
98 virtualenvs via pip and setuptools, which do not make commands available
99 globally. In fact, one of the "features" of a virtualenv is the ability to
100 install a package without affecting the main system. As it is imposable to
101 ensure a man page is only generated when not installing into a virtualenv,
102 auto-generated man pages would pollute the main system and not stay contained in
103 the virtualenv. Additionally, as a user could install multiple different
104 versions of the same package into multiple different virtualenvs on the same
105 system, there is no guarantee that a globally installed man page will document
106 the version and behavior available in any given virtualenv.
107
108 ### We want to generate man pages on the fly
109
110 First, we do not want to commit man pages to our source control.
111 We want to generate them on the fly, either during build or installation time.
112
113 With setuptools and pip we face two problems:
114
115 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.
116 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.