Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 45
cpython#121277: Replace next versions in docs by the just-released version#164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
12 commits Select commit Hold shift + click to select a range
7977f16 Update versionadded:: next (and similar directives) on release
encukou 4280a27 Grep built docs for the string '(unreleased)'
encukou c482123 Run Black so tests pass
encukou a4f28cb Add type hints so more tests pass
encukou ee9deb8 Add tests for docs-related Tag attributes
encukou b47e793 Add tests for the check_doc_unreleased_version step
encukou 64439b4 Apply suggestions from code review
encukou 0714683 Convert to pytest-style test
encukou a3dfea5 Remove default from doc_dir
encukou fc90538 Type the test fixture
encukou 8995b8b Apply suggestions from code review
encukou 2071a8d Make the script executable
encukou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| """Tests for the update_version_next tool.""" | ||
| from pathlib import Path | ||
| import update_version_next | ||
| TO_CHANGE = """ | ||
| Directives to change | ||
| -------------------- | ||
| Here, all occurences of NEXT (lowercase) should be changed: | ||
| .. versionadded:: next | ||
| .. versionchanged:: next | ||
| .. deprecated:: next | ||
| .. deprecated-removed:: next 4.0 | ||
| whitespace: | ||
| .. versionchanged:: next | ||
| .. versionchanged :: next | ||
| .. versionadded:: next | ||
| arguments: | ||
| .. versionadded:: next | ||
| Foo bar | ||
| .. versionadded:: next as ``previousname`` | ||
| """ | ||
| UNCHANGED = """ | ||
| Unchanged | ||
| --------- | ||
| Here, the word "next" should NOT be changed: | ||
| .. versionchanged:: NEXT | ||
| ..versionchanged:: NEXT | ||
| ... versionchanged:: next | ||
| foo .. versionchanged:: next | ||
| .. otherdirective:: next | ||
| .. VERSIONCHANGED: next | ||
| .. deprecated-removed: 3.0 next | ||
| """ | ||
| EXPECTED_CHANGED = TO_CHANGE.replace("next", "VER") | ||
| def test_freeze_simple_script(tmp_path: Path) -> None: | ||
| p = tmp_path.joinpath | ||
| p("source.rst").write_text(TO_CHANGE + UNCHANGED) | ||
| p("subdir").mkdir() | ||
| p("subdir/change.rst").write_text(".. versionadded:: next") | ||
| p("subdir/keep.not-rst").write_text(".. versionadded:: next") | ||
| p("subdir/keep.rst").write_text("nothing to see here") | ||
| args = ["VER", str(tmp_path)] | ||
| update_version_next.main(args) | ||
| assert p("source.rst").read_text() == EXPECTED_CHANGED + UNCHANGED | ||
| assert p("subdir/change.rst").read_text() == ".. versionadded:: VER" | ||
| assert p("subdir/keep.not-rst").read_text() == ".. versionadded:: next" | ||
| assert p("subdir/keep.rst").read_text() == "nothing to see here" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| #!/usr/bin/env python3 | ||
encukou marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| """ | ||
| Replace `.. versionchanged:: next` lines in docs files by the given version. | ||
| Run this at release time to replace `next` with the just-released version | ||
| in the sources. | ||
| No backups are made; add/commit to Git before running the script. | ||
| Applies to all the VersionChange directives. For deprecated-removed, only | ||
| handle the first argument (deprecation version, not the removal version). | ||
| """ | ||
| import argparse | ||
| import re | ||
| import sys | ||
| from pathlib import Path | ||
| DIRECTIVE_RE = re.compile( | ||
| r""" | ||
| (?P<before> | ||
| \s*\.\.\s+ | ||
| (version(added|changed|removed)|deprecated(-removed)?) | ||
| \s*::\s* | ||
| ) | ||
| next | ||
| (?P<after> | ||
| .* | ||
| ) | ||
| """, | ||
| re.VERBOSE | re.DOTALL, | ||
| ) | ||
| parser = argparse.ArgumentParser( | ||
| description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter | ||
| ) | ||
| parser.add_argument( | ||
| "version", | ||
| help='String to replace "next" with. Usually `x.y`, but can be anything.', | ||
| ) | ||
| parser.add_argument( | ||
| "directory", | ||
| type=Path, | ||
| help="Directory to process", | ||
| ) | ||
| parser.add_argument( | ||
| "--verbose", | ||
| "-v", | ||
| action="count", | ||
| default=0, | ||
| help="Increase verbosity. Can be repeated (`-vv`).", | ||
| ) | ||
| def main(argv: list[str]) -> None: | ||
| args = parser.parse_args(argv) | ||
| version = args.version | ||
encukou marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| if args.verbose: | ||
| print( | ||
| f'Updating "next" versions in{args.directory} to{version!r}', | ||
| file=sys.stderr, | ||
| ) | ||
| for path in Path(args.directory).glob("**/*.rst"): | ||
| num_changed_lines = 0 | ||
| lines = [] | ||
| with open(path, encoding="utf-8") as file: | ||
| for lineno, line in enumerate(file, start=1): | ||
| try: | ||
| if match := DIRECTIVE_RE.fullmatch(line): | ||
| line = match["before"] + version + match["after"] | ||
| num_changed_lines += 1 | ||
| lines.append(line) | ||
| except Exception as exc: | ||
| exc.add_note(f"processing line{path}:{lineno}") | ||
| raise | ||
| if num_changed_lines: | ||
| if args.verbose: | ||
| s = "" if num_changed_lines == 1 else "s" | ||
| print( | ||
| f"Updating file{path} ({num_changed_lines} change{s})", | ||
| file=sys.stderr, | ||
| ) | ||
| with open(path, "w", encoding="utf-8") as file: | ||
| file.writelines(lines) | ||
| else: | ||
| if args.verbose > 1: | ||
| print(f"Unchanged file{path}", file=sys.stderr) | ||
| if __name__ == "__main__": | ||
| main(sys.argv[1:]) | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.