Upgrade some old syntax (#4338)
Signed-off-by: Tomasz Kłoczko <kloczek@github.com> Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
This commit is contained in:
parent
455de7703e
commit
0c033f3eb7
@ -1,4 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Configuration file for the Sphinx documentation builder.
|
||||
#
|
||||
@ -24,7 +23,7 @@
|
||||
def make_pypi_svg(version: str) -> None:
|
||||
template: Path = CURRENT_DIR / "_static" / "pypi_template.svg"
|
||||
target: Path = CURRENT_DIR / "_static" / "pypi.svg"
|
||||
with open(str(template), "r", encoding="utf8") as f:
|
||||
with open(str(template), encoding="utf8") as f:
|
||||
svg: str = string.Template(f.read()).substitute(version=version)
|
||||
with open(str(target), "w", encoding="utf8") as f:
|
||||
f.write(svg)
|
||||
|
@ -24,17 +24,12 @@
|
||||
from base64 import b64encode
|
||||
from io import BytesIO
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
from typing import Any, Final, Literal
|
||||
|
||||
import click
|
||||
import urllib3
|
||||
from packaging.version import Version
|
||||
|
||||
if sys.version_info >= (3, 8):
|
||||
from typing import Final, Literal
|
||||
else:
|
||||
from typing_extensions import Final, Literal
|
||||
|
||||
COMMENT_FILE: Final = ".pr-comment.json"
|
||||
DIFF_STEP_NAME: Final = "Generate HTML diff report"
|
||||
DOCS_URL: Final = (
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
|
||||
def git(*args: str) -> str:
|
||||
return check_output(["git"] + list(args)).decode("utf8").strip()
|
||||
return check_output(["git", *args]).decode("utf8").strip()
|
||||
|
||||
|
||||
def blackify(base_branch: str, black_command: str, logger: logging.Logger) -> int:
|
||||
@ -26,19 +26,19 @@ def blackify(base_branch: str, black_command: str, logger: logging.Logger) -> in
|
||||
merge_base = git("merge-base", "HEAD", base_branch)
|
||||
if not merge_base:
|
||||
logger.error(
|
||||
"Could not find a common commit for current head and %s" % base_branch
|
||||
f"Could not find a common commit for current head and {base_branch}"
|
||||
)
|
||||
return 1
|
||||
|
||||
commits = git(
|
||||
"log", "--reverse", "--pretty=format:%H", "%s~1..HEAD" % merge_base
|
||||
"log", "--reverse", "--pretty=format:%H", f"{merge_base}~1..HEAD"
|
||||
).split()
|
||||
for commit in commits:
|
||||
git("checkout", commit, "-b%s-black" % commit)
|
||||
git("checkout", commit, f"-b{commit}-black")
|
||||
check_output(black_command, shell=True)
|
||||
git("commit", "-aqm", "blackify")
|
||||
|
||||
git("checkout", base_branch, "-b%s-black" % current_branch)
|
||||
git("checkout", base_branch, f"-b{current_branch}-black")
|
||||
|
||||
for last_commit, commit in zip(commits, commits[1:]):
|
||||
allow_empty = (
|
||||
@ -51,7 +51,7 @@ def blackify(base_branch: str, black_command: str, logger: logging.Logger) -> in
|
||||
"diff",
|
||||
"--binary",
|
||||
"--find-copies",
|
||||
"%s-black..%s-black" % (last_commit, commit),
|
||||
f"{last_commit}-black..{commit}-black"
|
||||
],
|
||||
stdout=PIPE,
|
||||
)
|
||||
|
@ -11,8 +11,7 @@
|
||||
import sys
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from subprocess import PIPE, run
|
||||
from typing import List
|
||||
from subprocess import run
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
NEW_VERSION_CHANGELOG_TEMPLATE = """\
|
||||
@ -70,9 +69,9 @@ class NoGitTagsError(Exception): ... # noqa: E701,E761
|
||||
|
||||
# TODO: Do better with alpha + beta releases
|
||||
# Maybe we vendor packaging library
|
||||
def get_git_tags(versions_only: bool = True) -> List[str]:
|
||||
def get_git_tags(versions_only: bool = True) -> list[str]:
|
||||
"""Pull out all tags or calvers only"""
|
||||
cp = run(["git", "tag"], stdout=PIPE, stderr=PIPE, check=True, encoding="utf8")
|
||||
cp = run(["git", "tag"], capture_output=True, check=True, encoding="utf8")
|
||||
if not cp.stdout:
|
||||
LOG.error(f"Returned no git tags stdout: {cp.stderr}")
|
||||
raise NoGitTagsError
|
||||
|
@ -119,13 +119,13 @@ def pytest_collection_modifyitems(config: "Config", items: "List[Node]") -> None
|
||||
item.add_marker(skip_mark(frozenset(optional_markers_on_test)))
|
||||
|
||||
|
||||
@lru_cache()
|
||||
@lru_cache
|
||||
def skip_mark(tests: FrozenSet[str]) -> "MarkDecorator":
|
||||
names = ", ".join(sorted(tests))
|
||||
return pytest.mark.skip(reason=f"Marked with disabled optional tests ({names})")
|
||||
|
||||
|
||||
@lru_cache()
|
||||
@lru_cache
|
||||
def no(name: str) -> str:
|
||||
if name.startswith("no_"):
|
||||
return name[len("no_") :]
|
||||
|
@ -2984,7 +2984,7 @@ def test_equivalency_ast_parse_failure_includes_error(self) -> None:
|
||||
|
||||
|
||||
try:
|
||||
with open(black.__file__, "r", encoding="utf-8") as _bf:
|
||||
with open(black.__file__, encoding="utf-8") as _bf:
|
||||
black_source_lines = _bf.readlines()
|
||||
except UnicodeDecodeError:
|
||||
if not black.COMPILED:
|
||||
|
@ -230,7 +230,7 @@ def _parse_minimum_version(version: str) -> Tuple[int, int]:
|
||||
return int(major), int(minor)
|
||||
|
||||
|
||||
@functools.lru_cache()
|
||||
@functools.lru_cache
|
||||
def get_flags_parser() -> argparse.ArgumentParser:
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument(
|
||||
@ -303,7 +303,7 @@ def parse_mode(flags_line: str) -> TestCaseArgs:
|
||||
|
||||
|
||||
def read_data_from_file(file_name: Path) -> Tuple[TestCaseArgs, str, str]:
|
||||
with open(file_name, "r", encoding="utf8") as test:
|
||||
with open(file_name, encoding="utf8") as test:
|
||||
lines = test.readlines()
|
||||
_input: List[str] = []
|
||||
_output: List[str] = []
|
||||
|
Loading…
Reference in New Issue
Block a user