Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ Fixes #(issue)
# Checklist (delete if not relevant):

- [ ] I have added tests that prove my fix is effective or that my feature works
- [ ] I have updated CHANGELOG.md
- [ ] I have added a changelog entry to `changelog.d/` (see `changelog.d/README.md`)
- [ ] I have made corresponding changes to user documentation for new features
- [ ] I have made corresponding changes to library documentation for API changes
8 changes: 4 additions & 4 deletions CHANGELOG.md
Comment thread
mcepl marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# **Upcoming release**

- #223 Add regression tests for restructuring and patchedast with `elif(` written without a space (@mcepl)

<!--
Do not edit this file directly; add your entry to changelog.d/
instead, see changelog.d/README.md.
-->

# Release 1.16.0
Comment thread
mcepl marked this conversation as resolved.
Resolved

Expand Down
36 changes: 36 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Maintenance tasks for rope; a thin wrapper around
# bin/changelog.py and the Sphinx documentation. Kept portable
# between GNU make and BSD make.

PYTHON ?= python3
CHANGELOG = $(PYTHON) bin/changelog.py
ENTRIES != ls changelog.d/[0-9]*.md 2>/dev/null || true

.PHONY: help changelog-add changelog-preview changelog docs release FORCE

help:
@echo "make changelog-add N=<issue/PR> [TEXT=...] add changelog.d/N.md"
@echo "make changelog-preview show the next release section"
@echo "make changelog fold entries into CHANGELOG.md"
@echo "make docs build the HTML documentation"
@echo "make release changelog + docs"

changelog-add:
@$(CHANGELOG) add "$$N" "$$TEXT"

changelog-preview:
@$(CHANGELOG) preview

changelog: CHANGELOG.md

# Collecting removes the entries, so any entry left means
# CHANGELOG.md is out of date, whatever the timestamps say.
CHANGELOG.md: $(ENTRIES) $(ENTRIES:%=FORCE)
@$(CHANGELOG) collect

FORCE:

docs:
cd docs && $(MAKE) html

release: changelog docs
214 changes: 214 additions & 0 deletions bin/changelog.py
Comment thread
mcepl marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
#!/usr/bin/env python3
"""Manage changelog entries in changelog.d/ (see changelog.d/README.md)."""

import argparse
import os
import re
import shlex
import shutil
import subprocess
import sys
import tempfile
from pathlib import Path

ROOT = Path(__file__).resolve().parent.parent
ENTRIES_DIR = ROOT / "changelog.d"
TEMPLATE = ENTRIES_DIR / "TEMPLATE.md"
CHANGELOG = ROOT / "CHANGELOG.md"
PYPROJECT = ROOT / "pyproject.toml"

# Entries live in changelog.d/<N>.md (or <N>-<suffix>.md), one or
# more per pull request, and are only folded into CHANGELOG.md at
# release time, so that pull requests do not all conflict on the
# top of CHANGELOG.md.


class ChangelogError(Exception):
pass


def read_text(path):
return path.read_text(encoding="utf-8")


def write_text(path, text):
path.write_text(text, encoding="utf-8", newline="\n")


def version():
match = re.search(
r"""^version\s*=\s*['"]([^'"]+)['"]""", read_text(PYPROJECT), re.M
)
if match is None:
raise ChangelogError(f"Cannot find version in {PYPROJECT.name}")
return match.group(1)


def entry_key(path):
"""Sort by number, then 1234.md, 1234-2.md, …, 1234-10.md"""
number = re.match(r"\d+", path.stem).group()
suffix = path.stem[len(number) :]
return int(number), len(suffix), suffix


def entry_files():
"""Return the entry files, sorted by issue/PR number"""
return sorted(
(
path
for path in ENTRIES_DIR.glob("*.md")
if path.name[0].isdigit() and path.is_file()
),
key=entry_key,
)


def entry_path(n):
path = ENTRIES_DIR / f"{n}.md"
suffix = 2
while path.exists():
path = ENTRIES_DIR / f"{n}-{suffix}.md"
suffix += 1
return path


def editor_command():
"""Return the user's editor as an argument list

Like git, prefer $VISUAL and $EDITOR, then git's own editor
(core.editor), and fall back to notepad or vi.
"""
editor = os.environ.get("VISUAL") or os.environ.get("EDITOR")
if not editor and shutil.which("git"):
try:
editor = subprocess.run(
["git", "var", "GIT_EDITOR"],
cwd=ROOT,
capture_output=True,
text=True,
check=True,
).stdout.strip()
except subprocess.CalledProcessError:
editor = None
if not editor:
editor = "notepad" if os.name == "nt" else "vi"
if os.name == "nt":
# Keep backslashes in Windows paths, just strip the quotes.
return [arg.strip('"') for arg in shlex.split(editor, posix=False)]
return shlex.split(editor)


def clean_entry(text):
"""Drop HTML comments, trailing whitespace and blank lines around"""
text = re.sub(r"<!--.*?-->", "", text, flags=re.S)
lines = [line.rstrip() for line in text.splitlines()]
return "\n".join(lines).strip("\n")


def cmd_add(n, text=None):
if not re.fullmatch(r"\d+", n):
raise ChangelogError(f"Not an issue/PR number: {n!r}")

if text:
entry = f"- #{n} {text}"
else:
template = read_text(TEMPLATE).replace("NNNN", n)
# Edit in a private directory, so that an aborted edit
# leaves nothing behind and the editor still sees a *.md
# file name.
with tempfile.TemporaryDirectory(prefix="changelog.") as tmpdir:
tmp = Path(tmpdir) / f"{n}.md"
write_text(tmp, template)
try:
subprocess.run([*editor_command(), str(tmp)], check=True)
except (OSError, subprocess.CalledProcessError) as err:
raise ChangelogError(f"Running the editor failed: {err}") from err
entry = read_text(tmp)
if clean_entry(entry) == clean_entry(template):
raise ChangelogError("Entry left unchanged, nothing written.")
entry = clean_entry(entry)

if not re.sub(rf"^- #{n}", "", entry).strip():
raise ChangelogError("Empty entry, nothing written.")

path = entry_path(n)
write_text(path, entry + "\n")
print(f"Created {path.relative_to(ROOT).as_posix()}:")
print(entry)


def release_section():
files = entry_files()
if not files:
raise ChangelogError(f"No entries in {ENTRIES_DIR.name}/")
entries = "".join(clean_entry(read_text(path)) + "\n" for path in files)
return f"# Release {version()}\n\n{entries}", files


def cmd_preview():
section, _ = release_section()
sys.stdout.write(section)


def cmd_collect():
section, files = release_section()
heading = section.splitlines()[0]
changelog = read_text(CHANGELOG)
if heading in changelog.splitlines():
raise ChangelogError(
f"{CHANGELOG.name} already has {heading!r}; "
f"bump version in {PYPROJECT.name} first"
)

# Keep whatever precedes the first release (the header).
match = re.search(r"^# Release ", changelog, re.M)
pos = match.start() if match else len(changelog)
write_text(CHANGELOG, f"{changelog[:pos]}{section}\n{changelog[pos:]}")
for path in files:
path.unlink()
try:
subprocess.run(
["git", "add", "-A", ENTRIES_DIR.name, CHANGELOG.name],
cwd=ROOT,
check=True,
)
except (OSError, subprocess.CalledProcessError) as err:
print(f"Warning: git add failed: {err}", file=sys.stderr)
print(f"{CHANGELOG.name} updated for {version()}; review and commit.")


def parse_args(argv):
parser = argparse.ArgumentParser(prog="changelog.py", description=__doc__)
commands = parser.add_subparsers(dest="command", required=True)
add = commands.add_parser(
"add",
help="add changelog.d/N.md (the default command)",
description="Add changelog.d/N.md, in an editor unless TEXT is given.",
)
add.add_argument("n", metavar="N", help="issue or pull request number")
add.add_argument("text", metavar="TEXT", nargs="?", help="the entry text")
commands.add_parser("preview", help="show the next release section")
commands.add_parser("collect", help="fold the entries into CHANGELOG.md")
# `changelog.py 1234 ...` is short for `changelog.py add 1234 ...`
if argv and argv[0].isdigit():
argv = ["add", *argv]
return parser.parse_args(argv)


def main(argv):
args = parse_args(argv)
try:
if args.command == "add":
cmd_add(args.n, args.text)
elif args.command == "preview":
cmd_preview()
else:
cmd_collect()
except ChangelogError as err:
print(err, file=sys.stderr)
return 1
return 0
Comment thread
mcepl marked this conversation as resolved.
Resolved


if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))
1 change: 1 addition & 0 deletions changelog.d/223.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- #223 Add regression tests for restructuring and patchedast with `elif(` written without a space (@mcepl)
5 changes: 5 additions & 0 deletions changelog.d/985.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- #985 Collect changelog entries from `changelog.d/` instead of
editing `CHANGELOG.md` directly, so that pull requests no longer
conflict with each other on the top of the changelog. Add yours
with `python bin/changelog.py <N>`, see `changelog.d/README.md`.
(@mcepl)
31 changes: 31 additions & 0 deletions changelog.d/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Changelog entries

Every pull request adds its changelog entry as a file in this
directory, named after the issue or pull request number, e.g.
`changelog.d/1234.md`. The entries are collected into
`CHANGELOG.md` when a new version is released.

## How to add an entry

Run

```sh
python bin/changelog.py 1234
```

It opens a text editor with `TEMPLATE.md` and saves the result
as `changelog.d/1234.md`. To use a different editor than the one
it picks, set the `VISUAL` or `EDITOR` environment variable. Or
give the text on the command line and skip the editor:

```sh
python bin/changelog.py 1234 'Fix renaming of keyword arguments (@yourname)'
```

Alternatively, copy `TEMPLATE.md` to `changelog.d/1234.md` and
edit it by hand. `TEMPLATE.md` also describes how to write the
entry.

`python bin/changelog.py preview` shows how the entries will look
in the next release; `python bin/changelog.py --help` lists all
commands.
15 changes: 15 additions & 0 deletions changelog.d/TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
- #NNNN Describe what changed, why, and what users of rope may
notice. (@your-github-handle)

<!--
Replace NNNN with the issue or pull request number and save this
file as changelog.d/NNNN.md.

The entry is a Markdown list item starting with the issue/PR
number; several related ones may be listed together, e.g.
"- #826, #940 ...". Wrap long lines and indent continuation lines
by two spaces. Do not hesitate to write more than a one-liner.
Credit yourself at the end.

This comment is removed when the entries are collected.
-->
7 changes: 6 additions & 1 deletion docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ BUILDDIR = _build
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile
.PHONY: help html Makefile

# Explicit rule, so that `make html` (used by the top-level
# Makefile) works with BSD make too, which lacks pattern rules.
html:
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
Expand Down
9 changes: 9 additions & 0 deletions docs/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ Follow the instructions on GitHub_ on how to setup Git and fork the
`python-rope/rope`_ repository. Once your changes are ready, send a
`pull request`_ for review.

Every pull request should add a changelog entry, a file in
``changelog.d/`` named after the issue or pull request number. To
create it, run::

python bin/changelog.py 1234

See ``changelog.d/README.md`` for details. Please do not edit
``CHANGELOG.md`` directly.


Programming Style
-----------------
Expand Down
15 changes: 8 additions & 7 deletions docs/release-process.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ Pre-Release
Release
-------

1. Ensure tickets assigned to Milestones are up to date
2. Update ``CHANGELOG.md``
1. Increment version number in ``pyproject.toml`` and collect the
changelog entries: ``python bin/changelog.py collect``
2. Ensure tickets assigned to Milestones are up to date and match
``CHANGELOG.md``
3. Close milestone
4. Increment version number in ``pyproject.toml``
5. `git commit && git push`
6. Tag the release with the tag annotation containing the release information,
4. ``git commit -a && git push``
5. Tag the release with the tag annotation containing the release information,
``python bin/tag-release.py``
7. Create Github Release
8. Publish release announcements to GitHub Discussions
6. Create Github Release
7. Publish release announcements to GitHub Discussions


Release Schedule
Expand Down
Loading