| 1 |
""" |
| 2 |
Standalone script for writing release doc:: |
| 3 |
|
| 4 |
python tools/write_release <version> |
| 5 |
|
| 6 |
Example:: |
| 7 |
|
| 8 |
python tools/write_release.py 1.7.0 |
| 9 |
|
| 10 |
Needs to be run from the root of the repository and assumes |
| 11 |
that the output is in `release` and wheels and sdist in |
| 12 |
`release/installers`. |
| 13 |
|
| 14 |
Translation from rst to md markdown requires Pandoc, you |
| 15 |
will need to rely on your distribution to provide that. |
| 16 |
|
| 17 |
""" |
| 18 |
import argparse |
| 19 |
import os |
| 20 |
import subprocess |
| 21 |
from pathlib import Path |
| 22 |
|
| 23 |
# Name of the notes directory |
| 24 |
NOTES_DIR = "doc/source/release" |
| 25 |
# Name of the output directory |
| 26 |
OUTPUT_DIR = "release" |
| 27 |
# Output base name, `.rst` or `.md` will be appended |
| 28 |
OUTPUT_FILE = "README" |
| 29 |
|
| 30 |
def write_release(version): |
| 31 |
""" |
| 32 |
Copy the <version>-notes.rst file to the OUTPUT_DIR and use |
| 33 |
pandoc to translate it to markdown. That results in both |
| 34 |
README.rst and README.md files that can be used for on |
| 35 |
github for the release. |
| 36 |
|
| 37 |
Parameters |
| 38 |
---------- |
| 39 |
version: str |
| 40 |
Release version, e.g., '2.3.2', etc. |
| 41 |
|
| 42 |
Returns |
| 43 |
------- |
| 44 |
None. |
| 45 |
|
| 46 |
""" |
| 47 |
notes = Path(NOTES_DIR) / f"{version}-notes.rst" |
| 48 |
outdir = Path(OUTPUT_DIR) |
| 49 |
outdir.mkdir(exist_ok=True) |
| 50 |
target_md = outdir / f"{OUTPUT_FILE}.md" |
| 51 |
target_rst = outdir / f"{OUTPUT_FILE}.rst" |
| 52 |
|
| 53 |
# translate README.rst to md for posting on GitHub |
| 54 |
os.system(f"cp {notes} {target_rst}") |
| 55 |
subprocess.run( |
| 56 |
["pandoc", "-s", "-o", str(target_md), str(target_rst), "--wrap=preserve"], |
| 57 |
check=True, |
| 58 |
) |
| 59 |
|
| 60 |
|
| 61 |
if __name__ == '__main__': |
| 62 |
parser = argparse.ArgumentParser() |
| 63 |
parser.add_argument( |
| 64 |
"version", |
| 65 |
help="NumPy version of the release, e.g. 2.3.2, etc.") |
| 66 |
|
| 67 |
args = parser.parse_args() |
| 68 |
write_release(args.version) |