From e558bae14b9e2fe70a02aa5dbbfc3d26b41c1460 Mon Sep 17 00:00:00 2001 From: Jerry Zhang Date: Mon, 27 Jul 2026 13:23:12 -0700 Subject: [PATCH] build: Move manpage logic into a shell script This makes it easier to reuse across potential build systems. Also move version into version.py so that it doesn't intercept init.py. --- Makefile | 24 ++++++------------------ revup/__init__.py | 5 ----- revup/revup.py | 6 ++---- revup/version.py | 5 +++++ scripts/build_manpage.sh | 40 ++++++++++++++++++++++++++++++++++++++++ setup.cfg | 2 +- 6 files changed, 54 insertions(+), 28 deletions(-) create mode 100644 revup/version.py create mode 100755 scripts/build_manpage.sh diff --git a/Makefile b/Makefile index 3fc6a088..84ab5587 100644 --- a/Makefile +++ b/Makefile @@ -35,18 +35,8 @@ clean: rm -rf $(BUILD_DIR) rm -rf .mypy_cache -REVUP_VERSION:=$(shell $(PYTHON) revup/__init__.py) +REVUP_VERSION:=$(shell $(PYTHON) revup/version.py) REVUP_DATE ?= Apr 21, 2021 -define REVUP_HEADER ---- -title: TITLE -section: 1 -header: Revup Manual -footer: revup VERSION -date: DATE ---- -endef -export REVUP_HEADER REVUP_VERSION_HASH?=${shell git rev-parse --short v$(REVUP_VERSION) || echo main} @@ -66,13 +56,11 @@ upload: $(PYTHON) -m twine upload build/revup-$(REVUP_VERSION).tar.gz man: - mkdir -p revup/man1 ; \ - cd docs ; \ - for file in *.md ; do \ - CMD_NAME=`echo $${file} | awk -F'[.]' '{print $$1}'` ; \ - echo "$${REVUP_HEADER}" | m4 -DTITLE=$${CMD_NAME} -DVERSION=$(REVUP_VERSION) -DDATE="$(REVUP_DATE)" - | \ - cat - $${file} | pandoc -f markdown-smart -s -t man > ../revup/man1/$${CMD_NAME}.1 || exit 1 ; \ - gzip -n -f -k ../revup/man1/$${CMD_NAME}.1 || exit 1 ; \ + mkdir -p revup/man1 + @for src in docs/*.md ; do \ + name=$$(basename $${src} .md) ; \ + scripts/build_manpage.sh "$${name}" "$(REVUP_VERSION)" "$(REVUP_DATE)" \ + "$${src}" "revup/man1/$${name}.1.gz" || exit 1 ; \ done test: diff --git a/revup/__init__.py b/revup/__init__.py index 007c8677..e69de29b 100644 --- a/revup/__init__.py +++ b/revup/__init__.py @@ -1,5 +0,0 @@ -__version__ = "0.4.0" - -if __name__ == "__main__": - # So that Makefile can get the version without having to parse python - print(__version__) diff --git a/revup/revup.py b/revup/revup.py index 50d127e7..2b1546db 100755 --- a/revup/revup.py +++ b/revup/revup.py @@ -8,7 +8,6 @@ import sys from typing import Any, List, Tuple -import revup from revup import config, git, logs, shell from revup.completion import ( ShellType, @@ -21,6 +20,7 @@ from revup.forge_utils import parse_forge_info from revup.topic_stack import PrBodySource from revup.types import RevupUsageException +from revup.version import REVUP_VERSION REVUP_CONFIG_ENV_VAR = "REVUP_CONFIG_PATH" CONFIG_FILE_NAME = ".revupconfig" @@ -47,9 +47,7 @@ def __call__(self, parser: Any, namespace: Any, values: Any, option_string: Any def make_toplevel_parser() -> RevupArgParser: revup_parser = RevupArgParser(add_help=False, prog="revup") revup_parser.add_argument("--help", "-h", action=HelpAction, nargs=0) - revup_parser.add_argument( - "--version", action="version", version=f"%(prog)s {revup.__version__}" - ) + revup_parser.add_argument("--version", action="version", version=f"%(prog)s {REVUP_VERSION}") revup_parser.add_argument("--proxy") revup_parser.add_argument("--forge-oauth", "--github-oauth") revup_parser.add_argument("--forge-url", "--github-url", default="github.com") diff --git a/revup/version.py b/revup/version.py new file mode 100644 index 00000000..c9de9316 --- /dev/null +++ b/revup/version.py @@ -0,0 +1,5 @@ +REVUP_VERSION = "0.4.0" + +if __name__ == "__main__": + # Lets Makefile read the version without parsing a Python file. + print(REVUP_VERSION) diff --git a/scripts/build_manpage.sh b/scripts/build_manpage.sh new file mode 100755 index 00000000..ab47eb51 --- /dev/null +++ b/scripts/build_manpage.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash +# Build a gzipped man page from a markdown source. +# +# Usage: build_manpage.sh +# +# Composes a pandoc-style YAML header with m4, prepends it to the markdown, +# pipes through pandoc, then gzip -n for reproducibility. Honors $M4 and +# $PANDOC env vars so Bazel can supply hermetic toolchains; falls back to PATH. +set -euo pipefail + +NAME=$1 +VERSION=$2 +DATE=$3 +INPUT=$4 +OUTPUT=$5 + +: "${M4:=m4}" +: "${PANDOC:=pandoc}" + +HEADER=$("$M4" \ + -DTITLE="$NAME" \ + -DVERSION="$VERSION" \ + -DDATE="$DATE" \ + <<'EOF' +--- +title: TITLE +section: 1 +header: Revup Manual +footer: revup VERSION +date: DATE +--- +EOF +) + +TMP=$(mktemp -d) +trap 'rm -rf "$TMP"' EXIT + +printf '%s\n' "$HEADER" | cat - "$INPUT" \ + | "$PANDOC" -f markdown-smart -s -t man > "$TMP/page.1" +gzip -n -c "$TMP/page.1" > "$OUTPUT" diff --git a/setup.cfg b/setup.cfg index 4c61c196..76c34052 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = revup -version = attr: revup.__version__ +version = attr: revup.version.REVUP_VERSION author = Jerry Zhang author_email = jerry@skydio.com description = Revolutionary github tools. Effortlessly create multiple branches and pull requests.