-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
Use ruff for formatting #8761
base: main
Are you sure you want to change the base?
Use ruff for formatting #8761
Conversation
I can't reproduce The trailing empty line for blocks (empty Another thing which I'm not too happy about is their assumption of Additionally, So as a summary, I'm not a fan of (most of) these changes, and I would vote for waiting until the dust settled a bit more (I feel a bit conflicted as the author and maintainer of one of the replaced hooks, though). |
I find that the big files such as Running So I would prioritize performance quite highly here
Not strongly opposed to waiting for a bit if others want to, I do expect some churn in the ruff formatter
I think this is an issue with black versons. Worth aligning with the pre-commit config |
Hello, Thanks for your answers! I made this Draft PR as a small example of migrating from black to ruff-format, to have some base material to talk about the parent issue #8760.
and
Regarding
I also see I don't have a compiled version of black installed. I am not sure how to get this version though. Also I agree that I am not a fan of this forced de-inlining, I had a look inside of the ruff-format documentation but could not find any configuration option allowing to opt-out of this de-inlining. It also brings unnecessary formatting changes to the codebase. Maybe an issue can be raised on the ruff repo itself about this topic, it being a necessary condition before even considering moving to using ruff-format. Edit: astral-sh/ruff#10026
Regarding the trailing
Is this something that If I understand well, it formats code contained in documentation. This issue mentions formatting code in documentation + blackdoc: astral-sh/ruff#7146
I agree with @max-sixty here, I also use VSCode with auto-formatting enabled and the project is laggy from time to time. Two levers of action I can think of: reducing formatting time with a more performant formatter, or reducing the size of the file sizes (this would be a refactoring effort, and I don't know what the xarray team considers to be a "too big" file that would deserve to be split). Quality of life during development is valuable |
Based on the discussion at the end of astral-sh/ruff#5822 I am led to believe that we just need to wait a bit more?
that was #4510 (comment), sorry for not directly linking that
In any case, note that formatters should not change the behavior of other tools, if it does then there's something wrong with either the formatter or the other tool. The trouble here, though, is that >>> print("...")
... be interpreted as? However, this: >>> if condition():
... do_something()
... is not as ambiguous: since the code example starts with a block statement, the I'm not sure how resolve this, besides switching to a different format where you're much more unlikely to encounter the ambiguity (like the IPython format).
I can empathize with that. I personally do the auto-formatting on commit (using |
95f6cb6
to
350b0b4
Compare
Yes indeed, if I understand well black has this concept of "Preview" style: https://black.readthedocs.io/en/stable/the_black_code_style/future_style.html This is possible to test this "preview" style (see astral-sh/ruff#10026 (comment) ; I updated the PR accordingly) When this preview style is used, Ellipses are back onto their single line, but other style changes also come in. The
What is the IPython format, an alternative syntax for doctests? As usual, delimitation is the issue: how to delimitate input from expected output to be unambiguous without becoming too verbose... |
You'd also get these other changes with
just like For example:
|
So What I can see potentially annoying with IPython format is the numbering of the input-output pairs, if you want to add an example at the top of the docstring, all the following existing doctests would require to change. Also, when going from 9 to 10, digit count goes grom 1 to 2 and adds an offset. Here I just empty the execution count, replacing it by a space. Then the docstrings would look like for example: In [ ]: """
...: """
Out[ ]: '\n'
In [ ]: (
...: 1 + 2
...: )
Out[ ]: 3
In [ ]: print("...")
...
In [ ]: print("Out[ ]:")
Out[ ]:
In [ ]: "Out[ ]:"
Out[ ]: 'Out[ ]:'
In [ ]: None
In [ ]: |
I notice that the diff is now quite large? I guess that's the If we can reduce the size of the diff as much as possible and get the docs passing, I'd be +1 here. But obv one voice among many. I'm also fine to wait until things settle more if others prefer. |
Yes, the preview flag brings too things:
The preview flag cannot be reliable upon, so for now, the only option is to wait for the official integration of single line stubs in the formatting rules Even with There is still also the issue of ellipsis new lines in the dosctrings, but it is has a less significant share in the diff. I'll try to keep this draft PR updated as a "showcase" of what applying ruff alongside a |
e8ce1c0
to
93ef61c
Compare
OK perfect! |
ruff
for formatting #8760- [ ] Tests added- [ ] User visible changes (including notable bug fixes) are documented inwhats-new.rst
- [ ] New functions/methods are listed inapi.rst
Note: many inline
...
obtain their own line. Runningblack .
would have produced the same result