Skip to content

Fail "new primer" runs on fatal errors, like "old primer" #6746

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/primer_run_main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ jobs:
run: |
. venv/bin/activate
pip install -e .
python tests/primer/primer_tool.py run --type=main
python tests/primer/primer_tool.py run --type=main 2>warnings.txt
WARNINGS=$(head -c 65000 < warnings.txt)
if [[ $WARNINGS ]]
then echo "::warning ::$WARNINGS"
fi
- name: Upload output
uses: actions/upload-artifact@v3
with:
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/primer_run_pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,11 @@ jobs:
run: |
. venv/bin/activate
pip install -e .
python tests/primer/primer_tool.py run --type=pr
python tests/primer/primer_tool.py run --type=pr 2>warnings.txt
WARNINGS=$(head -c 65000 < warnings.txt)
if [[ $WARNINGS ]]
then echo "::warning ::$WARNINGS"
fi
- name: Upload output of PR
uses: actions/upload-artifact@v3
with:
Expand Down
20 changes: 19 additions & 1 deletion tests/primer/primer_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import argparse
import json
import sys
import warnings
from io import StringIO
from itertools import chain
from pathlib import Path
from typing import Dict, List, Union

Expand Down Expand Up @@ -134,6 +136,22 @@ def _handle_run_command(self) -> None:
) as f:
json.dump(packages, f)

# Fail loudly (and fail CI pipelines) if any fatal errors are found,
# unless they are astroid-errors, in which case just warn.
# This is to avoid introducing a dependency on bleeding-edge astroid
# for pylint CI pipelines generally, even though we want to use astroid main
# for the purpose of diffing emitted messages and generating PR comments.
messages = list(chain.from_iterable(packages.values()))
astroid_errors = [msg for msg in messages if msg["symbol"] == "astroid-error"]
other_fatal_msgs = [
msg
for msg in messages
if msg["type"] == "fatal" and msg["symbol"] != "astroid-error"
]
if astroid_errors:
warnings.warn(f"Fatal errors traced to astroid: {astroid_errors}")
assert not other_fatal_msgs, other_fatal_msgs

def _handle_compare_command(self) -> None:
with open(self.config.base_file, encoding="utf-8") as f:
main_dict: PackageMessages = json.load(f)
Expand Down Expand Up @@ -246,7 +264,7 @@ def _lint_package(self, data: PackageToLint) -> list[dict[str, str | int]]:
arguments += [f"--rcfile={data.pylintrc_relpath}"]
output = StringIO()
reporter = JSONReporter(output)
Run(arguments, reporter=reporter, do_exit=False)
Run(arguments, reporter=reporter, exit=False)
return json.loads(output.getvalue())

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion tests/profile/test_profile_against_externals.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_run(tmp_path, name, git_repo):
filepaths = _get_py_files(scanpath=str(checkoutdir))
print(f"Have {len(filepaths)} files")

runner = Run(filepaths, reporter=Reporter(), do_exit=False)
runner = Run(filepaths, reporter=Reporter(), exit=False)

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