Get(LintResults, LintRequest, lint_request) for lint_request in valid_requests
)
sorted_results = sorted(itertools.chain.from_iterable(results), key=lambda res: res.linter_name)
if not sorted_results:
return Lint(exit_code=0)
linter_to_reports = defaultdict(list)
for result in sorted_results:
if result.report:
linter_to_reports[result.linter_name].append(result.report)
if linter_to_reports:
// TODO(/): Tolerate when a linter has multiple reports.
linters_with_multiple_reports = [
linter for linter, reports in linter_to_reports.items() if len(reports) > 1
]
if linters_with_multiple_reports:
if lint_subsystem.per_target_caching:
suggestion = "Try running without `--lint-per-target-caching` set."
else:
suggestion = (
"The linters likely partitioned the input targets, such as grouping by Python "
"interpreter compatibility. Try running on fewer targets or unset "
"`--lint-reports-dir`."
)
raise InvalidLinterReportsError(
"Multiple reports would have been written for these linters: "
f"{linters_with_multiple_reports}. The option `--lint-reports-dir` only works if "
f"each linter has a single result. {suggestion}"
)
reports = itertools.chain.from_iterable(linter_to_reports.values())
merged_reports = await Get(Digest, MergeDigests(report.digest for report in reports))
workspace.write_digest(merged_reports, path_prefix=lint_subsystem.reports_dir)
logger.info(f"Wrote lint result files to {lint_subsystem.reports_dir}.")
exit_code = 0
for result in sorted_results:
if result.exit_code == 0:
sigil = console.green("✓")
status = "succeeded"
else:
sigil = console.red("𐄂")
status = "failed"
exit_code = result.exit_code
console.print_stderr(f"{sigil} {result.linter_name} {status}.")
if result.stdout:
console.print_stderr(result.stdout)
if result.stderr:
console.print_stderr(result.stderr)
if result != sorted_results[-1]:
console.print_stderr("")
return Lint(exit_code)
After Change
Get(LintResults, LintRequest, lint_request) for lint_request in valid_requests
)
all_results = tuple(sorted(all_results, key=lambda results: results.linter_name))
reports = list(itertools.chain.from_iterable(results.reports for results in all_results))
if reports:
// TODO(/): Tolerate when a linter has multiple reports.
linters_with_multiple_reports = [
results.linter_name for results in all_results if len(results.reports) > 1
]
if linters_with_multiple_reports:
if lint_subsystem.per_target_caching:
suggestion = "Try running without `--lint-per-target-caching` set."
else:
suggestion = (
"The linters likely partitioned the input targets, such as grouping by Python "
"interpreter compatibility. Try running on fewer targets or unset "
"`--lint-reports-dir`."
)
raise InvalidLinterReportsError(
"Multiple reports would have been written for these linters: "
f"{linters_with_multiple_reports}. The option `--lint-reports-dir` only works if "
f"each linter has a single result. {suggestion}"
)
merged_reports = await Get(Digest, MergeDigests(report.digest for report in reports))
workspace.write_digest(merged_reports)
logger.info(f"Wrote lint result files to {lint_subsystem.reports_dir}.")
exit_code = 0
if all_results:
console.print_stderr("")
for results in all_results:
if results.skipped:
sigil = console.yellow("-")
status = "skipped"
elif results.exit_code == 0:
sigil = console.green("✓")
status = "succeeded"
else:
sigil = console.red("𐄂")
status = "failed"
exit_code = results.exit_code
console.print_stderr(f"{sigil} {results.linter_name} {status}.")
return Lint(exit_code)