Answer architecture round 1: 0 🔴, 3 🟡 (0 misread); move docker's parsing to bin/ for item 227's shim, read launchers once in shell_command.launched, and give the memory limit its own decision, sized to what the work needs

This commit is contained in:
2026-10-24 00:31:41 +02:00
parent 7b61fd5b4b
commit a292ec4cae
9 changed files with 89 additions and 67 deletions
+9 -9
View File
@@ -1,23 +1,23 @@
"""Whether a simple command is a heavy one, for the `run-heavy` rule: a docker build, or a run of a mutation tool."""
from rule_hook.docker_command import docker_arguments, docker_subcommand, LAUNCHERS, tool_name
from docker_command import docker_subcommand
from shell_command import launched, tool_name
# 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"})
BUILDS = (["build"], ["buildx", "build"], ["compose", "build"])
def heavy(words: list[str]) -> bool:
"""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):
launch = launched(words, {"docker", *MUTATORS})
if launch is None or "run-heavy" in launch.launchers or LIGHT_FLAGS & set(words):
return False
docker = docker_arguments(words)
if docker is not None:
subcommand = docker_subcommand(docker)
return subcommand in (["build"], ["buildx", "build"], ["compose", "build"]) or (subcommand[-1:] in (["run"], ["exec"]) and mutation_run(names[len(words) - len(docker):]))
# Past a launcher, the mutation tool may follow the launcher's own options, as in uvx --with pytest mutmut run.
return (names[0] in LAUNCHERS or names[0] in MUTATORS) and mutation_run(names)
if launch.tool == "docker":
subcommand = docker_subcommand(launch.arguments)
return subcommand in BUILDS or (subcommand[-1:] in (["run"], ["exec"]) and mutation_run([tool_name(word) for word in launch.arguments]))
return mutation_run([launch.tool, *(tool_name(word) for word in launch.arguments)])
def mutation_run(names: list[str]) -> bool: