cjolowicz / cookiecutter-hypermodern-python

Hypermodern Python Cookiecutter
http://cookiecutter-hypermodern-python.readthedocs.io/
MIT License
1.78k stars 231 forks source link

Proposal: use ruff to replace flake8 and related extensions #1282

Open cauliyang opened 1 year ago

cauliyang commented 1 year ago

Now ruff is blazing fast linter than flake8. Its rules are self contained and it is evolving quickly so far. Currently it has covered most useful rules. I think we can keep an eye on it and move to ruff at proper time. What do you think?

joelb123 commented 1 year ago

I strongly agree. Not only is it faster, the list of modules that would get replaced, AFAIK is:

In addition, there's more out-of-the-box functionality (e.g. pandas-vet for us pandas users).

bmritz commented 1 year ago

@joelb123 @cauliyang do you know of any forks that use ruff? I have a fork at https://github.com/bmritz/cookiecutter-hypermodern-python that I was thinking about putting ruff into, but if there's a reference I could go off of, that would be helpful.

EDIT: here's one: https://github.com/dbatten5/cookiecutter-hypermodern-python. And here is the relevant commit: https://github.com/dbatten5/cookiecutter-hypermodern-python/commit/327b373ce1ffbb1ebfb13e9d3fa8b48a4fafe271

joelb123 commented 1 year ago

Yes, I saw the @dbatten5 commit, but I haven't looked at it in detail. I did notice that this fork kept 'isort', which is a pity since getting rid of fighting with 'isort' is one of the many good things about ruff.

Because ruff is so performant and has '--fix' for many issues, it can enable checks/fixes with every save by the IDE (e.g., via the pycharm ruff plugin). This means more productivity for those who use ruff, but it also means more boilerplate in 'pyproject.toml'.

dbatten5 commented 1 year ago

I couldn't really get ruff working without isort the same as when I had isort. Would be happy to get rid of it though and run everything through ruff - do you have an example config for ruff replacing the need for isort @joelb123 ?

EDIT: Got there in the end https://github.com/dbatten5/cookiecutter-hypermodern-python/commit/68dbd7d52e6215119aa6428f472b1ee44603c009 . Was having a little trouble with autodetection of first party imports so ended up having to go with src = ['src', 'tests'] under [tool.ruff].

bosd commented 6 months ago

Does anyone have ruff running succesfully and able to open a PR in this repo?

dbatten5 commented 6 months ago

I have it running in my fork https://github.com/dbatten5/cookiecutter-hypermodern-python. Should be able to open a PR in the near future

aeturrell commented 3 months ago

I think this would be a great change, not sure if anyone has put in a PR for it yet?

bruno-fs commented 3 months ago

I'm working on replacing all compatible linters with ruff on my fork. The only things I didn't replace yet are darglint and flake8-rst-docstrings. I'm not sure how to handle them. I also replaced black with ruff format.

Given darglint was archived, I wonder if it is still relevant. But there's an open issue for it on ruff repo. However, flake8-rst-docstrings don't have an open discussion there.

webknjaz commented 3 months ago

There's darglint2 per https://softwarerecs.stackexchange.com/a/86925/61183, additionally, there's a pylint plugin with similar features. There's a similar flake8 integration in https://github.com/jsh9/pydoclint which is promised to be faster. The latter was actually offered in the issue mentioned above.

bruno-fs commented 3 months ago

@webknjaz Thanks for pointing that out! I'm impressed with pydoclint speed!

bosd commented 1 month ago

@bruno-fs Your fork looks really interesting. Any plans to contribute and open a PR here? 🙏

bruno-fs commented 4 weeks ago

Thanks, @bosd. I'm using it in some projects.

I do plan to open a PR, but aaaaaaaaaall the documentation still needs to be updated and I have other priorities atm.

Also, I went a little bit further and stripped away flake8-rst-docstrings and replaced darglint with pydoclint, which might be seem as controversial moves.

Furthermore, I'm also on the verge of removing poetry.lock from the template, because it is a constant source of conflicts in my workflow, which relies on cruft .

bosd commented 3 weeks ago

@bruno-fs Thanks, your fork looks really interesting. Specifically the cruft. Personally I like it, but it might be too opinionated for the projects i'm working with.

bruno-fs commented 3 weeks ago

@bosd cruft is not on the fork, I'm just using it to consume the template instead of using cookiecutter itself :D

But replacing linters with ruff already is an opinionated move. The author might not even accept a PR. What are your thoughts on this matter, @cjolowicz?

Would you accept a PR replacing python linters with ruff? If so, I could create a branch with a cleanup version of my fork, only replacing the linters. I'd probably need help from someone interested to also update the documentation. That part is lacking in my fork.