Skip to content

Commit

Permalink
Run Black so tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
encukou committed Aug 16, 2024
1 parent 4280a27 commit c482123
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 54 deletions.
12 changes: 5 additions & 7 deletions run_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<user>\w+):(?P<key>\w+)")
RELEASE_REGEXP = re.compile(
Expand Down Expand Up @@ -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(

Check warning on line 503 in run_release.py

View check run for this annotation

Codecov / codecov/patch

run_release.py#L502-L503

Added lines #L502 - L503 were not covered by tests
["git", "commit", "-a", "--amend", "--no-edit"], cwd=db["git_repo"]
)
Expand Down Expand Up @@ -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()
Expand All @@ -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()

Check warning on line 582 in run_release.py

View check run for this annotation

Codecov / codecov/patch

run_release.py#L580-L582

Added lines #L580 - L582 were not covered by tests


Expand Down
41 changes: 21 additions & 20 deletions tests/test_update_version_next.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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"
)
63 changes: 36 additions & 27 deletions update_version_next.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from pathlib import Path

DIRECTIVE_RE = re.compile(
r'''
r"""
(?P<before>
\s*\.\.\s+
(version(added|changed|removed)|deprecated(-removed)?)
Expand All @@ -28,27 +28,33 @@
(?P<after>
.*
)
''',
""",
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):
Expand All @@ -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:])

0 comments on commit c482123

Please sign in to comment.