pw_presubmit: Ignore some Python debug output

Ignore "Requirement already satisfied:" lines when summarizing failures.

Change-Id: I62e66a9793dbcbb3867d99c9ce72ec53aa56f8be
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/127007
Commit-Queue: Rob Mohr <mohrr@google.com>
Reviewed-by: Wyatt Hepler <hepler@google.com>
Pigweed-Auto-Submit: Rob Mohr <mohrr@google.com>
diff --git a/pw_presubmit/py/ninja_parser_test.py b/pw_presubmit/py/ninja_parser_test.py
index 2d65e1b..4710f5e 100644
--- a/pw_presubmit/py/ninja_parser_test.py
+++ b/pw_presubmit/py/ninja_parser_test.py
@@ -27,6 +27,7 @@
 [1169/1797] ACTION //pw_presubmit/py:py.lint.mypy(//pw_build/python_toolchain:python)
 FAILED: python/gen/pw_presubmit/py/py.lint.mypy.pw_pystamp
 python ../../pw_build/py/pw_build/python_runner.py --gn-root ../../ --current-path ../../pw_presubmit/py --default-toolchain=//pw_toolchain/default:default --current-toolchain=//pw_build/python_toolchain:python --env=MYPY_FORCE_COLOR=1 --touch python/gen/pw_presubmit/py/py.lint.mypy.pw_pystamp --capture-output --module mypy --python-virtualenv-config python/gen/pw_env_setup/pigweed_build_venv/venv_metadata.json --python-dep-list-files python/gen/pw_presubmit/py/py.lint.mypy_metadata_path_list.txt -- --pretty --show-error-codes ../../pw_presubmit/py/pw_presubmit/__init__.py ../../pw_presubmit/py/pw_presubmit/build.py ../../pw_presubmit/py/pw_presubmit/cli.py ../../pw_presubmit/py/pw_presubmit/cpp_checks.py ../../pw_presubmit/py/pw_presubmit/format_code.py ../../pw_presubmit/py/pw_presubmit/git_repo.py ../../pw_presubmit/py/pw_presubmit/inclusive_language.py ../../pw_presubmit/py/pw_presubmit/install_hook.py ../../pw_presubmit/py/pw_presubmit/keep_sorted.py ../../pw_presubmit/py/pw_presubmit/ninja_parser.py ../../pw_presubmit/py/pw_presubmit/npm_presubmit.py ../../pw_presubmit/py/pw_presubmit/pigweed_presubmit.py ../../pw_presubmit/py/pw_presubmit/presubmit.py ../../pw_presubmit/py/pw_presubmit/python_checks.py ../../pw_presubmit/py/pw_presubmit/shell_checks.py ../../pw_presubmit/py/pw_presubmit/todo_check.py ../../pw_presubmit/py/pw_presubmit/tools.py ../../pw_presubmit/py/git_repo_test.py ../../pw_presubmit/py/keep_sorted_test.py ../../pw_presubmit/py/ninja_parser_test.py ../../pw_presubmit/py/presubmit_test.py ../../pw_presubmit/py/tools_test.py ../../pw_presubmit/py/setup.py
+  Requirement already satisfied: pyserial in c:\\b\\s\\w\\ir\\x\\w\\co\\environment\\pigweed-venv\\lib\\site-packages (from pigweed==0.0.13+20230126212203) (3.5)
 ../../pw_presubmit/py/presubmit_test.py:63: error: Module has no attribute
 "Filter"  [attr-defined]
             TestData(presubmit.Filter(suffix=('.a', '.b')), 'foo.c', False...
diff --git a/pw_presubmit/py/pw_presubmit/ninja_parser.py b/pw_presubmit/py/pw_presubmit/ninja_parser.py
index 2c60095..131137d 100644
--- a/pw_presubmit/py/pw_presubmit/ninja_parser.py
+++ b/pw_presubmit/py/pw_presubmit/ninja_parser.py
@@ -25,6 +25,8 @@
 
 
 def parse_ninja_stdout(ninja_stdout: Path) -> str:
+    """Extract an error summary from ninja output."""
+
     failure_begins = False
     failure_lines = []
     last_line = ''
@@ -49,5 +51,14 @@
                     failure_lines.extend([last_line, line])
             last_line = line
 
+    # Remove "Requirement already satisfied:" lines since many of those might
+    # be printed during Python installation, and they usually have no relevance
+    # to the actual error.
+    failure_lines = [
+        x
+        for x in failure_lines
+        if not x.lstrip().startswith('Requirement already satisfied:')
+    ]
+
     result = '\n'.join(failure_lines)
     return re.sub(r'\n+', '\n', result)