Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new ecosystem comparison modes for the formatter #8416

Merged
merged 8 commits into from
Nov 2, 2023

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
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 enabled auto-merge (squash) November 2, 2023 01:18
@zanieb zanieb merged commit 2f7e2a8 into main Nov 2, 2023
15 checks passed
@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