-
Notifications
You must be signed in to change notification settings - Fork 49
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
Review Python linting strategy and possible automation #4631
Comments
Thanks for making an issue. I didn't have any input on the Python formatting rules in this project (they started before I joined I think) and I also found them pretty annoying when I started, but now I don't really mind them. Now my opinion is that pylint is and always will be annoying (although useful) but black is fine. And I don't mind hard line limits if they're generous enough. I also wouldn't mind changing out black for a more generic PEP8 checker (rather than an auto formatter)---I would still use black to satisfy it though. I don't write a ton of code in this repo but if we were going to have project-wide standards then I would probably want to spend more time thinking about it. And probably @cmoussa1 would too? |
Thanks for tagging me in this @jameshcorbett. I think out of the two Python formatters, I prefer It probably warrants some more discussion, and whatever we end up deciding, in my opinion, it would be best for the rest of the sub-projects to follow suit and maintain consistency with flux-core, as James mentioned above. It's probably worth mentioning that I simply copied flux-core's Python formatting guidelines when the flux-accounting repository was first created. |
Tagging #4623 (comment) for reference |
Note that we did actually put down "black" as our only project-wide python "standard" in RFC 7 We should change RFC 7 to whatever makes sense and doesn't scare people away! I think we chose black just because nobody had a strong feeling about python style and black doesn't offer options, so no decisions were needed :_) I could be wrong. Maybe @cmoussa1 has been a ball of rage all this time. |
IIRC, @tgamblin had suggested |
Black's nice b/c it's fully automatic -- i.e., nobody has to bother fixing formatting issues -- at least not
We waited to switch to I use blacken.el in emacs so that when I save files they're automatically blackened, and it works great. I added support to it so that it reads your There is also the very popular pre-commit tool, which applies black and other style checks automatically locally: https://pre-commit.com |
Oh and in case you think we went to black unscientifically 🤪, I did a whole analysis of what our line length should be in spack/spack#24718. We went with 99 -- see the plots there for the rationale. It MAY be a little OCD, just maybe. |
Nice discussion! I left for my run and this was blank and now 😍 ! Thanks for that, and I'm glad to see that I'm not out in left field with respect to my thoughts. I'm going to put this all together and will make some automation around the preferences soon - I'm also thinking isort, mypy, black, and flake8 (with a specific set of things) and a pre-commit that does nice cleanup of line endings, etc. (those always get me!) I think we can find a nice balance of automated fixes, but still having a good style enforced. |
And the only other one I use for other projects (that I don't see here) is pyflakes - and that might be fulfilled by a subset of flake8 (it finds unused variables/imports etc.) I'll test that out too in this context. |
From here:
Maybe we should be using |
I think I mostly have been using pyflakes because it sounds like some kind of breakfast cereal, and this is a highly important decision point! 🥄 |
pyflakes : corn flakes :: flake8 : product19 |
product19... one step away from soylent green! |
Python project linting.... tools? No... it's people! 😱 🙀 😭 |
Heh, I came to give a rundown and @tgamblin beat me to it. The thing that flake8 does that's really helpful, is that it's a meta-tool. It actually runs pylint as well as several others, and offers a common interface for enforcing or ignoring violations from any of them. I'm strongly in favor of running at least flake8, black, and mypy or pyright (for type checks, since we're on 3.6 we might as well get real type checking) all at a pinned versions easily fetched from a requirements file or similar so we don't run into a split between local dev and CI, and can easily keep things up to date. The only real change in there would be we'll get slightly more tests, and probably want to come up with a list of the things we want to ignore. Spack's list of ignores is pretty good, though there are a couple we probably don't want to copy over: https://github.com/spack/spack/blob/develop/.flake8#L20 |
Nice! So I had quite an adventure this morning - either flake8 fixes and/or isort completely broke testing, and a made a new PR that (finally) has the refactored pre-commit, only with black and mypy and general file cleanups (but flake8 and isort would need to be tested individually to be added back). My gut is that it's import order that matters - so my proposal for next steps is to get that PR reviewed and merged, and then I can make incremental fixes for flake8 / isort to figure out what was the culprit that broke tests (and document it for future developers to not make the same mistake). Then we can further tweak our linting/formatting preferences from there! But I am loving having added pre-commit, and just one place in the CI to look for linting and formatting checks. Separation I think only makes sense if the checks are time intensive, but in this case it was just #toomanyclicks! |
My strategy won't work - 3.6 is too old. Someone else feel free to tweak the current hard coded scripts to do differently, and ping me (or I'll remember and come back) when we can use a more up-to-date version of Python. |
No description provided.
The text was updated successfully, but these errors were encountered: