Skip to content

The agent that grows with you

style(code-health): wrap the long lines added by the lane-C fixes

Teknium7ceedd731a82
diff --git a/scripts/check b/scripts/check
index fbf1f522f8e..21c4cb53aed 100755
--- a/scripts/check
+++ b/scripts/check
@@ -74,15 +74,16 @@ judge() { # judge TREE-ISH ARGS...: check out TREE-ISH alone and run its own sc
"""
_HOOKS = {
# git may export a relative GIT_INDEX_FILE, and the checker runs from another directory.
- "pre-commit": _HOOK_HEAD + r"""GIT_INDEX_FILE="$(git rev-parse --path-format=absolute --git-path index)" || exit 1
-export GIT_INDEX_FILE
+ "pre-commit": _HOOK_HEAD + """\
+index="$(git rev-parse --path-format=absolute --git-path index)" || exit 1
+export GIT_INDEX_FILE="$index"
tree="$(git write-tree)" || exit 1
git cat-file -e "$tree:scripts/check" 2>/dev/null || exit 0
judge "$tree" --staged
""",
# stdin: "<local ref> <local sha> <remote ref> <remote sha>" per pushed ref; an all-zero
# local sha is a deletion. Each pushed commit is judged as CI will judge the PR.
- "pre-push": _HOOK_HEAD + r"""status=0
+ "pre-push": _HOOK_HEAD + """status=0
while read -r _ local_sha _ _; do
case "$local_sha" in *[!0]*) ;; *) continue ;; esac
git cat-file -e "$local_sha:scripts/check" 2>/dev/null || continue
diff --git a/scripts/code_health/cli.py b/scripts/code_health/cli.py
index 7f7e53a1446..2d54a167010 100644
--- a/scripts/code_health/cli.py
+++ b/scripts/code_health/cli.py
@@ -36,8 +36,9 @@ _MODES = ("blocking", "advisory", "off")
def parse_switch(text: str) -> str:
- """The module-level ``ENFORCEMENT`` value (plain or annotated assignment, the last one wins,
- as at runtime). Missing, unparseable or unknown is "blocking": no edit relaxes it by accident."""
+ """The module-level ``ENFORCEMENT`` value (plain or annotated assignment; the last one wins,
+ as at runtime). Missing, unparseable or unknown is "blocking", so no edit relaxes it by
+ accident."""
try:
body = ast.parse(text).body
except SyntaxError:
diff --git a/scripts/code_health/gitio.py b/scripts/code_health/gitio.py
index 726c6ac51cb..24d746db5ae 100644
--- a/scripts/code_health/gitio.py
+++ b/scripts/code_health/gitio.py
@@ -43,7 +43,8 @@ def resolve_tree(repo: Path, rev: str) -> str:
def commit_or_none(repo: Path, rev: str) -> str | None:
"""``rev`` as a commit sha, or None when it does not name a commit (a tree, a missing ref)."""
- return git(repo, "rev-parse", "--verify", "--quiet", f"{rev}^{{commit}}", check=False).strip() or None
+ out = git(repo, "rev-parse", "--verify", "--quiet", f"{rev}^{{commit}}", check=False)
+ return out.strip() or None
def default_base(repo: Path, tip: str = "HEAD") -> str:
diff --git a/scripts/code_health/report.py b/scripts/code_health/report.py
index 2efe4af027c..88137ce6c23 100644
--- a/scripts/code_health/report.py
+++ b/scripts/code_health/report.py
@@ -33,7 +33,7 @@ def apply_allows(findings: list[Finding], head: dict[str, FileMeasure]) -> None:
for line_no in _allow_lines(finding, fm):
text = fm.comments.get(line_no, "")
match = _ALLOW.search(text)
- # `allow BLE001 S110` and `allow BLE001, S110` both name two rules (_ALLOW takes either).
+ # `allow BLE001 S110` and `allow BLE001, S110` both name two rules (_ALLOW takes both).
if match and finding.rule in re.split(r"[,\s]+", match.group(1).strip()):
finding.allowed_reason = match.group(2).strip()
break
diff --git a/tests/scripts/test_code_health_cli.py b/tests/scripts/test_code_health_cli.py
index 8a132f44556..b30aaeac599 100644
--- a/tests/scripts/test_code_health_cli.py
+++ b/tests/scripts/test_code_health_cli.py
@@ -47,8 +47,8 @@ def _sh(cwd: Path, *argv: str, env: dict[str, str] | None = None) -> subprocess.
timeout=600, check=False)
-def _git(repo: Path, *args: str, env: dict[str, str] | None = None) -> str:
- proc = _sh(repo, "git", *args, env=env)
+def _git(repo: Path, *args: str) -> str:
+ proc = _sh(repo, "git", *args)
assert proc.returncode == 0, (args, proc.stdout, proc.stderr)
return proc.stdout.strip()
@@ -63,10 +63,10 @@ def _write(repo: Path, files: Mapping[str, str | None]) -> None:
path.write_text(text, encoding="utf-8")
-def _commit(repo: Path, files: Mapping[str, str | None], env: dict[str, str] | None = None) -> str:
+def _commit(repo: Path, files: Mapping[str, str | None]) -> str:
_write(repo, files)
_git(repo, "add", "--all", "--", *files)
- _git(repo, "commit", "-q", "-m", "step", env=env)
+ _git(repo, "commit", "-q", "-m", "step")
return _git(repo, "rev-parse", "HEAD")
@@ -104,8 +104,8 @@ def _engine_repo(tmp_path: Path) -> Path:
return repo
-def _check(repo: Path, *args: str, env: dict[str, str] | None = None) -> subprocess.CompletedProcess:
- return _sh(repo, sys.executable, str(repo / "scripts/check"), *args, env=env)
+def _check(repo: Path, *args: str) -> subprocess.CompletedProcess:
+ return _sh(repo, sys.executable, str(repo / "scripts/check"), *args)
def _ratchet_repo(tmp_path: Path, switch: str | None = None) -> tuple[Path, str]:
@@ -124,8 +124,8 @@ def _ratchet_repo(tmp_path: Path, switch: str | None = None) -> tuple[Path, str]
@pytest.mark.parametrize("unstaged", [
# the policy file read by the PS-P05 rule, narrowed so it no longer covers pkg/
- ("scripts/ci/profile_scope_patterns.json", lambda t: t.replace('"id": "P05",', '"id": "P05",\n'
- ' "path_regex": "^nowhere/",')),
+ ("scripts/ci/profile_scope_patterns.json", lambda t: t.replace(
+ '"id": "P05",', '"id": "P05",\n "path_regex": "^nowhere/",')),
# the engine itself, edited to exempt pkg/ from PS-P05
("scripts/code_health/config.py", lambda t: t.replace(
'exclude=SINGLE_PROFILE, pattern_id="P05"',
@@ -256,7 +256,8 @@ def test_hooks_prefer_the_repo_virtualenv_over_path_python(tmp_path):
fake = tmp_path / "fakebin"
fake.mkdir()
for name in ("python3", "python"):
- (fake / name).write_text("#!/bin/sh\necho 'wrong interpreter' >&2\nexit 97\n", encoding="utf-8")
+ (fake / name).write_text("#!/bin/sh\necho 'wrong interpreter' >&2\nexit 97\n",
+ encoding="utf-8")
(fake / name).chmod(0o755)
env = _env()
env["PATH"] = f"{fake}{os.pathsep}{env['PATH']}"