| 42 | |
| 43 | |
| 44 | def process_file(black_bin, filename, config): |
| 45 | logger.debug("Check %s", filename) |
| 46 | args = ['--quiet', '--check', '--config', config] |
| 47 | |
| 48 | # Fast path for runs with fix_style option or without errors. |
| 49 | rc, out = run_black_safe(black_bin, filename, args) |
| 50 | if rc == 1: |
| 51 | # black runs 15x+ slower if diff is requested, even for files w/o actual diff. |
| 52 | # Rerun black in case of found error. |
| 53 | rc, out = run_black_safe(black_bin, filename, args + ['--diff']) |
| 54 | |
| 55 | if out: |
| 56 | sys.stdout.write(out) |
| 57 | lines = out.splitlines(keepends=True) |
| 58 | # strip diff header with "+++" "---" lines |
| 59 | lines = lines[2:] |
| 60 | if len(lines) > SNIPPET_LINES_LIMIT: |
| 61 | lines = lines[:SNIPPET_LINES_LIMIT] |
| 62 | lines += ["[[rst]]..[truncated].. see full diff in the stdout file in the logsdir"] |
| 63 | out = ''.join(lines) |
| 64 | |
| 65 | return out |
| 66 | |
| 67 | |
| 68 | def main(): |