Skip to main content

Hatch build hook plugin to generate manual pages

Project description

Hatch Argparse Manpage

Package PyPI - Python Version PyPI - Version
Meta Hatch project Ruff GitButler Checked with mypy License: GPL v3 GitHub Sponsors

This provides a build hook plugin for Hatch to automatically generate a manual page from an ArgumentParser object, using argparse-manpage by Pavel Raiskup.

Table of Contents

Explanation

This plugin is not an official project of argparse-manpage. Instead, it acts as a wrapper around it, making it available to Hatch users. As such, if argparse-manpage changes in ways incompatible with this plugin, this plugin may not function as expected.

This plugin has been tested against argparse-manpage version 4.5.

Configuration

The build hook plugin name is argparse-manpage.

Calling the plugin

Modify pyproject.toml to include the plugin as a build dependency:

[build-system]
requires = ["hatchling", "hatch-argparse-manpage"]
build-backend = "hatchling.build"

Generating the manual page

This plugin requires the directories storing the generated man pages are within the project's base directory, and is not equal to the project's base directory.

For example, for a project named myproject, and a src layout src/myproject, an acceptable directory in which to store a man page would be man.

Using the configuration option [tool.hatch.build.hooks.argparse-manpage], specify the man pages using the format defined by argparse-manpage.

For example:

[tool.hatch.build.hooks.argparse-manpage]
manpages = [
    "man/foo.1:object=parser:pyfile=bin/foo.py",
    "man/bar.1:function=get_parser:pyfile=bin/bar",
    "man/baz.1:function=get_parser:pyfile=bin/bar:prog=baz",
]

Extra options

Project URLs

If a URL is not specified in the man page's build configuration, this plugin extracts it from the [project.urls] section of the project's pyproject.toml:

  1. If a homepage URL is specified, then it is used.
  2. If not, if only one URL is specified, it is used.

Argparse-manpage uses a project URL to generate a man section that explains where to download the program the page is being built for.

To suppress this behavior, set include-url to false (the default value is true):

[tool.hatch.build.hooks.argparse-manpage]
include-url = false
manpages = [
    "man/foo.1:object=parser:pyfile=bin/foo.py",
    "man/bar.1:function=get_parser:pyfile=bin/bar",
    "man/baz.1:function=get_parser:pyfile=bin/bar:prog=baz",
]

Argparse-manpage invocation

This plugin defaults to calling argparse-manpage's Python code directly. If this generates an exception, this plugin will attempt to call argparse-manpage as a command line program. To force the use of argparse-manpage as a command line program, set force-command-line to true (the default value is false):

[tool.hatch.build.hooks.argparse-manpage]
force-command-line = true
manpages = [
    "man/foo.1:object=parser:pyfile=bin/foo.py",
    "man/bar.1:function=get_parser:pyfile=bin/bar",
    "man/baz.1:function=get_parser:pyfile=bin/bar:prog=baz",
]

Cleaning output files

The plugin includes logic to remove the files it outputs using hatch's clean hook. As well as individual files, any output directories created will also be removed, as long as these directories do not contain files created by something other than this plugin.

History

The code to parse the pyproject.toml config in this plugin overlaps with the code in argparse-manpage, but differs in that it is rewritten to conform to contemporary Python stylistic conventions, as well as the specific needs of this plugin.

Related Hatch plugin

GNU gettext users may be interested in hatch-gettext.

License

hatch-argparse-manpage is distributed under the terms of the GPL-3.0-or-later license.

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

hatch_argparse_manpage-0.6.0.tar.gz (23.4 kB view details)

Uploaded Source

Built Distribution

hatch_argparse_manpage-0.6.0-py3-none-any.whl (22.2 kB view details)

Uploaded Python 3

File details

Details for the file hatch_argparse_manpage-0.6.0.tar.gz.

File metadata

File hashes

Hashes for hatch_argparse_manpage-0.6.0.tar.gz
Algorithm Hash digest
SHA256 74b3778f1d02899d5f1fd74065627defae8095d292f1eee6a24d0b8f57ed0ec8
MD5 02052c2c64887502a103b441aefc0d60
BLAKE2b-256 79c9dbb4abadc06897d57d77028f14a15cf3c315cbe37006a4b86fd436f4ae13

See more details on using hashes here.

File details

Details for the file hatch_argparse_manpage-0.6.0-py3-none-any.whl.

File metadata

File hashes

Hashes for hatch_argparse_manpage-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 375ba72f32bd9c99862cfd683f77464266b758651960a693a0ce6e834ba890a5
MD5 4108871505377094f2a6a3cb86d0ddb2
BLAKE2b-256 ebecfd0d0398d7ed0c18a3cd49850d9d41df206a47165d4fd374d6f2a63b35f1

See more details on using hashes here.

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