From f7893931781f865774dbd04a244728fd17f457a6 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Fri, 23 Aug 2024 19:17:35 -0400 Subject: [PATCH] fix: handle a check modifying the input fixtures (#243) Signed-off-by: Henry Schreiner --- src/repo_review/processor.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/repo_review/processor.py b/src/repo_review/processor.py index 7c7de64..421fa27 100644 --- a/src/repo_review/processor.py +++ b/src/repo_review/processor.py @@ -1,9 +1,11 @@ from __future__ import annotations +import copy import dataclasses import graphlib import textwrap import typing +import warnings from collections.abc import Mapping, Set from typing import Any, TypeVar @@ -211,13 +213,18 @@ def process( # Keep track of which checks have been completed completed: dict[str, str | None] = {} + fixtures_copy = copy.deepcopy(fixtures) # Run all the checks in topological order based on their dependencies ts = graphlib.TopologicalSorter(graph) for name in ts.static_order(): if all(completed.get(n, "") == "" for n in graph[name]): - result = apply_fixtures({"name": name, **fixtures}, tasks[name].check) + result = apply_fixtures({"name": name, **fixtures_copy}, tasks[name].check) completed[name] = process_result_bool(result, tasks[name], name) + if fixtures != fixtures_copy: + fixtures_copy = copy.deepcopy(fixtures) + msg = f"{name} modified the input fixtures! Making a deepcopy to fix and continue." + warnings.warn(msg, stacklevel=1) else: completed[name] = None