-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
airbyte-ci: format python using ruff instead of isort+black #33251
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
0bb19da
to
9f63b84
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to before. No objections to Ruff.
Its faster, and lets us move from 2 tools to 1.
The fact that the rules are slightly different is annoying but formatting is to enforce a consistent style. The details of the style we choose are not important.
However, Given that @alafanechere is actively working in the area I would defer to him for final approval
Thanks for the review! Yes, I'll wait until his pre-commit hook + workflow changes have merged. |
I have a bit of good news and bad news. It looks like between the prior PR and this one, Bad news: this PR uses Worse news: some rules from So - we have a choice in front of us:
PS - I'm a bit bummed that |
Very excited to see that they expanded. @aaronsteers I can't seem to find any reference to where I could find a list of deviations in behaviour from black but so far it seems like if we are running ruff's version of linting and formatting we should be safe. But! I imagine im just being blind in my reading on Friday. I did run a little test in this PR Where I had the following order of operations
And these two things seem to be true
This means during and during But I think at this point I would be for us adding the formatting code in one PR and the check code in another. Since we werent doing much linting to begin with and I would love to keep the momentum going and get ruff into our code base. Because youre right, it is fast. |
@bnchrch : Here's the link for documented conflicts: https://docs.astral.sh/ruff/formatter/#format-suppression Also: here's the commit from After a quick manual review, some of the updates from this commit seem to be driven by what could be a difference in line length preferences. Might be worth more research to see if an inconsistent line length in my process caused some of those additional diffs. |
@@ -21,7 +21,9 @@ class DefaultFileBasedAvailabilityStrategy(AbstractFileBasedAvailabilityStrategy | |||
def __init__(self, stream_reader: AbstractFileBasedStreamReader): | |||
self.stream_reader = stream_reader | |||
|
|||
def check_availability(self, stream: "AbstractFileBasedStream", logger: logging.Logger, _: Optional[Source]) -> Tuple[bool, Optional[str]]: # type: ignore[override] | |||
def check_availability( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will generate mypy error as # type: ignore[override]
needs to be applied to the line where stream: "AbstractFileBasedStream"
is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I'll check the other annotations touched by this diff as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The others are OK, I checked with mypy using the config at airbyte-cdk/python/mypy.ini
9f63b84
to
0c276f8
Compare
@aaronsteers somehow I knew it was too good to be true. Still, this change in this PR seems like it's not only safe but also desirable, considering that There's nothing stopping anyone from adding |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm in for using ruff
in place of black and isort but I'd love to make sure this tool change is not changing our formatting rules. Ideally this tool change should not require a new formatting of the repo.
I belive there might be some configuration tweaking to get this result.
That's legitimate. I don't have the time nor the interest in getting to understand the ruff rules, so I'll let someone else take over from here. |
@postamar re:
Yes, 100% agreed. Let's go forward with this as a first step. And incrementally, we can add additional format/lint autofixes in a future iteration. @alafanechere - can you say more about your point above? The changes auto-applied here are basically bringing our code to meet black auto format standards, but using Ruff which is faster and better long-term. I didn't think we had any similar auto formatting for Python code before this, but I could be mistaken. (Or maybe we have auto formatting for some directories but not others?) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great. 👍 Approving for my part. ✅
As discussed in the threads above, we can always do a follow-up to add more linting and autofixes.
One thing that might be nice is (maybe under "contributing" and maybe in a follow-up pr?) a section on "code style" or python "dev standards" - with a mention of what auto-formatter we use and how developers/contributors can invoke it manually. (Just a thought... please disregard if this already exists.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change looks good but you might have to approve and merge despite the failing cdk mypy check unless you plan on resolving the typing errors too. The check runs on all modified cdk files so a lot of failures are surfaced on this PR
0c276f8
to
b907fa7
Compare
@alafanechere I looked into it some more and no, we can't minimize the diff more by tweaking the config. The short of it is, there is no config, both black and ruff are opinionated formatters. Ruff has somewhat different opinions on certain matters, which explains a lot of the diff: https://docs.astral.sh/ruff/formatter/black/ . Note that black's style is also continuously evolving, see https://black.readthedocs.io/en/stable/the_black_code_style/future_style.html . I admittedly don't have a horse in this race but it all strikes me as quite benign. Given these facts, I'm hoping that you might change your mind. Otherwise the logical alternative is that we not just keep using black, but this exact version of black, which doesn't strike me as better. |
Yolo, one tool is better than four, we should switch and clean out our documentation. It's going to be easier on us, and it's going to be easier on external contributors and new engineers starting on the team. |
Just continuing dicussion here, obviously we would need to reformat everything. Here's what I think we should do:
|
This picks up where #29853 stalled. At the time, we didn't have
airbyte-ci format
. I re-used @aaronsteers 's pyproject.toml settings here. The resulting diff is surprisingly not huge.