-
Notifications
You must be signed in to change notification settings - Fork 669
Ruff formatting #3459
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
Ruff formatting #3459
Conversation
|
I'm not really a fan of things like I find the one item per line much for readable |
|
I prefer one item per line too, unless it's ~2 parameters, in which case they become few enough that I have no trouble grasping what's going on. In my brain readability is more important than uniformity (and with this that they are necessarily not the same thing). With that said, this is absolutely a deteriorating change: - MenuItem(
- text=str(_('Automatic time sync (NTP)')),
- action=ask_ntp,
- value=True,
- preview_action=self._prev_ntp,
- key='ntp'
- ),
+ MenuItem(text=str(_('Automatic time sync (NTP)')), action=ask_ntp, value=True, preview_action=self._prev_ntp, key='ntp'),We also have to change these lines: Lines 32 to 34 in e61b966
Which I'm fine with, since Python now with Python 3.13 handles inline quotation marks better within f-strings. So there's really no need to be strict about this anymore. |
|
I was really hoping there would be more settings but it feels much like |
This can be fixed by adding trailing commas: The Line 223 in e61b966
|
|
@correctmost thanks for that, I pushed an update with that and it seems to have done a bit better. But there are still some things that got moved into a single line such as Is there something to keep those items per line as well? |
|
Oh, weird, it looks like This should work better: |
|
Great that worked! @Torxed what do you think? |
|
It's looking better! I have a question why it's not doing the same here: - part_mods = [
- d.segment for d in data
- if isinstance(d.segment, PartitionModification)
- and d.segment != entry
- ]
+ part_mods = [d.segment for d in data if isinstance(d.segment, PartitionModification) and d.segment != entry] |
|
I assume that's because the max line length is quite high for a python project with 160. Reducing it I can see that it starts getting broken up, e.g. with 100. Having said that, I've noticed some other oddities such as |
|
I really wish these programs weren't so hung up on line length. But at some point, I think this PR might better benefit us, so I'll stand behind it despite the oddities if everyone else like this :) |
|
I'd be in favour of reducing the line count though, to maybe 120, unless there's a good reason to keep it at 160? I can try running the formatter with yapf as well to compare the output, that one has lots of options to tweak which might suit better? |
|
I just wish it could keep strings long. I prefer one slightly long string over many smaller strings over multiple lines. Preference things I guess, but try and see what 120 line length would look like. I suspect it will chop up 80% of our function definitions. |
|
It seems that the I found some mention in an issue astral-sh/ruff#8642 (comment) which then later points to what black recommends to ignore them https://ichard26-testblackdocs.readthedocs.io/en/refactor_docs/compatible_configs.html#configuration. I pushed another version formatted with I had to remove the type variables in classes and functions as yapf couldn't handle them. I raised an issue in yapf for it google/yapf#1277. The formatting looks similar to ruff but it allows for more tweaks and doesn't seem to suffer from the same above flake8 deviations. |
If ruff is used for auto-formatting, it might be okay to remove the flake8 checks. The current Pylint + ruff + mypy checks should cover most of the flake8 checks.
Looking at the commit log, it doesn't seem like yapf is actively developed. I don't think it would be good to rely on a formatter that won't be able to handle new Python syntax. |
|
Agreed, I think moving forward with ruff is probably the better option for now. |
|
@Torxed I've updated the PR with all files formatted, I left the current 160 line length for now, we can adjust it in a follow up if needed. |
Torxed
left a comment
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.
Sounds good, and good job elaborating on this one!
Related issue: #1682
I know this topic has been up a few times so I thought it's time for another round :)
Some previous discussion around using YAPF #997
As the code base has been integrated heavily with
ruffit would make sense to also explore using theruff formatextension.I run a simple
ruff format archinstall/to get a feeling of what it might look like and to collect feedback on what works and what looks funky. It seems there are some settings for the formatter but not to an extend of YAPF.Documentation: https://docs.astral.sh/ruff/settings/#format
@Torxed any feedback would be great :)
Edit
Based on the discussions below, the general consent is to use
ruff formatfor now as the main formatting tool.This PR therefore
pyproject.toml