Skip to content
Open
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 fragment 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
5 changes: 0 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
# **Upcoming release**

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


# Release 1.16.0

- #859 Fix `find_definition`/Rename not resolving `async def` methods called via `self` (@gadievron)
Expand Down
33 changes: 33 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Maintenance tasks for rope.
#
# Changelog entries live as individual fragments in changelog.d/
# (one file per PR, see changelog.d/README.md) and are only merged
# into CHANGELOG.md at release time, so that pull requests do not
# keep conflicting on the top of CHANGELOG.md. The real work is done
# by bin/news; this Makefile is kept portable (GNU make, BSD make).

NEWS = ./bin/news

.PHONY: help news changelog-preview changelog docs release

help:
@echo "make news N=<issue/PR> write a changelog fragment in \$$EDITOR"
@echo " (or bin/news <issue/PR>)"
@echo "make changelog-preview show the pending changelog entries"
@echo "make changelog fold fragments into CHANGELOG.md"
@echo "make docs build the HTML documentation"
@echo "make release changelog + docs"

news:
@$(NEWS) add "$$N" "$$TEXT"

changelog-preview:
@$(NEWS) preview

changelog:
@$(NEWS) collect

docs:
cd docs && $(MAKE) html

release: changelog docs
132 changes: 132 additions & 0 deletions bin/news
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
#!/bin/sh
# Manage changelog fragments in changelog.d/ (see changelog.d/README.md).
#
# bin/news [add] <issue/PR> [text] create changelog.d/<issue/PR>.md,
# in $VISUAL/$EDITOR unless text given
# bin/news preview show the pending release section
# bin/news collect fold the fragments into CHANGELOG.md
#
# Deliberately plain POSIX sh, so it works the same on Linux, the BSDs
# and macOS.

set -eu

cd "$(dirname "$0")/.."
NEWS_DIR=changelog.d
CHANGELOG=CHANGELOG.md

die() {
printf '%s\n' "$*" >&2
exit 1
}

usage() {
sed -n '4,7s/^# \{0,1\}//p' "$0" >&2
exit 2
}

version() {
v=$(sed -n "s/^version *= *['\"]\([^'\"]*\)['\"].*/\1/p" pyproject.toml)
[ -n "$v" ] || die "Cannot find version in pyproject.toml"
printf '%s\n' "$v"
}

# Fragment file names, sorted by issue number.
fragments() {
for f in "$NEWS_DIR"/[0-9]*.md; do
[ -e "$f" ] && basename "$f"
done | sort -n | sed "s|^|$NEWS_DIR/|"
}

template() {
cat <<EOF
- #$1

# Describe your change for the changelog of the next release.
#
# The entry is a Markdown list item starting with the issue/PR
# number; wrap long lines and indent continuation lines by two
# spaces. Do not hesitate to write more than a one-liner: say
# what changed, why, and what users of rope may notice.
# Credit yourself at the end, e.g. (@your-github-handle).
#
# Lines starting with '# ' are removed. Leaving the entry empty
# aborts.
EOF
}

cmd_add() {
[ $# -ge 1 ] && [ -n "$1" ] || usage
n=$1
shift
case $n in
*[!0-9]*) die "Not an issue/PR number: '$n'" ;;
esac
text="$*"

f="$NEWS_DIR/$n.md"
[ ! -e "$f" ] || f="$NEWS_DIR/$n-$(date +%s).md"

# Edit in a private directory, so that an aborted edit leaves
# nothing behind and the editor still sees a *.md file name.
tmpdir=$(mktemp -d "${TMPDIR:-/tmp}/news.XXXXXX")
trap 'rm -rf "$tmpdir"' EXIT
tmp="$tmpdir/$n.md"

if [ -n "$text" ]; then
printf -- '- #%s %s\n' "$n" "$text" >"$tmp"
else
template "$n" >"$tmp"
# unquoted on purpose: allow e.g. EDITOR='code --wait'
${VISUAL:-${EDITOR:-vi}} "$tmp"
fi

# drop comments and leading (and, via $(), trailing) blank lines
entry=$(grep -v -E '^#( |$)' "$tmp" | sed -e '/./,$!d')
rest=$(printf '%s' "$entry" | sed -e "s/^- #$n//" | tr -d '[:space:]')
[ -n "$rest" ] || die "Empty entry, nothing written."

printf '%s\n' "$entry" >"$f"
printf 'Created %s:\n' "$f"
cat "$f"
}

cmd_preview() {
files=$(fragments)
[ -n "$files" ] || die "No fragments in $NEWS_DIR/"
printf '# Release %s\n\n' "$(version)"
# shellcheck disable=SC2086 # file names are digits and dashes only
cat $files
}

cmd_collect() {
v=$(version)
files=$(fragments)
[ -n "$files" ] || die "No fragments in $NEWS_DIR/"
! grep -q -x -F "# Release $v" "$CHANGELOG" ||
die "$CHANGELOG already has 'Release $v';" \
"bump version in pyproject.toml first"

tmp=$(mktemp "${TMPDIR:-/tmp}/changelog.XXXXXX")
trap 'rm -f "$tmp"' EXIT
{
cmd_preview
echo
cat "$CHANGELOG"
} >"$tmp"
cat "$tmp" >"$CHANGELOG"
# shellcheck disable=SC2086
rm -f $files
git add -A "$NEWS_DIR" "$CHANGELOG"
echo "$CHANGELOG updated for $v; review and commit."
}

[ $# -ge 1 ] || usage
case $1 in
add) shift; cmd_add "$@" ;;
preview) cmd_preview ;;
collect) cmd_collect ;;
-h | --help | help) usage ;;
[0-9]*) cmd_add "$@" ;;
*) usage ;;
esac
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)
1 change: 1 addition & 0 deletions changelog.d/886.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#886 Track and close SQLite connections created in worker threads in AutoImport (@mcepl)
1 change: 1 addition & 0 deletions changelog.d/985.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- #985 create new system for combining CHANGELOG.md from individual snippets for each PR (@mcepl)
51 changes: 51 additions & 0 deletions changelog.d/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Changelog fragments

Instead of editing `CHANGELOG.md` directly (which makes nearly
every pull request conflict with every other one), each pull
request adds a small file to this directory. The fragments are
merged into `CHANGELOG.md` by `make changelog` (part of
`make release`) when a new version is released.

## How to add an entry

Create a file named after the issue or pull request number, e.g.
`changelog.d/1234.md`. If you need more than one fragment for the
same number, add a suffix: `1234-docs.md`. The file name **must**
start with a digit and end in `.md`; other files (like this one)
are ignored.

The easiest way is to run

```sh
bin/news 1234 # or: make news N=1234
```

which opens `$VISUAL`/`$EDITOR` (falling back to `vi`) with a
template and saves the result as `changelog.d/1234.md`. Leaving
the entry empty aborts without creating anything.

The content is one or more Markdown list items, in the same style
as the existing `CHANGELOG.md`. Please don't limit yourself to a
terse one-liner: explain what changed, why, and what users of
rope may notice. Wrap long lines and indent continuation lines by
two spaces:

```markdown
- #1234 Fix renaming of keyword arguments when inlining a method
whose body conflicts with names in the host scope; previously
rope produced `__0__from_lang=` in the result. (@yourname)
```

Several related issues may be listed together, e.g.
`- #826, #940 Keep star imports …`.

For scripts, `bin/news 1234 'Short description (@you)'` (or
`make news N=1234 TEXT='...'`) writes the fragment without
starting an editor.

Use `bin/news preview` (or `make changelog-preview`) to see what
the next release section will look like.

`bin/news` is a plain POSIX shell script and the `Makefile` is
portable, so this works with both GNU and BSD make, on Linux, the
BSDs and macOS.
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
15 changes: 15 additions & 0 deletions docs/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,21 @@ 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.

Please do not edit ``CHANGELOG.md`` directly. Instead, add a small
changelog fragment named after the issue or pull request number to the
``changelog.d/`` directory. Running ``bin/news 1234`` (or
``make news N=1234``) opens your ``$EDITOR`` with a template and
creates ``changelog.d/1234.md``, e.g.::

- #1234 Fix renaming of keyword arguments when inlining a method
whose body conflicts with names in the host scope. (@yourname)

Longer entries explaining what changed and why are welcome.

The fragments are collected into ``CHANGELOG.md`` at release time, which
avoids merge conflicts between pull requests. See
``changelog.d/README.md`` for details.


Programming Style
-----------------
Expand Down
17 changes: 16 additions & 1 deletion docs/library.rst
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,22 @@ by passing memory=False to AutoImport constructor. This default will change in
the future, if you want to always store the autoimport cache in-memory, then
you need to explicitly pass memory=True.

It must be closed when done with the ``AutoImport.close()`` method.
It must be closed when done with the ``AutoImport.close()`` method. Each
thread uses its own SQLite connection; do not pass connections between threads.
When sharing an instance, stop and join worker threads before calling
``close()``. It raises ``RopeError`` rather than closing a connection owned by
another live thread. Alternatively, workers can release their connections with
``close_thread_connection()`` before shutdown. Connections left by finished
workers are closed when another thread creates a connection or when ``close()``
runs.
If committing or closing a connection fails, ``close()`` attempts to close
all remaining connections before raising the first SQLite error.

Assigning to ``AutoImport.connection`` replaces the current thread's
connection without closing the old one. The caller must close the old
connection; ``AutoImport`` only tracks and closes the replacement. If the
assignment is rejected, the supplied connection remains the caller's
responsibility.

AutoImport can search for a name from both modules and statements you can import from them.

Expand Down
10 changes: 6 additions & 4 deletions docs/release-process.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ Release
-------

1. Ensure tickets assigned to Milestones are up to date
2. Update ``CHANGELOG.md``
3. Close milestone
4. Increment version number in ``pyproject.toml``
5. `git commit && git push`
2. Close milestone
3. Increment version number in ``pyproject.toml``
4. Run ``make release``: it folds the fragments from ``changelog.d/``
into ``CHANGELOG.md`` (``git rm``-ing the fragments) and builds the
documentation; ``make changelog-preview`` shows the result in advance
5. Review ``CHANGELOG.md``, then ``git commit -a && git push``
6. Tag the release with the tag annotation containing the release information,
``python bin/tag-release.py``
7. Create Github Release
Expand Down
Loading
Loading