Skip to content

Commit c29bba6

Browse files
Fail "new primer" runs on fatal errors, like the "old primer" (#6746)
1 parent d3180ea commit c29bba6

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

.github/workflows/primer_run_main.yaml

+5-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,11 @@ jobs:
9696
run: |
9797
. venv/bin/activate
9898
pip install -e .
99-
python tests/primer/primer_tool.py run --type=main
99+
python tests/primer/primer_tool.py run --type=main 2>warnings.txt
100+
WARNINGS=$(head -c 65000 < warnings.txt)
101+
if [[ $WARNINGS ]]
102+
then echo "::warning ::$WARNINGS"
103+
fi
100104
- name: Upload output
101105
uses: actions/upload-artifact@v3
102106
with:

.github/workflows/primer_run_pr.yaml

+5-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,11 @@ jobs:
167167
run: |
168168
. venv/bin/activate
169169
pip install -e .
170-
python tests/primer/primer_tool.py run --type=pr
170+
python tests/primer/primer_tool.py run --type=pr 2>warnings.txt
171+
WARNINGS=$(head -c 65000 < warnings.txt)
172+
if [[ $WARNINGS ]]
173+
then echo "::warning ::$WARNINGS"
174+
fi
171175
- name: Upload output of PR
172176
uses: actions/upload-artifact@v3
173177
with:

tests/primer/primer_tool.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
import argparse
88
import json
99
import sys
10+
import warnings
1011
from io import StringIO
12+
from itertools import chain
1113
from pathlib import Path
1214
from typing import Dict, List, Union
1315

@@ -134,6 +136,22 @@ def _handle_run_command(self) -> None:
134136
) as f:
135137
json.dump(packages, f)
136138

139+
# Fail loudly (and fail CI pipelines) if any fatal errors are found,
140+
# unless they are astroid-errors, in which case just warn.
141+
# This is to avoid introducing a dependency on bleeding-edge astroid
142+
# for pylint CI pipelines generally, even though we want to use astroid main
143+
# for the purpose of diffing emitted messages and generating PR comments.
144+
messages = list(chain.from_iterable(packages.values()))
145+
astroid_errors = [msg for msg in messages if msg["symbol"] == "astroid-error"]
146+
other_fatal_msgs = [
147+
msg
148+
for msg in messages
149+
if msg["type"] == "fatal" and msg["symbol"] != "astroid-error"
150+
]
151+
if astroid_errors:
152+
warnings.warn(f"Fatal errors traced to astroid: {astroid_errors}")
153+
assert not other_fatal_msgs, other_fatal_msgs
154+
137155
def _handle_compare_command(self) -> None:
138156
with open(self.config.base_file, encoding="utf-8") as f:
139157
main_dict: PackageMessages = json.load(f)
@@ -246,7 +264,7 @@ def _lint_package(self, data: PackageToLint) -> list[dict[str, str | int]]:
246264
arguments += [f"--rcfile={data.pylintrc_relpath}"]
247265
output = StringIO()
248266
reporter = JSONReporter(output)
249-
Run(arguments, reporter=reporter, do_exit=False)
267+
Run(arguments, reporter=reporter, exit=False)
250268
return json.loads(output.getvalue())
251269

252270
@staticmethod

tests/profile/test_profile_against_externals.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def test_run(tmp_path, name, git_repo):
4646
filepaths = _get_py_files(scanpath=str(checkoutdir))
4747
print(f"Have {len(filepaths)} files")
4848

49-
runner = Run(filepaths, reporter=Reporter(), do_exit=False)
49+
runner = Run(filepaths, reporter=Reporter(), exit=False)
5050

5151
print(
5252
f"Had {len(filepaths)} files with {len(runner.linter.reporter.messages)} messages"

0 commit comments

Comments
 (0)