removed.
- A verb `documentation` has been added. Calling mkosi with this verb will show
the documentation. This is useful when running mkosi during development to
- always have the documentation in the correct version available. If available,
- the man page will be shown, but it will fall back to the markdown file from
- which it can be generated, e.g. via `pandoc -t man -s -o mkosi.1
- mkosi.md`. The markdown file can be found in `mkosi/resources` in the Python
- package or by redirecting the output of `python -m mkosi documentation` into a
- file. Distro packagers are encouraged to add a file `mkosi.1` into the
- `mkosi/resources` directory of the Python package as well es install it in
- the appropriate search path for man pages.
+ always have the documentation in the correct version available. By default it
+ will try several ways to output the documentation, but a specific option can
+ be chosen with the `--doc-format` option. Distro packagers are encouraged to
+ add a file `mkosi.1` into the `mkosi/resources` directory of the Python
+ package, if it is missing, as well es install it in the appropriate search
+ path for man pages. The man page can be generated from the markdown file
+ `mkosi/resources/mkosi.md` e.g via `pandoc -t man -s -o mkosi.1 mkosi.md`.
## v14
import datetime
import hashlib
import http.server
-import itertools
import importlib.resources
+import itertools
import json
import logging
import os
from mkosi.config import (
Compression,
ConfigFeature,
+ DocFormat,
ManifestFormat,
MkosiArgs,
MkosiConfig,
def show_docs(args: MkosiArgs) -> None:
- with importlib.resources.path("mkosi.resources", "mkosi.1") as man:
- if man.exists():
- run(["man", man])
- return
+ if args.doc_format == DocFormat.auto:
+ formats = [DocFormat.man, DocFormat.pandoc, DocFormat.markdown, DocFormat.system]
+ else:
+ formats = [args.doc_format]
- md = importlib.resources.read_text("mkosi.resources", "mkosi.md")
- page(md, args.pager)
+ while formats:
+ form = formats.pop(0)
+ try:
+ if form == DocFormat.man:
+ with importlib.resources.path("mkosi.resources", "mkosi.1") as man:
+ if not man.exists():
+ raise FileNotFoundError()
+ run(["man", "--local-file", man])
+ return
+ elif form == DocFormat.pandoc:
+ if not shutil.which("pandoc"):
+ logging.debug("pandoc is not available")
+ with importlib.resources.path("mkosi.resources", "mkosi.md") as mdr:
+ pandoc = run(["pandoc", "-t", "man", "-s", mdr], stdout=subprocess.PIPE)
+ run(["man", "--local-file", "-"], input=pandoc.stdout)
+ return
+ elif form == DocFormat.markdown:
+ md = importlib.resources.read_text("mkosi.resources", "mkosi.md")
+ page(md, args.pager)
+ return
+ elif form == DocFormat.system:
+ run(["man", "mkosi"])
+ return
+ except (FileNotFoundError, subprocess.CalledProcessError) as e:
+ if not formats:
+ if isinstance(e, FileNotFoundError):
+ die("The mkosi package does not contain the man page.")
+ raise e
def expand_specifier(s: str) -> str:
return self != Compression.none
+class DocFormat(StrEnum):
+ auto = enum.auto()
+ markdown = enum.auto()
+ man = enum.auto()
+ pandoc = enum.auto()
+ system = enum.auto()
+
+
def parse_boolean(s: str) -> bool:
"Parse 1/true/yes/y/t/on as true and 0/false/no/n/f/off/None as false"
s_l = s.lower()
genkey_common_name: str
auto_bump: bool
presets: list[str]
+ doc_format: DocFormat
@classmethod
def from_namespace(cls, ns: argparse.Namespace) -> "MkosiArgs":
default=[],
help="Build the specified presets and their dependencies",
)
+ parser.add_argument(
+ "--doc-format",
+ help="The format to show documentation in",
+ default=DocFormat.auto,
+ type=DocFormat,
+ )
parser.add_argument(
"--nspawn-keep-unit",
action="store_true",
`documentation`
-: Show mkosi's documentation.
+: Show mkosi's documentation. By default this verb will try several ways
+ to output the documentation, but a specific option can be chosen with
+ the `--doc-format` option. Distro packagers are encouraged to add a
+ file `mkosi.1` into the `mkosi/resources` directory of the Python
+ package, if it is missing, as well as to install it in the appropriate
+ search path for man pages. The man page can be generated from the
+ markdown file `mkosi/resources/mkosi.md` e.g via
+ `pandoc -t man -s -o mkosi.1 mkosi.md`.
`help`
dependencies are built. If not specified, all presets are built. See
the `Presets` section for more information.
+`--doc-format`
+
+: The format to show the documentation in. Supports the values `markdown`,
+ `man`, `pandoc`, `system` and `auto`. In the case of `markdown` the
+ documentation is shown in the original Markdown format. `man` shows the
+ documentation in man page format, if it is available. `pandoc` will generate
+ the man page format on the fly, if `pandoc` is available. `system` will show
+ the system-wide man page for mkosi, which may or may not correspond to the
+ version you are using, depending on how you installed mkosi. `auto`, which is
+ the default, will try all methods in the order `man`, `pandoc`, `markdown`,
+ `system`.
+
## Supported output formats
The following output formats are supported: