Skip to content

Commit

Permalink
black-primer: Print summary after individual failures
Browse files Browse the repository at this point in the history
If the individual failures are verbose, it's useful to have
the summary at the end. Otherwise, it can be really difficult
to figure out which projects have an issue.
  • Loading branch information
nipunn1313 committed Oct 28, 2021
1 parent 467efe1 commit 2791168
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -9,6 +9,7 @@
- Fixed feature detection for positional-only arguments in lambdas (#2532)
- Bumped typed-ast version minimum to 1.4.3 for 3.10 compatiblity (#2519)
- Add primer support for --projects (#2555)
- Print primer summary after individual failures (#2570)

### _Blackd_

Expand Down
24 changes: 14 additions & 10 deletions src/black_primer/lib.py
Expand Up @@ -88,6 +88,18 @@ def analyze_results(project_count: int, results: Results) -> int:
failed_pct = round(((results.stats["failed"] / project_count) * 100), 2)
success_pct = round(((results.stats["success"] / project_count) * 100), 2)

if results.failed_projects:
click.secho("\nFailed projects:\n", bold=True)

for project_name, project_cpe in results.failed_projects.items():
print(f"## {project_name}:")
print(f" - Returned {project_cpe.returncode}")
if project_cpe.stderr:
print(f" - stderr:\n{project_cpe.stderr.decode('utf8')}")
if project_cpe.stdout:
print(f" - stdout:\n{project_cpe.stdout.decode('utf8')}")
print("")

click.secho("-- primer results 📊 --\n", bold=True)
click.secho(
f"{results.stats['success']} / {project_count} succeeded ({success_pct}%) ✅",
Expand All @@ -110,16 +122,8 @@ def analyze_results(project_count: int, results: Results) -> int:
)

if results.failed_projects:
click.secho("\nFailed projects:\n", bold=True)

for project_name, project_cpe in results.failed_projects.items():
print(f"## {project_name}:")
print(f" - Returned {project_cpe.returncode}")
if project_cpe.stderr:
print(f" - stderr:\n{project_cpe.stderr.decode('utf8')}")
if project_cpe.stdout:
print(f" - stdout:\n{project_cpe.stdout.decode('utf8')}")
print("")
failed = list(results.failed_projects.keys())
click.secho(f"\nFailed projects: {failed}\n", bold=True)

return results.stats["failed"]

Expand Down
15 changes: 9 additions & 6 deletions tests/test_primer.py
Expand Up @@ -20,6 +20,14 @@


EXPECTED_ANALYSIS_OUTPUT = """\
Failed projects:
## black:
- Returned 69
- stdout:
Black didn't work
-- primer results 📊 --
68 / 69 succeeded (98.55%) ✅
Expand All @@ -28,12 +36,7 @@
- 0 projects skipped due to Python version
- 0 skipped due to long checkout
Failed projects:
## black:
- Returned 69
- stdout:
Black didn't work
Failed projects: ['black']
"""
FAKE_PROJECT_CONFIG = {
Expand Down

0 comments on commit 2791168

Please sign in to comment.