-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
gh-121277: Allow .. versionadded:: next
in docs
#121278
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
Merged
Changes from 2 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
f0005e7
Make `versionchanged:: next`` expand to current (unreleased) version
encukou 0c86239
Use in existing docs
encukou e270ddc
Apply extension suggestions from code review
encukou 0022e1a
Update Doc/tools/extensions/pyspecific.py
encukou 342838d
Fix location of the the Doc dir
encukou 1d9a618
Specify encoding
encukou 311bceb
Improve the docstring/usage
encukou 72a3162
Re-add stray removed line
encukou 91bd511
Split long line
encukou 46ae814
Set `env` before using it
encukou 9c4502c
Add a blurb
encukou 426aae1
Merge in the main branch
encukou 993dd5c
Consolidate VersionChange imports
encukou 5f2b612
Apply suggestions from code review
encukou 8b8a2f9
Expand help
encukou d163647
Add lineno to exceptions
encukou 757cf6b
Remove the tool; that now lives in the release-tools repo
encukou 7136c0e
Merge in the main branch
encukou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
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,76 @@ | ||
#!/usr/bin/env python3 | ||
""" | ||
Replace `.. versionchanged:: next` lines in docs files by the given version. | ||
|
||
Applies to all the VersionChange directives. For deprecated-removed, only | ||
handle the first argument (deprecation version, not the removal version). | ||
|
||
AA-Turner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
|
||
import re | ||
import sys | ||
import argparse | ||
from pathlib import Path | ||
|
||
DIRECTIVE_RE = re.compile( | ||
r''' | ||
(?P<before> | ||
\s*\.\.\s+ | ||
(version(added|changed|removed)|deprecated(-removed)?) | ||
\s*::\s* | ||
AA-Turner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
next | ||
(?P<after> | ||
.* | ||
) | ||
''', | ||
re.VERBOSE | re.DOTALL, | ||
) | ||
|
||
basedir = (Path(__file__) | ||
.parent # cpython/Tools/doc | ||
.parent # cpython/Tools | ||
.parent # cpython | ||
.resolve() | ||
) | ||
docdir = basedir / 'Doc' | ||
encukou marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
parser = argparse.ArgumentParser( | ||
description=__doc__, | ||
formatter_class=argparse.RawDescriptionHelpFormatter) | ||
parser.add_argument('version', | ||
help='String to replace "next" with.') | ||
encukou marked this conversation as resolved.
Show resolved
Hide resolved
|
||
parser.add_argument('directory', type=Path, nargs='?', | ||
help=f'Directory to process. Default: {docdir}', | ||
default=docdir) | ||
encukou marked this conversation as resolved.
Show resolved
Hide resolved
|
||
parser.add_argument('--verbose', '-v', action='count', default=0) | ||
encukou marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def main(argv): | ||
encukou marked this conversation as resolved.
Show resolved
Hide resolved
|
||
args = parser.parse_args(argv) | ||
version = args.version | ||
encukou marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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'): | ||
encukou marked this conversation as resolved.
Show resolved
Hide resolved
|
||
num_changed_lines = 0 | ||
lines = [] | ||
with open(path) as file: | ||
for lineno, line in enumerate(file, start=1): | ||
if match := DIRECTIVE_RE.fullmatch(line): | ||
line = match['before'] + version + match['after'] | ||
num_changed_lines += 1 | ||
lines.append(line) | ||
if num_changed_lines: | ||
if args.verbose: | ||
print(f'Updating file {path} ({num_changed_lines} changes)', | ||
file=sys.stderr) | ||
encukou marked this conversation as resolved.
Show resolved
Hide resolved
|
||
with open(path, 'w') as file: | ||
file.writelines(lines) | ||
AA-Turner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
else: | ||
if args.verbose > 1: | ||
print(f'Unchanged file {path}', file=sys.stderr) | ||
|
||
|
||
if __name__ == '__main__': | ||
main(sys.argv[1:]) |
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,99 @@ | ||
"""Sanity-check tests for the "docs/replace_versoin_next" tool.""" | ||
encukou marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
from pathlib import Path | ||
import unittest | ||
|
||
from test.test_tools import basepath | ||
from test.support.import_helper import DirsOnSysPath, import_module | ||
from test.support import os_helper | ||
from test import support | ||
|
||
print(basepath) | ||
tooldir = Path(basepath) / 'Doc' / 'tools' | ||
print(tooldir) | ||
|
||
with DirsOnSysPath(str(tooldir)): | ||
import sys | ||
print(sys.path) | ||
version_next = import_module('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') | ||
|
||
|
||
class TestVersionNext(unittest.TestCase): | ||
maxDiff = len(TO_CHANGE + UNCHANGED) * 10 | ||
|
||
def test_freeze_simple_script(self): | ||
with os_helper.temp_dir() as testdir: | ||
path = Path(testdir) | ||
path.joinpath('source.rst').write_text(TO_CHANGE + UNCHANGED) | ||
path.joinpath('subdir').mkdir() | ||
path.joinpath('subdir/change.rst').write_text( | ||
'.. versionadded:: next') | ||
path.joinpath('subdir/keep.not-rst').write_text( | ||
'.. versionadded:: next') | ||
path.joinpath('subdir/keep.rst').write_text( | ||
'nothing to see here') | ||
args = ['VER', testdir] | ||
if support.verbose: | ||
args.append('-vv') | ||
version_next.main(args) | ||
self.assertEqual(path.joinpath('source.rst').read_text(), | ||
EXPECTED_CHANGED + UNCHANGED) | ||
self.assertEqual(path.joinpath('subdir/change.rst').read_text(), | ||
'.. versionadded:: VER') | ||
self.assertEqual(path.joinpath('subdir/keep.not-rst').read_text(), | ||
'.. versionadded:: next') | ||
self.assertEqual(path.joinpath('subdir/keep.rst').read_text(), | ||
'nothing to see here') |
Oops, something went wrong.
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.