Answer principles round 1: 1 🔴, 7 🟡 (0 misread); every effect is handed in as an argument, no test patches a global, and the traces principle scopes tools that run on their user's machine
CI / tests (pull_request) Successful in 3m43s
CI / tests (pull_request) Successful in 3m43s
This commit is contained in:
@@ -19,14 +19,14 @@ OWN = pathlib.Path(__file__).resolve().parents[2]
|
||||
OWN_CHECK_SECONDS = 20
|
||||
|
||||
|
||||
def todo_breaches(directory: str, home: pathlib.Path, own: pathlib.Path = OWN) -> list[Breach]:
|
||||
def todo_breaches(directory: str, home: pathlib.Path, own: pathlib.Path = OWN, seconds: float = OWN_CHECK_SECONDS) -> list[Breach]:
|
||||
"""Why the plan of directory's project is not ranked, where the plan has changed; the plan is the todo.md its config names. directory may also be in a config's folder, a git repo of its own."""
|
||||
top = guarded_git(directory, "rev-parse", "--show-toplevel")
|
||||
if isinstance(top, Failure):
|
||||
return []
|
||||
held_here = held(pathlib.Path(top), home)
|
||||
if held_here is not None:
|
||||
return folder_breaches(top, held_here, own)
|
||||
return folder_breaches(top, held_here, own, seconds)
|
||||
config = located(top, home, functools.partial(git, guarded=True))
|
||||
if isinstance(config, Failure):
|
||||
# A checkout whose todo.md changes with no config is one whose config is still to write. An unchanged todo.md may be a third party's, whose clone needs no config.
|
||||
@@ -39,10 +39,10 @@ def todo_breaches(directory: str, home: pathlib.Path, own: pathlib.Path = OWN) -
|
||||
# A plan outside the checkout has no commit in the checkout to differ from, so it is checked on every call.
|
||||
if tracked is not None and not changed(top, todo, tracked):
|
||||
return []
|
||||
return [Breach("todo-rank-check", line, top) for line in check_failures(top, todo, config, own)]
|
||||
return [Breach("todo-rank-check", line, top) for line in check_failures(top, todo, config, own, seconds)]
|
||||
|
||||
|
||||
def folder_breaches(top: str, config: ProjectConfig | Failure, own: pathlib.Path) -> list[Breach]:
|
||||
def folder_breaches(top: str, config: ProjectConfig | Failure, own: pathlib.Path, seconds: float) -> list[Breach]:
|
||||
"""Why the plan kept in top, a config's folder, is not ranked, where the plan has changed in that folder's repo; ranked as for a commit in the project's checkout.
|
||||
|
||||
A config that fails to load doesn't block anything here, so that the commit that fixes it goes through."""
|
||||
@@ -53,18 +53,18 @@ def folder_breaches(top: str, config: ProjectConfig | Failure, own: pathlib.Path
|
||||
return []
|
||||
if not todo.is_file() or not changed(str(config.folder), todo, todo.relative_to(config.folder).as_posix()):
|
||||
return []
|
||||
return [Breach("todo-rank-check", line, top) for line in check_failures(str(config.top), todo, config, own)]
|
||||
return [Breach("todo-rank-check", line, top) for line in check_failures(str(config.top), todo, config, own, seconds)]
|
||||
|
||||
|
||||
def check_failures(top: str, todo: pathlib.Path, config: ProjectConfig, own: pathlib.Path) -> list[str]:
|
||||
def check_failures(top: str, todo: pathlib.Path, config: ProjectConfig, own: pathlib.Path, seconds: float) -> list[str]:
|
||||
"""Why rank_todo.py --check fails on todo. A checkout of the repo the hook runs from checks with its own bin/rank_todo.py, so a branch that changes the table's shape is held to its own rules. Any other checkout checks with the hook's ranking: running its script would run its code before every commit."""
|
||||
script = pathlib.Path(top) / "bin" / "rank_todo.py"
|
||||
if not script.is_file() or not same_repo(top, own):
|
||||
return file_plan(config, todo).check()
|
||||
try:
|
||||
ran = subprocess.run([sys.executable, str(script), "--check", str(todo)], capture_output=True, cwd=top, text=True, timeout=OWN_CHECK_SECONDS)
|
||||
ran = subprocess.run([sys.executable, str(script), "--check", str(todo)], capture_output=True, cwd=top, text=True, timeout=seconds)
|
||||
except subprocess.TimeoutExpired:
|
||||
return [f"{script} --check did not finish in {OWN_CHECK_SECONDS} seconds"]
|
||||
return [f"{script} --check did not finish in {seconds} seconds"]
|
||||
except OSError as failure:
|
||||
return [f"{script} --check could not run: {failure}"]
|
||||
if ran.returncode == 0:
|
||||
|
||||
Reference in New Issue
Block a user