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
Improve linting #352
Comments
Hi @marcusvaltonen, Thank you for the issue. Indeed, the code is not perfectly PEP8 compliant, not least due to some of the choices regarding line lengths.
All in all, I think it is definitely a good idea to incorporate a linter, either flake8, pylint, or another one. My only concern is that linters should not be taken as gospel (e.g., the whitespace issue), and therefore pre-commit-hooks may not be the most appropriate place for them. Indeed, it can create a very negative experience for people unfamiliar with pre-commit hooks, that will not know how to "fix" their problems and therefore not be able to commit. They definitely could be part of the CI-pipeline. @mrava87 could maybe give better input on that end. |
Hi both, For this reason I think we should not go after making every linter happy as we probably would spend more time on this than on real useful development. As we migrate to v2, I am happy to reconsider some of the choices that @cako initially made To me this is a totally acceptable set of pre-commit tools and black is a wel-known and widely used tool. Of course we could use black in tandem with flake8 (a quick search gave https://ljvmiranda921.github.io/notebook/2018/06/21/precommits-using-black-and-flake8/), I would be happy to consider this. At the moment my reccomandation is to hold on for a bit as we are going through a lot of internal changes whilst we create v2, we could include this at the very end :) |
Regarding unused import, can you point us to one or two places… I code in pycharm and unused imports are highlighted in grey, so I would be surprised if this happens more than once or twice in the entire library (excluding the init files for the reason @cako mentioned) |
Hello, Nice to hear your opinions. Linters are always there to help - if they don't, you are using it wrong. Every linter cannot for logical reasons (contradicting style opinions or simply too demanding) be happy, but you should stick to one code style and enforce it. I simply think that there are too many inconsistencies in pylops and its derivatives, which could be streamlined. Having e.g. pylint tell you how many variables you should accept as an input argument, how many public methods a class should have or when to write docstrings might seem like too picky, and in many cases it is -- but you can always disable these warnings using locally or globally. For me it is about making a conscious design choice. I've been in big projects without properly enforcing such tools and after a couple of years you end up having to do major refactoring because things are going out of control, thus jeopardizing stability etc. Having a linter saying "hey, this could be a potential issue" is a good hint at where parts of the project could benefit from an architectural update. I haven't spent much time on pylops, and I know you guys have, so I will try to be humble. It is merely my opinion while scrolling through the code base, where I find design choices that I wouldn't have made. That doesn't mean that they are bad design choices, there are many ways to accomplish the same thing. On all repositories I maintain I like to put it as a step in the CI-pipeline, because developers should be allowed to commit their work in progress while developing, and not as pre-commit hooks. At least I would suggest to fix the line length and the imports (and make sure they are checked before merge), I am happy to do that. Here are some import errors (and I found more in pyproximal as well):
Then of course there is the "problem" with the init.py files. I would just go ahead and say that it is a design choice, and simply not check the F401 error on those files. |
Thanks! Don't get me wrong, I like the idea of linters (or anything else that eases development) but I am just trying to avoid that to go too far... I used to be in a place where sometimes I felt some projects were evolving on making linters happier more than making developers and users happier. This reminds me when you write a paper and try to make reviewers happier but none is gaining anything... so again, let's use these tools but just be pragmatic about ;) Honestly, I think I know why we get a lot of For the |
I tried to configure flake8 to be somewhat compatible with black. I think it is a good compromise is to provide a flake8 configuration compatible with black in Anyways, here is an example of configs:
Some rationale behind these choices:
With these configurations, I was able to remove most of the "noise" in the linting, and was left with a few warnings/errors that can improve the code. I will submit them in a PR soon! |
This is a good start @cako. I would personally like to have a step in the CI-pipeline to check this, but you can of course (if you don't want to strictly enforce it) always allow merging without that step passing. Again, then you are doing a well-informed decision of knowingly stray from the guidelines. I strongly believe that the style-guide you chose should be enforced everywhere, and if there are rules you don't like, then you can modify/disregard them. The limitations in doing so is is probably the reason I am not a huge fan of Black and the workflow it promotes. I don't think a unified inter-repository style guide is possible in a language like python which is used by vastly different communities (scientific, enterprise, web-applications, etc.). I guess that works better for gofmt (for Go language), which has inspired Black, as the community is more homogeneous. Again, just some thoughts on my end, nothing I expect you to take seriously into account. I completely agree that hunting a 10.0 / 10.0 in pylint rating can be a waste of time, but I have always been pragmatic about it and allowed locally disabling it or similar, and in the end I don't think I have regretted this. |
Thanks! I agree with your config decisions, again personally I find it weird when I see Just a question, if I put in my
I still get quite some warnings by running |
@cako for now you suggest, devs add the |
@marcusvaltonen I didn't know it was possible to provide checks that were not enforced before merge! @mrava87 If we can set this up, I would say that is the ideal way. We can have a core dev look over the code quality + linter warnings, and make an executive decision on whether to accept the code. I'm not sure how to do this, so it would be great to get some pointers. @mrava87 Yes, I only checked the |
@cako It depends on the CI-tool. I have been working a lot in enterprise with Gitlab CI and there they have an "optional" setting. |
What about this? https://github.com/marketplace/actions/python-flake8-lint We would need to try but if I understand correctly this would be an extra row in your PR CI pipeline, we can just look at it and ignore if we think there is no problem with the warnings? |
Exactly, it would be good to inform the reviews, but not to make it mandatory |
Have a look at the PR. I think I have been able to set it up successfully, this is what it is run:
I did run it locally and get zero warnings too :) |
* CI: added flake8 github action Handles #352 * minor: change path for flake8 action * minor: fix spaces in ignore of flake8 action * minor: add more ignore in flake8 action * minor: try to add per-file-ignore to flake8 action * minor: added flake8 to setup.cfg and makefile
Closing based on #364 |
I installed flake8 to check for code quality and ran it on pylops. It quite quickly finds a lot of flaws in the code quality. Some of the more common once are:
What is the line length? What I can find in the pre-commit hook it is 88 characters, but at multiple places this is exceeded.
Moreover flake8 is not an aggressive linter compared to e.g. pylint, so I believer this is a minimal requirement.
Suggestion
Enforce PEP8 using flake8 and e.g. flake8-import-order. Also consider enabling some of pylint's checkers for code quality (at least initially). This can be enforced as a pre-commit hook or in the CI-pipeline.
The text was updated successfully, but these errors were encountered: