| 1 |
# Gauging changes |
| 2 |
|
| 3 |
A lot of the time, your change will affect formatting and/or performance. Quantifying |
| 4 |
these changes is hard, so we have tooling to help make it easier. |
| 5 |
|
| 6 |
It's recommended you evaluate the quantifiable changes your _Black_ formatting |
| 7 |
modification causes before submitting a PR. Think about if the change seems disruptive |
| 8 |
enough to cause frustration to projects that are already "Black-formatted". |
| 9 |
|
| 10 |
## diff-shades |
| 11 |
|
| 12 |
diff-shades is a tool that runs _Black_ across a list of open-source projects recording |
| 13 |
the results. The main highlight feature of diff-shades is being able to compare two |
| 14 |
revisions of _Black_. This is incredibly useful as it allows us to see what exact |
| 15 |
changes will occur, say merging a certain PR. |
| 16 |
|
| 17 |
For more information, please see the [diff-shades documentation][diff-shades]. |
| 18 |
|
| 19 |
### CI integration |
| 20 |
|
| 21 |
diff-shades is also the tool behind the "diff-shades results comparing ..." comments on |
| 22 |
PRs. The project has a GitHub Actions workflow that analyzes and compares two revisions |
| 23 |
of _Black_ according to these rules: |
| 24 |
|
| 25 |
| | Baseline revision | Target revision | |
| 26 |
| --------------------- | ------------------------------- | ---------------------------- | |
| 27 |
| On PRs | latest commit on PR base branch | PR commit with `main` merged | |
| 28 |
| On pushes (main only) | latest PyPI version | the pushed commit | |
| 29 |
|
| 30 |
For pushes to main, there's only one analysis job named `preview-new-changes` where the |
| 31 |
preview style is used for all projects. |
| 32 |
|
| 33 |
For PRs they get one more analysis job: `assert-no-changes`. It's similar to |
| 34 |
`preview-new-changes` but runs with the stable code style. It will fail if changes were |
| 35 |
made. This makes sure code won't be reformatted again and again within the same year in |
| 36 |
accordance to Black's stability policy. |
| 37 |
|
| 38 |
Additionally for PRs, a PR comment will be posted embedding a summary previewing any |
| 39 |
changes in both styles and links to further information. The next time the workflow is |
| 40 |
triggered on the same PR, it'll update the pre-existing diff-shades comment. |
| 41 |
|
| 42 |
```{note} |
| 43 |
Jobs will only fail intentionally if a file failed to format while analyzing, or if |
| 44 |
changes were made to the stable style. Otherwise a failure indicates a bug in the |
| 45 |
workflow. |
| 46 |
``` |
| 47 |
|
| 48 |
The workflow uploads several artifacts upon completion: |
| 49 |
|
| 50 |
- HTML diffs (.html) |
| 51 |
- handy for pushes where there's no PR to post a comment |
| 52 |
- The raw analyses (.json) |
| 53 |
- in case you want to do further analysis using the collected data locally |
| 54 |
- `.preview.pr-comment.md` and `.stable.pr-comment.md` (if triggered by a PR) |
| 55 |
- used to generate the PR comment and shouldn't be downloaded |
| 56 |
|
| 57 |
[diff-shades]: https://github.com/ichard26/diff-shades#readme |