Skip to main content

Automatically build manpage from argparse

This repository contains a command for setup.py to build a manpage for your project.

The initial code was developed for CrunchyFrog, a database query tool for Gnome. The frog is now retired and RunSQLRun is it's successor. Then, the build_manpage command was developed in andialbrecht and edited slightly in gabrielegiammatteo. There's even an old blog post about this command.

Since some useful work has been done in python pull request, the code from the PR has been used here too (with a belief that upstream merges this, some day). Then, some more flexibility has been added.

The build_manpages command for setup.py is on it's own way (right here). The old usage from build_manpage is still supported, documented in old documentation.

Usage

Download ./build_manpages directory and place it somewhere where Python can find it. E.g. by:

git submodule add --name build_manpages https://github.com/praiskup/build_manpages
git submodule update --init

In your setup.py add:

[...]
from build_manpages import build_manpages, get_build_py_cmd, get_install_cmd
from setuptools.command.build_py import build_py
from setuptools.command.install import install

setup(
  [...]
  cmdclass={
      'build_manpages': build_manpages,
      # Re-define build_py and install commands so the manual pages
      # are automatically re-generated and installed (optional)
      'build_py': get_build_py_cmd(build_py),
      'install': get_install_cmd(install),
  }
)

In your setup.cfg add:

[build_manpages]
manpages =
    man/foo.1:object=parser:pyfile=bin/foo.py
    man/bar.1:function=get_parser:pyfile=bin/bar

where each line means one manual page to be generated. The format of the lines is colon separated set of arguments/options. The first argument determines the filename of the generated manual page. Then follows a list of options of format option=value; and are about "how to get the particular argparse object".

Supported values are:

  • pyfile - what python file the argparse object resides in
  • object - the name of arparse object in "pyfile" to import
  • function - the name of function in pyfile to call to get the argparse object

Then run setup.py build_manpages to build a manpages for your project. Also, if you used get_build_py helper, setup.py build then transitively builds the manual pages.

Command-line usage

You can also use argparse-manpage command on a command-line. Example:

argparse-manpage --pyfile ./pythonfile --function get_parser --author me --author-email me@domain.com --project-name myproject --url https://pagure.io/myproject > cool-manpage.1

This reads ./pythonfile and executes function get_parser from it. The function should be programmed to return an ArgumentParser instance which is then used together with the other info supplied on the command-line to generate the man page.

See argparse-manpage --help for full info.

License

This work is released under the terms of the Apache License v2.0. See LICENSE for details.

Release files for argparse-manpage 2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for argparse-manpage 2
File Size Uploaded
argparse-manpage-2.tar.gz 34.5 kB Details

Release files / argparse-manpage-2.tar.gz

Download URL argparse-manpage-2.tar.gz
Size 34.5 kB
Tags Source
SHA-256 checksum
How to use checksums
565c76776092b3aed59e3d0806c39545dca3b910b455834fafec3b25948cf5fd
BLAKE2b-256 checksum
How to use checksums
a7b0a9a96132f1c46a3f38dada28eedd89bfcc61b8d35b38fb0847910a23113d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.6.0 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.10.0

Release history Release notifications | RSS feed

4.7

1 release file

4.6

1 release file

4.5

1 release file

4.4

1 release file

4.3

1 release file

4.2

1 release file

4.1

1 release file

4

1 release file

3

1 release file

2.2

1 release file

2.1

1 release file

This release

2 This release

1 release file

1.5

1 release file

1.4

1 release file

1.3

1 release file

1.2.2

1 release file

1.2.1

1 release file

1.1

1 release file

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page