From c482123fe488581ea1f8817935a02eeaf353cda8 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Fri, 16 Aug 2024 17:42:12 +0200 Subject: [PATCH] Run Black so tests pass --- run_release.py | 12 +++--- tests/test_update_version_next.py | 41 ++++++++++---------- update_version_next.py | 63 ++++++++++++++++++------------- 3 files changed, 62 insertions(+), 54 deletions(-) diff --git a/run_release.py b/run_release.py index 2150550..67aa7b2 100755 --- a/run_release.py +++ b/run_release.py @@ -31,9 +31,9 @@ import release as release_mod import sbom +import update_version_next from buildbotapi import BuildBotAPI, Builder from release import ReleaseShelf, Tag, Task -import update_version_next API_KEY_REGEXP = re.compile(r"(?P\w+):(?P\w+)") RELEASE_REGEXP = re.compile( @@ -499,7 +499,7 @@ def bump_version(db: ReleaseShelf) -> None: def bump_version_in_docs(db: ReleaseShelf) -> None: - update_version_next.main([db['release'].doc_version, str(db["git_repo"])]) + update_version_next.main([db["release"].doc_version, str(db["git_repo"])]) subprocess.check_call( ["git", "commit", "-a", "--amend", "--no-edit"], cwd=db["git_repo"] ) @@ -564,7 +564,7 @@ def check_doc_unreleased_version(db: ReleaseShelf) -> None: # didn't do its job. # But, there could also be a false positive. release_tag = db["release"] - docs_path = Path(db["git_repo"] / str(release_tag) / 'docs') + docs_path = Path(db["git_repo"] / str(release_tag) / "docs") archive_path = docs_path / f"python-{release_tag}-docs-html.tar.bz2" if release_tag.includes_docs: assert archive_path.exists() @@ -574,13 +574,11 @@ def check_doc_unreleased_version(db: ReleaseShelf) -> None: "tar", "-xjf", archive_path, - '--to-command=! grep -Hn --label="$TAR_FILENAME" "[(]unrelesed[)]"' + '--to-command=! grep -Hn --label="$TAR_FILENAME" "[(]unrelesed[)]"', ], ) if proc.returncode != 0: - if not ask_question( - "Are these `(unreleased)` strings in built docs OK?" - ): + if not ask_question("Are these `(unreleased)` strings in built docs OK?"): proc.check_returncode() diff --git a/tests/test_update_version_next.py b/tests/test_update_version_next.py index 37bdc32..492ef70 100644 --- a/tests/test_update_version_next.py +++ b/tests/test_update_version_next.py @@ -1,8 +1,7 @@ """Tests for the update_version_next tool.""" -from pathlib import Path import unittest - +from pathlib import Path from test.support import os_helper import update_version_next @@ -58,7 +57,7 @@ .. deprecated-removed: 3.0 next """ -EXPECTED_CHANGED = TO_CHANGE.replace('next', 'VER') +EXPECTED_CHANGED = TO_CHANGE.replace("next", "VER") class TestVersionNext(unittest.TestCase): @@ -67,21 +66,23 @@ class TestVersionNext(unittest.TestCase): 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] + 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] update_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') + 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" + ) diff --git a/update_version_next.py b/update_version_next.py index b3d53a3..dd08274 100644 --- a/update_version_next.py +++ b/update_version_next.py @@ -18,7 +18,7 @@ from pathlib import Path DIRECTIVE_RE = re.compile( - r''' + r""" (?P \s*\.\.\s+ (version(added|changed|removed)|deprecated(-removed)?) @@ -28,27 +28,33 @@ (?P .* ) - ''', + """, re.VERBOSE | re.DOTALL, ) -doc_dir = (Path(__file__) - .parent # cpython/Doc/tools - .parent # cpython/Doc - .resolve() - ) +doc_dir = Path(__file__).parent.parent.resolve() # cpython/Doc/tools # cpython/Doc 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, nargs='?', - help=f'Directory to process. Default: {doc_dir}', - default=doc_dir) -parser.add_argument('--verbose', '-v', action='count', default=0, - help='Increase verbosity. Can be repeated (`-vv`).') + 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, + nargs="?", + help=f"Directory to process. Default: {doc_dir}", + default=doc_dir, +) +parser.add_argument( + "--verbose", + "-v", + action="count", + default=0, + help="Increase verbosity. Can be repeated (`-vv`).", +) def main(argv): @@ -57,30 +63,33 @@ def main(argv): 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'): + file=sys.stderr, + ) + for path in Path(args.directory).glob("**/*.rst"): num_changed_lines = 0 lines = [] - with open(path, encoding='utf-8') as file: + 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'] + 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}') + exc.add_note(f"processing line {path}:{lineno}") raise if num_changed_lines: if args.verbose: - print(f'Updating file {path} ({num_changed_lines} changes)', - file=sys.stderr) - with open(path, 'w', encoding='utf-8') as file: + print( + f"Updating file {path} ({num_changed_lines} changes)", + 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) + print(f"Unchanged file {path}", file=sys.stderr) -if __name__ == '__main__': +if __name__ == "__main__": main(sys.argv[1:])