Skip to content

Add new ecosystem comparison modes for the formatter#8416

Merged
zanieb merged 8 commits intomainfrom
zanie/eco-format-cmp
Nov 2, 2023
Merged

Add new ecosystem comparison modes for the formatter#8416
zanieb merged 8 commits intomainfrom
zanie/eco-format-cmp

Conversation

@zanieb
Copy link
Member

@zanieb zanieb commented Nov 1, 2023

Previously, the ecosystem checks formatted with the baseline then formatted again with --diff to get the changed files.

Now, the ecosystem checks support a new mode where we:

  • Format with the baseline
  • Commit the changes
  • Reset to the target ref
  • Format again
  • Check the diff from the baseline commit

This effectively tests Ruff changes on unformatted code rather than changes in previously formatted code (unless, of course, the project is already using Ruff).

While this mode is the new default, I've retained the old one for local checks. The mode can be toggled with --format-comparison <type>.

Includes some more aggressive resetting of the GitHub repositories when cached.

Here, I've also stubbed comparison modes in which black is used as the baseline. While these do nothing here, #8419 adds support.

I tested this with the commit from #8216 and ecosystem changes appear https://gist.github.com/zanieb/a982ec8c392939043613267474471a6e

@zanieb zanieb marked this pull request as ready for review November 1, 2023 18:17
@zanieb zanieb added the internal An internal refactor or improvement label Nov 1, 2023
@zanieb zanieb force-pushed the zanie/eco-format-cmp branch from f7b5fd0 to 18b8873 Compare November 1, 2023 18:17
@zanieb zanieb requested review from MichaReiser and konstin November 1, 2023 18:38
@github-actions
Copy link
Contributor

github-actions bot commented Nov 1, 2023

PR Check Results

Ecosystem

✅ ecosystem check detected no linter changes.

✅ ecosystem check detected no format changes.

Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. I love the different modes for running it locally

case FormatComparison.black_then_ruff:
coro = format_then_format(Formatter.black, *args)
case FormatComparison.black_and_ruff:
coro = format_and_format(Formatter.black, *args)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh that's cool



class FormatComparison(Enum):
# Run Ruff baseline then Ruff comparison; checks for changes in behavior when formatting previously "formatted" code
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Python noob question: What's the reason for using inline comments here instead of docstrings?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there's a formalized way to document class attributes individually. Generally what you do is create a class docstring and then document the members using an 'Attributes' section, but that felt like more work than I wanted to do here 😬

tldr a docstring for the class is proper but I was lazy. I wish we had tooling to generate the scaffold.

Copy link
Member Author

@zanieb zanieb Nov 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I even just wrote it out and it feels awkward; I guess I write Rust now

class FormatComparison(Enum):
    """
    The type of format comparison to use.

    Attributes:
        ruff_then_ruff: Run Ruff baseline then Ruff comparison; checks for changes in
            behavior when formatting previously "formatted" code
        ruff_and_ruff: Run Ruff baseline then reset and run Ruff comparison; checks
            changes in behavior when formatting "unformatted" code
        black_then_ruff: Run Black baseline then Ruff comparison; checks for changes in
            behavior when formatting previously "formatted" code
        black_and_ruff: Run Black baseline then reset and run Ruff comparison; checks
            changes in behavior when formatting "unformatted" code
    """

Copy link
Member Author

@zanieb zanieb Nov 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you nudged, I switched to individual attribute docstrings — while the PEP is rejected, VSCode supports it.

@zanieb zanieb force-pushed the zanie/eco-format-cmp branch from 82c8405 to eef3b25 Compare November 2, 2023 01:14
@zanieb zanieb enabled auto-merge (squash) November 2, 2023 01:18
@zanieb zanieb merged commit 2f7e2a8 into main Nov 2, 2023
@zanieb zanieb deleted the zanie/eco-format-cmp branch November 2, 2023 01:20
zanieb added a commit that referenced this pull request Nov 2, 2023
Extends #8416 activating the
`black-and-ruff` and `black-then-ruff` formatter comparison modes for
ecosystem checks allowing us to compare changes to Black across the
ecosystem.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal An internal refactor or improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants