update_readme_help¶
rhiza_hooks.update_readme_help
¶
Script to update README with Makefile help output.
This hook runs 'make help' and embeds the output into README.md between special marker comments.
Migrated from rhiza's local pre-commit hook that runs 'make readme'. This is a Python wrapper that provides the same functionality.
get_make_help_output()
¶
Run 'make help' and capture the output.
Returns:
| Type | Description |
|---|---|
str | None
|
The output from 'make help', or None if the command fails. |
Source code in rhiza_hooks/update_readme_help.py
main(argv=None)
¶
Execute the script.
Source code in rhiza_hooks/update_readme_help.py
update_readme_with_help(readme_path, help_output)
¶
Update README.md with the make help output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
readme_path
|
Path
|
Path to the README.md file. |
required |
help_output
|
str
|
The output from 'make help'. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the file was modified, False otherwise. |
The marker pair is the whole contract. Without both markers there is nothing to replace and the hook is a silent no-op — which is the usual answer to "why did my README not update?":
import contextlib, io, tempfile from pathlib import Path tmp = tempfile.TemporaryDirectory() readme = Path(tmp.name) / "README.md" _ = readme.write_text("intro\n", encoding="utf-8") update_readme_with_help(readme, "test: run tests\n") False
With both markers present, everything between them is replaced by the fenced help output. The "Updated ..." notice goes to stderr, so it is redirected here rather than appearing as expected output:
_ = readme.write_text( ... "intro\n\nstale\n\n", encoding="utf-8" ... ) with contextlib.redirect_stderr(io.StringIO()): ... update_readme_with_help(readme, "test: run tests\n") True print(readme.read_text(encoding="utf-8"), end="") intro
Re-running with the same help output changes nothing, so the hook converges instead of failing every commit:
with contextlib.redirect_stderr(io.StringIO()): ... update_readme_with_help(readme, "test: run tests\n") False tmp.cleanup()
Source code in rhiza_hooks/update_readme_help.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |