Answer prose round 1: 0 🔴, 1 🟡 (0 misread); reword two comments, rename docker_at, file the DOCKER_VALUED gap as item 225

This commit is contained in:
2026-10-23 14:45:45 +02:00
parent fc38e80591
commit bd00eee3ca
2 changed files with 17 additions and 7 deletions
+6 -6
View File
@@ -4,7 +4,7 @@ import re
# Launchers that run the tool named later in their words, such as uvx --with pytest mutmut run.
LAUNCHERS = frozenset({"bunx", "env", "nice", "npx", "pipx", "pnpm", "time", "uvx", "yarn"})
# Each mutation tool, and the words that make its call a mutation run when one of them follows it within two words; with no words, every call is one.
# Each mutation tool, and the words that make its call a mutation run when one of them follows it within two words; where the set is empty, every call is one.
MUTATORS = {"cargo": {"mutants"}, "infection": set(), "mutmut": {"run"}, "stryker": {"run"}}
# Flags with which a tool only prints its help, version or list, so a call that carries one is light. Not -h, which docker run reads as the container's hostname.
LIGHT_FLAGS = frozenset({"--help", "--list", "--version"})
@@ -19,17 +19,17 @@ def tool_name(word: str) -> str:
def heavy(words: list[str]) -> bool:
"""Whether the simple command runs a docker build, or a mutation run directly, through a launcher or in a container, outside run-heavy."""
"""Whether the simple command, run directly or through a launcher, is a docker build or a mutation run, or runs one in a container, and is not under run-heavy."""
names = [tool_name(word) for word in words]
if not names or "run-heavy" in names or LIGHT_FLAGS & set(words):
return False
# Past a launcher, the tool may follow the launcher's own options and assignments, as in nice -n 19 docker build or uvx --with pytest mutmut run; without one, the command itself is the tool.
launched = names[0] in LAUNCHERS
reachable = names if launched else names[:1]
docker = reachable.index("docker") if "docker" in reachable else None
if docker is not None:
subcommand = docker_subcommand(words[docker + 1:])
return subcommand in (["build"], ["buildx", "build"], ["compose", "build"]) or (subcommand[-1:] in (["run"], ["exec"]) and mutation_run(names[docker + 1:]))
docker_at = reachable.index("docker") if "docker" in reachable else None
if docker_at is not None:
subcommand = docker_subcommand(words[docker_at + 1:])
return subcommand in (["build"], ["buildx", "build"], ["compose", "build"]) or (subcommand[-1:] in (["run"], ["exec"]) and mutation_run(names[docker_at + 1:]))
return (launched or names[0] in MUTATORS) and mutation_run(names)