arcade icon indicating copy to clipboard operation
arcade copied to clipboard

Autoformatting

Open benjamin-kirkbride opened this issue 1 year ago • 18 comments
trafficstars

How do people feel about implementing (and enforcing) autoformatting in Arcade? Specifically:

  • Black for code (120 char line length)
  • Ruff for imports

Some considerations:

  • we would likely need to disable this for sphinx purposes on some files
  • git blame can be preserved (inconveniently) using this: https://black.readthedocs.io/en/stable/guides/introducing_black_to_your_project.html#avoiding-ruining-git-blame

benjamin-kirkbride avatar Jun 26 '24 02:06 benjamin-kirkbride

As far as ruff goes, we already use it for linting, so using it for the import sorting is trivial.

Really just need to exclude the examples code from autoformatting as far as exclusions go, maybe the experimental directory because there are technically examples in that? Not sure autoformatting matters for any of those though.

I don't think we care about git blame preservation

Cleptomania avatar Jun 26 '24 02:06 Cleptomania

We definitely don't care about blame preservation.

einarf avatar Jun 26 '24 02:06 einarf

Things that probably need to happen for this:

  1. A single, giant PR for initial conversion
  2. Added to the CI to check for formatting(probably not having CI actually do any formatting though)
  3. Add a tool to make.py to run it(CI could just use this probably)
  4. Update contributing docs for it

Cleptomania avatar Jun 26 '24 02:06 Cleptomania

Isn't step one actually some kind of broader consensus? Who needs to sign off?

benjamin-kirkbride avatar Jun 26 '24 02:06 benjamin-kirkbride

Autoformatting the imports may break a bunch of stuff at first, due to.. load bearing import order

benjamin-kirkbride avatar Jun 26 '24 02:06 benjamin-kirkbride

Those steps were just like, assuming it was happening, we probably have very little load bearing import order left. The 3.0 work cleaned up a lot of Arcade import. I would probably be in favor of excluding __init__.py files from the formatting though, the top level one is probably a minefield

Cleptomania avatar Jun 26 '24 02:06 Cleptomania

gui is already formated with ruff and I use pre-commit hooks to enforce it on my side.

eruvanos avatar Jun 26 '24 06:06 eruvanos

TL;DR: I am very wary of this idea.

The most important part of this (imo) is knowing how to turn it off. The following probably need to be excluded:

  • make.py
  • examples (as Clepto said above)
  • arcade.experimental
  • Sphinx stuff
  • The top-level utils folder can be fragile (includes more Sphinx stuff)

We're refactoring the utils folder one step at a time (#2109), but it's probably best to leave it alone for now.

As to other auto-formatting options not mentioned above, there are good reasons to disable them in many cases. PEP-8 itself points out that following it dogmatically is bad. I don't think you're proposing we do so, but I'm bringing it up now so we can agree not to do so in the future.

pushfoo avatar Jun 26 '24 14:06 pushfoo

All done

einarf avatar Jun 27 '24 13:06 einarf

Did we sort imports too as part of this? Sorry if I missed that

benjamin-kirkbride avatar Jun 27 '24 19:06 benjamin-kirkbride

#2141 just covered implementing black. Intended to follow up with import sorting separately, I’ll just reopen this for that.

Cleptomania avatar Jun 27 '24 19:06 Cleptomania

.. or just make separate issue.

einarf avatar Jun 27 '24 20:06 einarf

Can we also do it with ruff? black and ruff are compatible, but ruff still wants to change >100 files, because it wants to do little more then black.

eruvanos avatar Jul 03 '24 22:07 eruvanos

We could do it with ruff, I believe the reason it touches so much more is that Ruff hits docstrings slightly. At the least we can make a PR with it and see what the difference looks like.

Cleptomania avatar Jul 03 '24 22:07 Cleptomania

The commit fails, because not all doc strings are shortened to a length of 100.

Do we want to keep it 100? Maybe I just go through the doc strings and format it.

eruvanos avatar Jul 04 '24 13:07 eruvanos

Related: #2214

pushfoo avatar Jul 05 '24 21:07 pushfoo

Clearing milestone on this because it's not critical for 3.0

einarf avatar Jul 10 '24 20:07 einarf

Both ruff and black is not using 100 line limit : https://github.com/pythonarcade/arcade/pull/2260

einarf avatar Jul 15 '24 13:07 einarf